Open taime opened 6 years ago
Hi @taime What error does it display on connect?
Environment:
Request Method: POST
Request URL: http://instametrics.gyds.ru/rest-auth/vk/connect/
Django Version: 2.0.3
Python Version: 3.5.5
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_filters',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.vk',
'allauth.socialaccount.providers.twitter',
'storages',
'core',
'api']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapper
62. return bound_func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/utils/decorators.py" in bound_func
58. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python3.5/site-packages/rest_auth/views.py" in dispatch
49. return super(LoginView, self).dispatch(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
494. response = self.handle_exception(exc)
File "/usr/local/lib/python3.5/site-packages/rest_framework/views.py" in handle_exception
454. self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
491. response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/rest_auth/views.py" in post
93. self.serializer.is_valid(raise_exception=True)
File "/usr/local/lib/python3.5/site-packages/rest_framework/serializers.py" in is_valid
236. self._validated_data = self.run_validation(self.initial_data)
File "/usr/local/lib/python3.5/site-packages/rest_framework/serializers.py" in run_validation
438. value = self.validate(value)
File "/code/core/serializers.py" in validate
72. login = self.get_social_login(adapter, app, social_token, access_data)
File "/usr/local/lib/python3.5/site-packages/rest_auth/registration/serializers.py" in get_social_login
58. social_login = adapter.complete_login(request, app, token, response=response)
File "/code/allauth/socialaccount/providers/vk/views.py" in complete_login
54. extra_data = resp.json()['response'][0]
Exception Type: KeyError at /rest-auth/vk/connect/
Exception Value: 'response'
And here is the project: https://github.com/taime/imetrics
Added answer on Stackoverflow
Since VK requires custom provider logic, you need to use serializer with logic defined in VKOAuth2Serializer
but with social login state process being set to connect. You can achieve it by creating a subclass of VKOAuth2Serializer
with SocialConnectMixin
.
So your new serializer and connect view would look the following way:
Serializer:
from rest_auth.registration.serializers import SocialConnectMixin
class VKOAuth2ConnectSerializer(SocialConnectMixin, VKOAuth2Serializer):
pass
View:
class VkConnect(SocialConnectView):
adapter_class = VKOAuth2Adapter
serializer_class = VKOAuth2ConnectSerializer
As I noticed on Stackoverflow: this doesn't work as connection. This works like registration/login.
Hello! Please help me make social connect for provider Vkontakte. I've already have VKOAuth2Serializer that works fine for login and register. But connect doesnt' work. Here is urls:
Views:
Serializers
Please tell me how to do connect. And also I want to ask, why nobody implement serializers for 3d party providers to library? Why only twitter and facebook? Would you add Vkontakte if I make pull request?
Thank you.
project is here: https://github.com/taime/imetrics