@@ -1020,48 +1020,42 @@ def repository(self, owner, repository):
1020
1020
json = self ._json(self ._get (url ), 200 )
1021
1021
return Repository (json , self ) if json else None
1022
1022
1023
- def _revoke_authorization (self , access_token = None ):
1024
- """Helper method for revoking application authorization keys.
1025
-
1026
- :param str access_token: (optional), the access token to delete; if
1027
- not provided, revoke all access tokens for this application
1028
-
1029
- """
1030
- p = self ._session .params
1031
- client_id = p .get ('client_id' )
1032
- client_secret = p .get ('client_secret' )
1033
- if client_id and client_secret :
1034
- auth = (client_id , client_secret )
1035
- url_parts = ['applications' , str (auth [0 ]), 'tokens' ]
1036
- if access_token :
1037
- url_parts .append (access_token )
1038
- url = self ._build_url (* url_parts )
1039
- return self ._delete (url , auth = auth , params = {
1040
- 'client_id' : None , 'client_secret' : None
1041
- })
1042
- return False
1043
-
1044
1023
@requires_app_credentials
1045
1024
def revoke_authorization (self , access_token ):
1046
1025
"""Revoke specified authorization for an OAuth application.
1047
1026
1048
- Revoke all authorization tokens created by your application.
1027
+ Revoke all authorization tokens created by your application. This will
1028
+ only work if you have already called ``set_client_id``.
1049
1029
1050
1030
:param str access_token: (required), the access_token to revoke
1051
1031
:returns: bool -- True if successful, False otherwise
1052
1032
"""
1053
- self ._revoke_authorization (access_token )
1033
+ client_id , client_secret = self ._session .retrieve_client_credentials ()
1034
+ url = self ._build_url ('applications' , str (client_id ), 'tokens' ,
1035
+ access_token )
1036
+ with self ._session .temporary_basic_auth (client_id , client_secret ):
1037
+ response = self ._delete (url , params = {'client_id' : None ,
1038
+ 'client_secret' : None })
1039
+
1040
+ return self ._boolean (response , 204 , 404 )
1054
1041
1055
1042
@requires_app_credentials
1056
1043
def revoke_authorizations (self ):
1057
1044
"""Revoke all authorizations for an OAuth application.
1058
1045
1059
- Revoke all authorization tokens created by your application.
1046
+ Revoke all authorization tokens created by your application. This will
1047
+ only work if you have already called ``set_client_id``.
1060
1048
1061
1049
:param str client_id: (required), the client_id of your application
1062
1050
:returns: bool -- True if successful, False otherwise
1063
1051
"""
1064
- self ._revoke_authorization ()
1052
+ client_id , client_secret = self ._session .retrieve_client_credentials ()
1053
+ url = self ._build_url ('applications' , str (client_id ), 'tokens' )
1054
+ with self ._session .temporary_basic_auth (client_id , client_secret ):
1055
+ response = self ._delete (url , params = {'client_id' : None ,
1056
+ 'client_secret' : None })
1057
+
1058
+ return self ._boolean (response , 204 , 404 )
1065
1059
1066
1060
def search_code (self , query , sort = None , order = None , per_page = None ,
1067
1061
text_match = False , number = - 1 , etag = None ):
0 commit comments