mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-22 09:06:40 +03:00
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:
parent
479a40d2cc
commit
46f7c18757
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user