From ab9d6a96aec3af5fe8cf7a0c3c070c10c3c9c9a0 Mon Sep 17 00:00:00 2001 From: Michael Gecht Date: Wed, 3 Jun 2020 17:18:27 +0200 Subject: [PATCH] Return refresh_token and expires_in --- dj_rest_auth/registration/serializers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dj_rest_auth/registration/serializers.py b/dj_rest_auth/registration/serializers.py index 7d9d4a0..b2a102e 100644 --- a/dj_rest_auth/registration/serializers.py +++ b/dj_rest_auth/registration/serializers.py @@ -79,6 +79,7 @@ class SocialLoginSerializer(serializers.Serializer): # Case 1: We received the access_token if attrs.get('access_token'): access_token = attrs.get('access_token') + tokens_to_parse = {'access_token': access_token} # Case 2: We received the authorization code elif attrs.get('code'): @@ -109,12 +110,17 @@ class SocialLoginSerializer(serializers.Serializer): ) token = client.get_access_token(code) 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: raise serializers.ValidationError( _("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 try: