【问题标题】:How to set up django-social-auth for website authentication如何为网站身份验证设置 django-social-auth
【发布时间】:2011-11-01 05:51:57
【问题描述】:

是否有任何简单且完整记录的方式来配置 django-social-auth(https://github.com/omab/django-social-auth.git)?文档太不完整了。模板丢失了,怎么回事包含所有网址?

【问题讨论】:

标签: django facebook authentication


【解决方案1】:

首先你必须在用户点击的地方生成de url,在args中你放置回调的url:

args = { 'client_id': settings.FACEBOOK_APP_ID, 'scope': settings.FACEBOOK_SCOPE, 'redirect_uri': request.build_absolute_uri('/authentication_callback'), } HttpResponseRedirect('https://www.facebook.com/dialog/oauth?' + urllib.urlencode(args)

回调代码:

token = request.GET.get('code') args = { 'client_id': settings.FACEBOOK_APP_ID, 'client_secret': settings.FACEBOOK_APP_SECRET, 'redirect_uri': request.build_absolute_uri('/authentication_callback'), 'code': token, } # Get a legit access token target = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(args)).read() response = cgi.parse_qs(target) access_token = response['access_token'][-1] # Read the user's profile information fb_profile = urllib.urlopen('https://graph.facebook.com/me?access_token=%s' % access_token) fb_profile = json.load(fb_profile) # These is the info of the facebook account: first=fb_profile['first_name'] last=fb_profile['last_name'] email=fb_profile['email'] fb_id=fb_profile['id']

希望对你有帮助

【讨论】:

  • 虽然这是关于 FB 身份验证的可靠信息,但与配置 django-social-auth 无关。
猜你喜欢
  • 1970-01-01
  • 2011-09-08
  • 2012-10-21
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 1970-01-01
  • 2017-06-05
  • 2016-08-04
相关资源
最近更新 更多