From 7c30c9df2963711cff343c831d3ec2efc3060e90 Mon Sep 17 00:00:00 2001 From: Amanur Rahman Date: Sat, 20 Feb 2021 15:40:09 +0600 Subject: [PATCH] Handled invalid auth_code parsing error --- rest_auth/registration/serializers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rest_auth/registration/serializers.py b/rest_auth/registration/serializers.py index 4f99c182..f499d145 100644 --- a/rest_auth/registration/serializers.py +++ b/rest_auth/registration/serializers.py @@ -11,6 +11,7 @@ from allauth.socialaccount.helpers import complete_social_login from allauth.socialaccount.models import SocialAccount from allauth.socialaccount.providers.base import AuthProcess + from allauth.socialaccount.providers.oauth2.client import OAuth2Error except ImportError: raise ImportError("allauth needs to be added to INSTALLED_APPS.") @@ -108,7 +109,10 @@ def validate(self, attrs): self.callback_url, scope ) - token = client.get_access_token(code) + try: + token = client.get_access_token(code) + except OAuth2Error as e: + raise serializers.ValidationError({'code': e}) access_token = token['access_token'] else: