سؤال

I'm managing my social authentication with tastypie and python-social-auth. I had no problem authenticating via facebook by doing the following :

from social.apps.django_app import load_strategy
provider = “facebook”
access_token = “CAAIkpON595IBADC8CqXgq615wfsls15u6RI23sreqbzntau”
strategy = load_strategy(backend=provider)   
user = strategy.backend.do_auth(access_token)

but when i try to do the same with provider="twitter" and a valid access token, i keep getting 403 when calling the 'do_auth' method. I managed to cURL to the twitter api, so my credentials are valid.

Am i missing any steps in the way? is twitter authentication should be different the facebook's?

Thanks!

هل كانت مفيدة؟

المحلول

The problem was i didn't added the 'redirect_uri' when defined the 'load_strategy'. Finally i ended up with this code:

# setup redirect uri in order to load strategy
    uri = redirect_uri = "social:complete"
    if uri and not uri.startswith('/'):
        uri = reverse(redirect_uri, args=(backend,))

    # load the strategy
    try:
        strategy = load_strategy(
            request=request, backend=backend,
            redirect_uri=uri, **kwargs
        )
    except MissingBackend:
        raise Http404('Backend not found')

Thanks to @omab for commenting this in the github issue page.

نصائح أخرى

I was following the examples, at the register_by_access_token method (I use django as API for an Angular app).

In the example, the line:

user = request.backend.do_auth(access_token)

Was not working with twitter with the oauth_token received by twitter, to get it work I have to create the following access_token:

access_token = {
              'oauth_token': auth[1],
              'oauth_token_secret': auth[2]
        }

Where auth[1] and [2] are the values that twitter returned.

Its weird because I didn't found this documented anywhere, I just found that people who missed SOCIAL_AUTH_TWITTER_KEY and SOCIAL_AUTH_TWITTER_SECRET get it working.

fyi: I use it with django rest framework

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top