From 46f7c1875751433b74ce70db3f099b90e0dad089 Mon Sep 17 00:00:00 2001 From: fpghost Date: Fri, 16 Nov 2018 09:55:59 +0100 Subject: [PATCH] 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) --- rest_auth/registration/serializers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rest_auth/registration/serializers.py b/rest_auth/registration/serializers.py index 4f99c18..723b6d7 100644 --- a/rest_auth/registration/serializers.py +++ b/rest_auth/registration/serializers.py @@ -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: