Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solves some revoke_token related errors (BaseOAuth1 and FacebookOAuth2) #158

Merged
merged 2 commits into from
Jan 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion social/backends/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
49 changes: 25 additions & 24 deletions social/backends/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)