Skip to content

Commit

Permalink
Store refresh_token in extra_data
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Jul 25, 2019
1 parent f00a650 commit 7e97bd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions auth_backends/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,14 @@ class EdXOAuth2(EdXBackendMixin, BaseOAuth2):

DEFAULT_SCOPE = ['user_id', 'profile', 'email']
discard_missing_values = True
# EXTRA_DATA is used to store the `user_id` from the details in the UserSocialAuth.extra_data field.
# EXTRA_DATA is used to store important data in the UserSocialAuth.extra_data field.
# See https://python-social-auth.readthedocs.io/en/latest/backends/oauth.html?highlight=extra_data
EXTRA_DATA = [('user_id', 'user_id', discard_missing_values)]
EXTRA_DATA = [
# Update the stored user_id, if it's present in the response
('user_id', 'user_id', discard_missing_values),
# Update the stored refresh_token, if it's present in the response
('refresh_token', 'refresh_token', discard_missing_values),
]

# local only (not part of social-auth)
CLAIMS_TO_DETAILS_KEY_MAP = _merge_two_dicts(PROFILE_CLAIMS_TO_DETAILS_KEY_MAP, {
Expand Down
11 changes: 9 additions & 2 deletions auth_backends/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ def test_user_data(self):

def test_extra_data(self):
"""
Ensure that `user_id` stays in EXTRA_DATA.
Ensure that `user_id` and `refresh_token` stay in EXTRA_DATA.
The refresh token is required to refresh the user's access
token in cases where the client_credentials grant type is not
being used, and the application is running on a completely
separate domain name.
"""
self.assertEqual(self.backend.EXTRA_DATA, [('user_id', 'user_id', True)])
self.assertEqual(self.backend.EXTRA_DATA, [
('user_id', 'user_id', True),
('refresh_token', 'refresh_token', True),
])

0 comments on commit 7e97bd8

Please sign in to comment.