Merge pull request #85 from mimischi/patch-1

Return refresh_token and expires_in in SocialLoginSerializer
This commit is contained in:
Michael 2020-06-03 22:47:17 -05:00 committed by GitHub
commit 05296dec44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,6 +79,7 @@ class SocialLoginSerializer(serializers.Serializer):
# Case 1: We received the access_token # Case 1: We received the access_token
if attrs.get('access_token'): if attrs.get('access_token'):
access_token = attrs.get('access_token') access_token = attrs.get('access_token')
tokens_to_parse = {'access_token': access_token}
# Case 2: We received the authorization code # Case 2: We received the authorization code
elif attrs.get('code'): elif attrs.get('code'):
@ -109,12 +110,17 @@ class SocialLoginSerializer(serializers.Serializer):
) )
token = client.get_access_token(code) token = client.get_access_token(code)
access_token = token['access_token'] access_token = token['access_token']
tokens_to_parse = {'access_token': access_token}
# If available we add additional data to the dictionary
for key in ["refresh_token", adapter.expires_in_key]:
if key in token:
tokens_to_parse[key] = token[key]
else: else:
raise serializers.ValidationError( raise serializers.ValidationError(
_("Incorrect input. access_token or code is required.")) _("Incorrect input. access_token or code is required."))
social_token = adapter.parse_token({'access_token': access_token}) social_token = adapter.parse_token(tokens_to_parse)
social_token.app = app social_token.app = app
try: try: