mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-10 19:26:35 +03:00
Merge pull request #187 from marsam/master
Capture OAuthError in TwitterLoginSerializer
This commit is contained in:
commit
3189a5c7a0
|
@ -15,12 +15,8 @@ from rest_framework import serializers
|
|||
from requests.exceptions import HTTPError
|
||||
# Import is needed only if we are using social login, in which
|
||||
# case the allauth.socialaccount will be declared
|
||||
|
||||
if 'allauth.socialaccount' in settings.INSTALLED_APPS:
|
||||
try:
|
||||
from allauth.socialaccount.helpers import complete_social_login
|
||||
except ImportError:
|
||||
pass
|
||||
from allauth.socialaccount.helpers import complete_social_login
|
||||
|
||||
|
||||
class SocialLoginSerializer(serializers.Serializer):
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
from django.conf import settings
|
||||
from django.http import HttpRequest
|
||||
from rest_framework import serializers
|
||||
from requests.exceptions import HTTPError
|
||||
# Import is needed only if we are using social login, in which
|
||||
# case the allauth.socialaccount will be declared
|
||||
try:
|
||||
if 'allauth.socialaccount' in settings.INSTALLED_APPS:
|
||||
from allauth.socialaccount.helpers import complete_social_login
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from allauth.socialaccount.models import SocialToken
|
||||
from allauth.socialaccount.models import SocialToken
|
||||
from allauth.socialaccount.providers.oauth.client import OAuthError
|
||||
|
||||
|
||||
class TwitterLoginSerializer(serializers.Serializer):
|
||||
|
@ -67,8 +65,8 @@ class TwitterLoginSerializer(serializers.Serializer):
|
|||
try:
|
||||
login = self.get_social_login(adapter, app, token, access_token)
|
||||
complete_social_login(request, login)
|
||||
except HTTPError:
|
||||
raise serializers.ValidationError('Incorrect value')
|
||||
except OAuthError as e:
|
||||
raise serializers.ValidationError(str(e))
|
||||
|
||||
if not login.is_existing:
|
||||
login.lookup()
|
||||
|
|
Loading…
Reference in New Issue
Block a user