Search code examples
twittertastypiepython-social-auth

Authenticate with twitter tastypie python social auth return 403


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!


Solution

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