diff --git a/social/backends/facebook.py b/social/backends/facebook.py index 27c709da4..ffeb39b03 100644 --- a/social/backends/facebook.py +++ b/social/backends/facebook.py @@ -112,7 +112,8 @@ def revoke_token_params(self, token, uid): return {'access_token': token} def process_revoke_token_response(self, response): - return response.code == 200 and response.content == 'true' + return super(FacebookOAuth2, self).process_revoke_token_response(response) \ + and response.content == 'true' class FacebookAppOAuth2(FacebookOAuth2): diff --git a/social/backends/oauth.py b/social/backends/oauth.py index f965d94ba..9d8e659bd 100644 --- a/social/backends/oauth.py +++ b/social/backends/oauth.py @@ -31,6 +31,8 @@ class OAuthAuth(BaseAuth): EXTRA_DATA = None ID_KEY = 'id' ACCESS_TOKEN_METHOD = 'GET' + REVOKE_TOKEN_URL = None + REVOKE_TOKEN_METHOD = 'POST' def extra_data(self, user, uid, response, details=None): """Return access_token and extra defined names to store in @@ -72,6 +74,29 @@ def user_data(self, access_token, *args, **kwargs): """Loads user data from service. Implement in subclass""" return {} + def revoke_token_url(self, token, uid): + return self.REVOKE_TOKEN_URL + + def revoke_token_params(self, token, uid): + return {} + + def revoke_token_headers(self, token, uid): + return {} + + def process_revoke_token_response(self, response): + return response.status_code == 200 + + def revoke_token(self, token, uid): + if self.REVOKE_TOKEN_URL: + url = self.revoke_token_url(token, uid) + params = self.revoke_token_params(token, uid) + headers = self.revoke_token_headers(token, uid) + data = urlencode(params) if self.REVOKE_TOKEN_METHOD != 'GET' \ + else None + response = self.request(url, params=params, headers=headers, + data=data, method=self.REVOKE_TOKEN_METHOD) + return self.process_revoke_token_response(response) + class BaseOAuth1(OAuthAuth): """Consumer based mechanism OAuth authentication, fill the needed @@ -214,8 +239,6 @@ class BaseOAuth2(OAuthAuth): ACCESS_TOKEN_URL = None REFRESH_TOKEN_URL = None REFRESH_TOKEN_METHOD = 'POST' - REVOKE_TOKEN_URL = None - REVOKE_TOKEN_METHOD = 'POST' RESPONSE_TYPE = 'code' REDIRECT_STATE = True STATE_PARAMETER = True @@ -367,25 +390,3 @@ def refresh_token(self, token, *args, **kwargs): request = self.request(url, **request_args) return self.process_refresh_token_response(request, *args, **kwargs) - def revoke_token_url(self, token, uid): - return self.REVOKE_TOKEN_URL - - def revoke_token_params(self, token, uid): - return {} - - def revoke_token_headers(self, token, uid): - return {} - - def process_revoke_token_response(self, response): - return response.status_code == 200 - - def revoke_token(self, token, uid): - if self.REVOKE_TOKEN_URL: - url = self.revoke_token_url(token, uid) - params = self.revoke_token_params(token, uid) - headers = self.revoke_token_headers(token, uid) - data = urlencode(params) if self.REVOKE_TOKEN_METHOD != 'GET' \ - else None - response = self.request(url, params=params, headers=headers, - data=data, method=self.REVOKE_TOKEN_METHOD) - return self.process_revoke_token_response(response)