Skip to content

Commit

Permalink
Support facebook return_scopes parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Dec 27, 2016
1 parent 45a76a2 commit 4e83280
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased](https://github.com/python-social-auth/social-core/commits/master)

### Added
- Added support for Facebook OAuth2 return_scopes parameter.
Refs [#818](https://github.com/omab/python-social-auth/issues/818)
- Added support for per-backend USER_FIELDS setting. Refs [#661](https://github.com/omab/python-social-auth/issues/661)
- Added `expires_in` as `expires` for LinkedIn OAuth2. Refs [#666](https://github.com/omab/python-social-auth/issues/666)
- Added `SOCIAL_AUTH_USER_AGENT` setting to override the default User-Agent header.
Expand Down
16 changes: 15 additions & 1 deletion social_core/backends/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ class FacebookOAuth2(BaseOAuth2):
USER_DATA_URL = 'https://graph.facebook.com/v{version}/me'
EXTRA_DATA = [
('id', 'id'),
('expires', 'expires')
('expires', 'expires'),
('granted_scopes', 'granted_scopes'),
('denied_scopes', 'denied_scopes')
]

def auth_params(self, state=None):
params = super(FacebookOAuth2, self).auth_params(state)
params['return_scopes'] = 'true'
return params

def authorization_url(self):
version = self.setting('API_VERSION', API_VERSION)
return self.AUTHORIZATION_URL.format(version=version)
Expand Down Expand Up @@ -129,6 +136,13 @@ def do_auth(self, access_token, response=None, *args, **kwargs):
data['access_token'] = access_token
if 'expires' in response:
data['expires'] = response['expires']

if self.data.get('granted_scopes'):
data['granted_scopes'] = self.data['granted_scopes'].split(',')

if self.data.get('denied_scopes'):
data['denied_scopes'] = self.data['denied_scopes'].split(',')

kwargs.update({'backend': self, 'response': data})
return self.strategy.authenticate(*args, **kwargs)

Expand Down

0 comments on commit 4e83280

Please sign in to comment.