Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autnticate/Create user from acces_token #233

Closed
ranjeetsghrix opened this issue Mar 31, 2014 · 13 comments
Closed

Autnticate/Create user from acces_token #233

ranjeetsghrix opened this issue Mar 31, 2014 · 13 comments

Comments

@ranjeetsghrix
Copy link

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 #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
@omab
Copy link
Owner

omab commented Mar 31, 2014

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

@ranjeetsghrix
Copy link
Author

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

@omab
Copy link
Owner

omab commented Apr 2, 2014

Cool, thanks for closing the issue.

@ranjeetsghrix
Copy link
Author

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

@omab
Copy link
Owner

omab commented Apr 2, 2014

@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=...')

@ranjeetsghrix
Copy link
Author

@omab It gives me 401 Client Error: Unauthorized

@omab
Copy link
Owner

omab commented Apr 2, 2014

@ranjeetsghrix, do you have a traceback?

@dkwasniak
Copy link

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

@omab
Copy link
Owner

omab commented Oct 15, 2014

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

@dkwasniak
Copy link

@omab
Copy link
Owner

omab commented Oct 15, 2014

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

@dkwasniak
Copy link

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

@elmkarami
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants