diff --git a/auth_backends/backends.py b/auth_backends/backends.py index b0633d72..ae99b57b 100644 --- a/auth_backends/backends.py +++ b/auth_backends/backends.py @@ -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, { diff --git a/auth_backends/tests/test_backends.py b/auth_backends/tests/test_backends.py index e525a7c1..37f91a96 100644 --- a/auth_backends/tests/test_backends.py +++ b/auth_backends/tests/test_backends.py @@ -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), + ])