我尝试使用Python Social Auth和Tastypie来验证我的应用程序的Facebook用户。我在请求的发布数据中传入访问令牌。
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)
我正在获得全球名称&#39;策略&#39;没有定义&#34;,任何帮助将不胜感激。
答案 0 :(得分:0)
尝试在 auth_user 方法中添加以下代码行,
strategy = load_strategy(request)