Skip to content

Commit 7d94730

Browse files
Barry Morrison and Ian Cordascosigmavirus24
authored andcommitted
Merge branch 'pr/198' into develop
2 parents e65432e + 2c38b36 commit 7d94730

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

github3/github.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
88
"""
99

10-
from json import dumps
11-
from requests import session
1210
from github3.auths import Authorization
1311
from github3.decorators import requires_auth, requires_basic_auth
1412
from github3.events import Event
@@ -103,19 +101,26 @@ def authorize(self, login, password, scopes=None, note='', note_url='',
103101
:returns: :class:`Authorization <Authorization>`
104102
"""
105103
json = None
104+
# TODO: Break this behaviour in 1.0 (Don't rely on self._session.auth)
106105
auth = self._session.auth or (login and password)
107106
if auth:
108107
url = self._build_url('authorizations')
109108
data = {'note': note, 'note_url': note_url,
110109
'client_id': client_id, 'client_secret': client_secret}
111110
if scopes:
112111
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
119124
return Authorization(json, self) if json else None
120125

121126
def check_authorization(self, access_token):

0 commit comments

Comments
 (0)