Skip to content

Commit

Permalink
Fix crash on bad auth code (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-w committed Feb 21, 2023
1 parent 51d4ced commit 62c1dc9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dj_rest_auth/registration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from allauth.socialaccount.providers.oauth2.client import OAuth2Error
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import HttpRequest, HttpResponseBadRequest
Expand Down Expand Up @@ -130,7 +131,12 @@ def validate(self, attrs):
headers=adapter.headers,
basic_auth=adapter.basic_auth,
)
token = client.get_access_token(code)
try:
token = client.get_access_token(code)
except OAuth2Error as ex:
raise serializers.ValidationError(
_('Failed to exchange code for access token')
) from ex
access_token = token['access_token']
tokens_to_parse = {'access_token': access_token}

Expand Down

0 comments on commit 62c1dc9

Please sign in to comment.