social login should also optionally get the refresh token and pass this token the adapter.parse_token, so that SocialToken also caches this and refresh is possible for offline (e.g. google api offline oauth)

This commit is contained in:
fpghost 2018-11-16 09:55:59 +01:00
parent 479a40d2cc
commit 46f7c18757

View File

@ -35,6 +35,7 @@ class SocialAccountSerializer(serializers.ModelSerializer):
class SocialLoginSerializer(serializers.Serializer):
access_token = serializers.CharField(required=False, allow_blank=True)
refresh_token = serializers.CharField(required=False, allow_blank=True)
code = serializers.CharField(required=False, allow_blank=True)
def _get_request(self):
@ -110,12 +111,17 @@ class SocialLoginSerializer(serializers.Serializer):
)
token = client.get_access_token(code)
access_token = token['access_token']
refresh_token = token.get('refresh_token')
else:
raise serializers.ValidationError(
_("Incorrect input. access_token or code is required."))
social_token = adapter.parse_token({'access_token': access_token})
token_dict = {'access_token': access_token}
if refresh_token:
# Also pass the refresh_token if there is one
token_dict.update({'refresh_token': refresh_token})
social_token = adapter.parse_token(token_dict)
social_token.app = app
try: