Skip to content

Commit 62c1dc9

Browse files
authored
Fix crash on bad auth code (#469)
1 parent 51d4ced commit 62c1dc9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

dj_rest_auth/registration/serializers.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from allauth.socialaccount.providers.oauth2.client import OAuth2Error
12
from django.contrib.auth import get_user_model
23
from django.core.exceptions import ValidationError as DjangoValidationError
34
from django.http import HttpRequest, HttpResponseBadRequest
@@ -130,7 +131,12 @@ def validate(self, attrs):
130131
headers=adapter.headers,
131132
basic_auth=adapter.basic_auth,
132133
)
133-
token = client.get_access_token(code)
134+
try:
135+
token = client.get_access_token(code)
136+
except OAuth2Error as ex:
137+
raise serializers.ValidationError(
138+
_('Failed to exchange code for access token')
139+
) from ex
134140
access_token = token['access_token']
135141
tokens_to_parse = {'access_token': access_token}
136142

0 commit comments

Comments
 (0)