0

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!

OmriToptix
  • 1,219
  • 1
  • 15
  • 22
  • Did you check redirect_uri property? Also check what's set in response with error code. There should be some additional message explaining what's wrong. – daniula May 15 '14 at 10:20
  • This process doesn't work with Twitter right now, there's an issue to track it at https://github.com/omab/python-social-auth/issues/272 and I need to set a time to work on it. – omab May 15 '14 at 16:02

2 Answers2

0

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.

OmriToptix
  • 1,219
  • 1
  • 15
  • 22
0

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

po5i
  • 548
  • 5
  • 19