2011-11-01 80 views
0

是否有任何简单且完整的配置django-social-auth(https://github.com/omab/django-social-auth.git)的方式?文档是如此不完整。模板不见了,所有的url都有哪些?如何设置django-social-auth进行网站身份验证

+0

有一个示例项目显示了要设置的内容。你有哪些麻烦? https://github.com/omab/django-social-auth/tree/master/example –

+0

我花了5个小时才真正理解文档,但我的应用程序现在工作正常。感谢 –

回答

2

首先,你必须在用户点击,在args你把回调的URL产生解网址:

 


    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'] 

 

希望这有助于

 


    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) 

 

回调的代码

+0

虽然这是关于FB身份验证的可靠信息与配置django-social-auth无关。 –

+0

你说得对,我只是在建议一个解决办法。 – andrebola

相关问题