python-social-auth icon indicating copy to clipboard operation
python-social-auth copied to clipboard

Autnticate/Create user from acces_token

Open ranjeetsghrix opened this issue 12 years ago • 13 comments

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

ranjeetsghrix avatar Mar 31 '14 10:03 ranjeetsghrix

Try doing request.strategy.backend.do_auth(access_token).

omab avatar Mar 31 '14 16:03 omab

Thanks a lot , you save my day or I don't know may be days :+1: )

ranjeetsghrix avatar Apr 02 '14 07:04 ranjeetsghrix

Cool, thanks for closing the issue.

omab avatar Apr 02 '14 07:04 omab

@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 avatar Apr 02 '14 07:04 ranjeetsghrix

@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 avatar Apr 02 '14 08:04 omab

@omab It gives me 401 Client Error: Unauthorized

ranjeetsghrix avatar Apr 02 '14 09:04 ranjeetsghrix

@ranjeetsghrix, do you have a traceback?

omab avatar Apr 02 '14 16:04 omab

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.

  1. When I am trying with backend.do_auth(access_token), I have got: 'unicode' object has no attribute 'do_auth'
  2. 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

dkej123 avatar Oct 15 '14 16:10 dkej123

@avonil, what's the code you are trying? How do you get the backend?

omab avatar Oct 15 '14 18:10 omab

@omab I am trying with:

https://gist.github.com/avonil/3ae50f1e22dce966a7a9#file-gistfile1-py

dkej123 avatar Oct 15 '14 18:10 dkej123

@avonil, that snippet looks good, how are you calling that view (what's the URL)?

omab avatar Oct 15 '14 18:10 omab

@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 ?

dkej123 avatar Oct 15 '14 18:10 dkej123

@avonil instead of backend.do_auth try request.backend.do_auth

elmkarami avatar Nov 23 '14 23:11 elmkarami