Comments (12)
Thanks for reply.
I use following view:'
class VKLogin(SocialLogin):
adapter_class = VKOAuth2Adapter
and receive following error
TypeError at /api/auth/vk/
string indices must be integers
which is result of following line in SocialLoginSerializer
login = self.adapter.complete_login(request, app, token,
response=access_token)
since complete_login in VK0Auth2Adapter is defined a little bit deferent that in Facebook0Auth2Adapter:
def complete_login(self, request, app, token, **kwargs):
uid = kwargs['response']['user_id']
resp = requests.get(self.profile_url,
params={'access_token': token.token,
'fields': ','.join(USER_FIELDS),
'user_ids': uid})
resp.raise_for_status()
extra_data = resp.json()['response'][0]
return self.get_provider().sociallogin_from_response(request,
extra_data)
Mainly you a need also to pass user_id (kwargs['response']['user_id']) to obtain relevant response according http://vk.com/dev/users.get. And as I understand from VK API docs on this step access_token is not required.
from django-rest-auth.
The problem is actual. Please reopen issue.
from django-rest-auth.
I have the same problem too:
File ... in complete_login
37. uid = kwargs['response']['user_id']
Exception Type: TypeError at /api/vk/
Exception Value: string indices must be integers
What to do?
from django-rest-auth.
Sure, you can create your own SocialLoginSerializer and define your own view class, like:
from rest_auth.views import Login
class CustomLogin(Login):
serializer_class = CustomSocialLoginSerializer
adapter_class = VKOAuth2Adapter
Could you paste error traceback which you get when using VK adapter?
from django-rest-auth.
So the only solution for you at this moment is to define you own social login serializer basing on SocialLoginSerializer and override validate method. There is no way to make it simpler, unfortunately.
You can also fork this project, make a patch and create a pull request to apply it to DRA code.
from django-rest-auth.
That's exactly what I was planing to do.
from django-rest-auth.
By the way, I am glad you fixed UserDetailsSerializer import in rest_auth/registration/views.py in v0.3.3 (e9fee3a).
from django-rest-auth.
Hi gorros, sorry I write it here, did you solve vk authorization issue? Can you help me with that?
My email is [email protected]
from django-rest-auth.
@sburavtsov This was a while ago, but according to my code this should solve the problem.
class CustomVKOAuth2Adapter(VKOAuth2Adapter):
def complete_login(self, request, app, token, **kwargs):
uid = kwargs['response']['user_id']
resp = requests.get(self.profile_url,
params={'fields': ','.join(USER_FIELDS),
'user_ids': uid})
resp.raise_for_status()
extra_data = resp.json()['response'][0]
return self.get_provider().sociallogin_from_response(request,
extra_data)
from django-rest-auth.
Than you! I will try it.
With the best regards, Sergey
Skype: serobur_skype
Phone: +7 960 102 40 40
On Feb 8, 2016, at 23:24, Gor Hayrapetyan [email protected] wrote:
@sburavtsov https://github.com/sburavtsov This was a while ago, but according to my code this should solve the problem.
class CustomVKOAuth2Adapter(VKOAuth2Adapter):
def complete_login(self, request, app, token, **kwargs): uid = kwargs['response']['user_id'] resp = requests.get(self.profile_url, params={'fields': ','.join(USER_FIELDS), 'user_ids': uid}) resp.raise_for_status() extra_data = resp.json()['response'][0] return self.get_provider().sociallogin_from_response(request, extra_data)
—
Reply to this email directly or view it on GitHub #45 (comment).
from django-rest-auth.
I had the same problem so I had to find the solvation. The point is here:
File "/home/kamirt/nissaenv/lib/python3.4/site-packages/rest_auth/registration/serializers.py", line 247, in validate
login = self.get_social_login(adapter, app, social_token, access_token)
File "/home/kamirt/nissaenv/lib/python3.4/site-packages/rest_auth/registration/serializers.py", line 180, in get_social_login
social_login = adapter.complete_login(request, app, token, response=response)
This "response" parameter in case VK must be like this: {user_id:*******, access_token: *******, expire_time: *******}. But this function passes already parsed response (only access_code).
from django-rest-auth.
So what is the final solution?
Here is the whole code in urls.py:
from allauth.socialaccount.providers.vk.views import VKOAuth2Adapter
class CustomVKOAuth2Adapter(VKOAuth2Adapter):
def complete_login(self, request, app, token, **kwargs):
uid = kwargs['response']['user_id']
resp = requests.get(self.profile_url,
params={'fields': ','.join(USER_FIELDS),
'user_ids': uid})
resp.raise_for_status()
extra_data = resp.json()['response'][0]
return self.get_provider().sociallogin_from_response(request,
extra_data)
in urlpatterns:
url(r'^rest-auth/vk/$', CustomVKOAuth2Adapter, name='vk_login'),
And I get error in browser what open http://127.0.0.1:8000/rest-auth/vk/:
AttributeError at /rest-auth/vk/ 'CustomVKOAuth2Adapter' object has no attribute 'status_code'
How to fix it?
from django-rest-auth.
Related Issues (20)
- Password Reset Confirm Expect parameter which is not in email HOT 1
- TEMPLATE DOES NOT EXIST
- Option to just need one password field for new account / reset/change password. HOT 2
- Can't login without email even though it's supposed to be optional
- Django and react login with google HOT 2
- TypeError: 'PhoneNumber' object is not subscriptable
- Deprectated import ugettext_lazy from django.utils.translation HOT 1
- ConnectionRefusedError: Registration endpoint response
- Update for Django 4.0 HOT 6
- Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name. HOT 8
- Wrong response on using login without verifying the user HOT 1
- `LogoutView`'s non-compliance with `drf-spectacular`
- ImportError: cannot import name 'url' from 'django.conf.urls' HOT 6
- The package doesn't work with django 4.0.*
- The package doesn't work with django 4.0.* HOT 1
- The package doesn't work with django 4.0
- The package doesn't work with django 4.0.*
- ImproperlyConfigured at /api/v1/auth/registration/account-email-verification-sent/
- The package doesn't work with Django from 3.12
- Failed to run with the lates allauth lib HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-rest-auth.