mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-12-01 21:33:45 +03:00
Fixing SocialLoginSerializer
This commit is contained in:
parent
54fb1de5d2
commit
e5f1bf62ab
|
@ -44,7 +44,6 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
|
|
||||||
'corsheaders',
|
|
||||||
|
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
|
@ -57,7 +56,7 @@ INSTALLED_APPS = (
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'corsheaders.middleware.CorsMiddleware',
|
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
|
|
@ -7,7 +7,9 @@ class SocialLoginSerializer(serializers.Serializer):
|
||||||
|
|
||||||
access_token = serializers.CharField(required=True)
|
access_token = serializers.CharField(required=True)
|
||||||
|
|
||||||
def validate_access_token(self, value):
|
|
||||||
|
def validate(self, attrs):
|
||||||
|
access_token = attrs['access_token']
|
||||||
|
|
||||||
view = self.context.get('view')
|
view = self.context.get('view')
|
||||||
request = self.context.get('request')
|
request = self.context.get('request')
|
||||||
|
@ -22,12 +24,12 @@ class SocialLoginSerializer(serializers.Serializer):
|
||||||
|
|
||||||
self.adapter = self.adapter_class()
|
self.adapter = self.adapter_class()
|
||||||
app = self.adapter.get_provider().get_app(request)
|
app = self.adapter.get_provider().get_app(request)
|
||||||
token = self.adapter.parse_token({'access_token': value})
|
token = self.adapter.parse_token({'access_token': access_token})
|
||||||
token.app = app
|
token.app = app
|
||||||
|
|
||||||
try:
|
try:
|
||||||
login = self.adapter.complete_login(request, app, token,
|
login = self.adapter.complete_login(request, app, token,
|
||||||
response=value)
|
response=access_token)
|
||||||
token.account = login.account
|
token.account = login.account
|
||||||
login.token = token
|
login.token = token
|
||||||
complete_social_login(request, login)
|
complete_social_login(request, login)
|
||||||
|
@ -37,6 +39,6 @@ class SocialLoginSerializer(serializers.Serializer):
|
||||||
if not login.is_existing:
|
if not login.is_existing:
|
||||||
login.lookup()
|
login.lookup()
|
||||||
login.save(request, connect=True)
|
login.save(request, connect=True)
|
||||||
self.object = {'user': login.account.user}
|
attrs['user'] = login.account.user
|
||||||
|
|
||||||
return value
|
return attrs
|
||||||
|
|
|
@ -75,5 +75,5 @@ ACCOUNT_ACTIVATION_DAYS = 1
|
||||||
SITE_ID = 1
|
SITE_ID = 1
|
||||||
|
|
||||||
MIGRATION_MODULES = {
|
MIGRATION_MODULES = {
|
||||||
'rest_framework.authtoken': 'rest_framework.authtoken.migrations',
|
'authtoken': 'authtoken.migrations',
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user