Autnticate/Create user from acces_token
I want to authenticate and create the user by access token where the access token can be sent by the Iphone/android mobile.I have googled this issue and Found some useful info but that was mostly regarding Django social auth not python social auth. I have also find out this one question mostly similar to my question https://github.com/omab/python-social-auth/issues/180 but his problem is related to twitter and I want to know how to register user related any back-end.
I have used this code but it gives me the error 'unicode' object has no attribute 'do_auth' , I have called this function by
url -> url(r'^auth/(?P<backend>[^/]+)/$',register_by_access_token, name="test_auth"),
and backend I am using is facebook.
@strategy()
def register_by_access_token(request, backend, *args, **kwargs):
access_token = {pass static token for testing purpose}
if not access_token:
raise AuthMissingParameter(backend, 'access_token')
user = backend.do_auth(access_token)
if user and user.is_active:
login(request, user)
return user
Try doing request.strategy.backend.do_auth(access_token).
Thanks a lot , you save my day or I don't know may be days :+1: )
Cool, thanks for closing the issue.
@omab One general question , In case of twitter what will be the access token because there are two things that we get from twitter oauth_token_secret and oauth_token.
@ranjeetsghrix, you can pass it as a dict or as a querystring (the usual format of OAuth1 access-tokens). Like this:
backend.do_auth({'oauth_token': '...', 'oauth_token_secret': '...'})
or
backend.do_auth('oauth_token=...&oauth_token_secret=...')
@omab It gives me 401 Client Error: Unauthorized
@ranjeetsghrix, do you have a traceback?
Hello,
I have got the same problem like @ranjeetsghrix. I have also tried your suggestion @omab but it doesn't work for me. I hava two kinds of errors.
- When I am trying with backend.do_auth(access_token), I have got:
'unicode' object has no attribute 'do_auth' - When I am trying with request.strategy.backend.do_auth(access_token), I have got:
'DjangoStrategy' object has no attribute 'backend'
I am completely new in python and maybe I made some mistakes. I will be grateful for your help.
BR avonil
@avonil, what's the code you are trying? How do you get the backend?
@omab I am trying with:
https://gist.github.com/avonil/3ae50f1e22dce966a7a9#file-gistfile1-py
@avonil, that snippet looks good, how are you calling that view (what's the URL)?
@omab
192.168.0.100:8000/api/register-by-token/facebook?access_token=
After that I have got error like above.
As I told I am new and maybe I don't understand something. Should I get backend instance somewhere before ?
@avonil instead of backend.do_auth try request.backend.do_auth