1

I'm trying to use Python Social Auth and Tastypie to authenticate Facebook users to my application. I'm passing in the access token in the post data of the request.

from social.apps.django_app import load_strategy

class SocialSignUpResource(ModelResource):

class Meta:
    queryset = User.objects.all()
    allowed_methods = ['post']
    resource_name = "social_sign_up"
    include_resource_uri = False

def prepend_urls(self):
    return [            
        url(r'^(?P<resource_name>%s)/auth%s$' %
            (self._meta.resource_name, trailing_slash()),
            self.wrap_view('auth_user'), name='api_auth_user'),  
    ]

def auth_user(self, request, **kwargs):
    data = json.loads(request.body)
    provider = data.get('provider', '')
    access_token = data.get('access_token', '')
    print "provider "+provider +" access_token " +access_token
    strategy = load_strategy(backend=provider)
    user = strategy.backend.do_auth(access_token)

I'm getting global name 'strategy' is not defined", any help would be appreciated.

reevh
  • 735
  • 2
  • 8
  • 20

1 Answers1

1

Try adding this line of code inside auth_user method,

strategy = load_strategy(request)
Sentient07
  • 1,270
  • 1
  • 16
  • 24