|
7 | 7 |
|
8 | 8 | """ |
9 | 9 |
|
10 | | -from json import dumps |
11 | | -from requests import session |
12 | 10 | from github3.auths import Authorization |
13 | 11 | from github3.decorators import requires_auth, requires_basic_auth |
14 | 12 | from github3.events import Event |
@@ -103,19 +101,26 @@ def authorize(self, login, password, scopes=None, note='', note_url='', |
103 | 101 | :returns: :class:`Authorization <Authorization>` |
104 | 102 | """ |
105 | 103 | json = None |
| 104 | + # TODO: Break this behaviour in 1.0 (Don't rely on self._session.auth) |
106 | 105 | auth = self._session.auth or (login and password) |
107 | 106 | if auth: |
108 | 107 | url = self._build_url('authorizations') |
109 | 108 | data = {'note': note, 'note_url': note_url, |
110 | 109 | 'client_id': client_id, 'client_secret': client_secret} |
111 | 110 | if scopes: |
112 | 111 | data['scopes'] = scopes |
113 | | - if self._session.auth: |
114 | | - json = self._json(self._post(url, data=data), 201) |
115 | | - else: |
116 | | - ses = session() |
117 | | - ses.auth = (login, password) |
118 | | - json = self._json(ses.post(url, data=dumps(data)), 201) |
| 112 | + # TODO: Unconditionally use the login and password, e.g., |
| 113 | + # old_auth = self._session.auth |
| 114 | + # self.login(login, password) |
| 115 | + # json = self._json(...) |
| 116 | + # self._session.auth = old_auth |
| 117 | + do_logout = False |
| 118 | + if not self._session.auth: |
| 119 | + do_logout = True |
| 120 | + self.login(login, password) |
| 121 | + json = self._json(self._post(url, data=data), 201) |
| 122 | + if do_logout: |
| 123 | + self._session.auth = None |
119 | 124 | return Authorization(json, self) if json else None |
120 | 125 |
|
121 | 126 | def check_authorization(self, access_token): |
|
0 commit comments