Handled invalid auth_code parsing error

This commit is contained in:
Amanur Rahman 2021-02-20 15:40:09 +06:00
parent 624ad01afb
commit 7c30c9df29

View File

@ -11,6 +11,7 @@ try:
from allauth.socialaccount.helpers import complete_social_login from allauth.socialaccount.helpers import complete_social_login
from allauth.socialaccount.models import SocialAccount from allauth.socialaccount.models import SocialAccount
from allauth.socialaccount.providers.base import AuthProcess from allauth.socialaccount.providers.base import AuthProcess
from allauth.socialaccount.providers.oauth2.client import OAuth2Error
except ImportError: except ImportError:
raise ImportError("allauth needs to be added to INSTALLED_APPS.") raise ImportError("allauth needs to be added to INSTALLED_APPS.")
@ -108,7 +109,10 @@ class SocialLoginSerializer(serializers.Serializer):
self.callback_url, self.callback_url,
scope scope
) )
try:
token = client.get_access_token(code) token = client.get_access_token(code)
except OAuth2Error as e:
raise serializers.ValidationError({'code': e})
access_token = token['access_token'] access_token = token['access_token']
else: else: