8000 Fix removing application auth tokens · buiduyhieu1/github3.py@6a5cd47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a5cd47

Browse files
jmcarpsigmavirus24
authored andcommitted
Fix removing application auth tokens
1 parent 46b0dac commit 6a5cd47

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

github3/github.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,29 +1019,46 @@ def repository(self, owner, repository):
10191019
json = self._json(self._get(url), 200)
10201020
return Repository(json, self) if json else None
10211021

1022-
def revoke_authorization(self, client_id, access_token):
1022+
def _revoke_authorization(self, access_token=None):
1023+
"""Helper method for revoking application authorization keys.
1024+
1025+
:param str access_token: (optional), the access token to delete; if
1026+
not provided, revoke all access tokens for this application
1027+
1028+
"""
1029+
p = self._session.params
1030+
client_id = p.get('client_id')
1031+
client_secret = p.get('client_secret')
1032+
if client_id and client_secret:
1033+
auth = (client_id, client_secret)
1034+
url_parts = ['applications', str(auth[0]), 'tokens']
1035+
if access_token:
1036+
url_parts.append(access_token)
1037+
url = self._build_url(*url_parts)
1038+
return self._delete(url, auth=auth, params={
1039+
'client_id': None, 'client_secret': None
1040+
})
1041+
return False
1042+
1043+
def revoke_authorization(self, access_token):
10231044
"""Revoke specified authorization for an OAuth application.
10241045
10251046
Revoke all authorization tokens created by your application.
10261047
1027-
:param str client_id: (required), the client_id of your application
1028-
:param str acess_token: (required), the access_token to revoke
1048+
:param str access_token: (required), the access_token to revoke
10291049
:returns: bool -- True if successful, False otherwise
10301050
"""
1031-
url = self._build_url('applications', str(client_id), 'tokens',
1032-
str(access_token))
1033-
return self._boolean(self._delete(url), 204, 404)
1051+
self._revoke_authorization(access_token)
10341052

1035-
def revoke_authorizations(self, client_id):
1053+
def revoke_authorizations(self):
10361054
"""Revoke all authorizations for an OAuth application.
10371055
10381056
Revoke all authorization tokens created by your application.
10391057
10401058
:param str client_id: (required), the client_id of your application
10411059
:returns: bool -- True if successful, False otherwise
10421060
"""
1043-
url = self._build_url('applications', str(client_id), 'tokens')
1044-
return self._boolean(self._delete(url), 204, 404)
< 8000 /code>1061+
self._revoke_authorization()
10451062

10461063
def search_code(self, query, sort=None, order=None, per_page=None,
10471064
text_match=False, number=-1, etag=None):

tests/unit/test_github.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ def test_can_login_without_two_factor_callback(self):
1616
self.instance.login(token='token')
1717

1818
def test_revoke_authorization(self):
19-
self.instance.revoke_authorization('client_id', 'access_token')
19+
self.instance.set_client_id('key', 'secret')
20+
self.instance.revoke_authorization('access_token')
2021
self.session.delete.assert_called_once_with(
21-
'https://api.github.com/applications/client_id/tokens/access_token'
22+
'https://api.github.com/applications/key/tokens/access_token',
23+
auth=('key', 'secret'),
24+
params={'client_id': None, 'client_secret': None}
2225
)
2326

2427
def test_revoke_authorizations(self):
25-
self.instance.revoke_authorizations('client_id')
28+
self.instance.set_client_id('key', 'secret')
29+
self.instance.revoke_authorizations()
2630
self.session.delete.assert_called_once_with(
27-
'https://api.github.com/applications/client_id/tokens'
31+
'https://api.github.com/applications/key/tokens',
32+
auth=('key', 'secret'),
33+
params={'client_id': None, 'client_secret': None}
2834
)

0 commit comments

Comments
 (0)
0