领带验证 [英] LinkedIn Authentication
问题描述
验证失败
我试图没有成功,让我的用户通过Python中的Oauth身份验证登录LinkedIn。我在python中使用Django,不使用任何第三方社交认证。我使用指南使用Python和Django访问API。但是我无法获取访问令牌。我可以让用户登录并获得验证码。我提出了一个新的要求,因为早先的问题太复杂了。您可以在这里看到:在Django中的URL字符串上执行POST
没有任何解决方案,仍然不确定这是LinkedIn或代码的问题。 LinkedIn在这里没有什么特别的帮助。
Nothing was resolved and still unsure if this is an issue with LinkedIn or the code. LinkedIn have not been particularly helpful here, sadly.
但在获取作者代码之后,我根本无法获取访问令牌。我收到一个400错误的一切,尽管收到作者的代码,根据文档的建议发布,我得到以下:
but after getting the Author code, I simply cannot get the access token. I'm getting a 400 error for everything and despite getting the author code, on posting as the documentation suggests, I get the following:
u'oauth_problem=parameter_absent&oauth_parameters_absent=oauth_consumer_key%26oauth_signature%26oauth_signature_method%26oauth_token%26oauth_timestamp%26oauth_verifier'
我把Python代码全部包含在这里,希望有人能够发现出了什么问题。
I'm enclosing my Python code here in its entirety in the hope that someone can spot what is going wrong.
import oauth2 as oauth
import httplib2
import time, os, simplejson
import urllib
import urllib2
import pycurl
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.core.urlresolvers import resolve
#from django.core.shortcuts import render, redirect
from django import forms
from django.utils import timezone
import urlparse
import requests
consumer_key = 'Yours'
consumer_secret = 'Yours'
user_token = 'Yours'
user_secret = 'Yours'
consumer = oauth.Consumer(consumer_key, consumer_secret)
access_token = oauth.Token(key=user_token,secret=user_secret)
client = oauth.Client(consumer, access_token)
request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken'
access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken'
authorize_url = 'https://www.linkedin.com/uas/oauth/authenticate'
def login(request):
redirect_uri = urllib2.quote('http://127.0.0.1:9000/loginsuccess')
codeURL = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=c3skrqz5wqmm&scope=r_fullprofile&state=DCEEFWF45453sdffef425&redirect_uri=" + redirect_uri
# Fill the keys and secrets you retrieved after registering your app
# Use your API key and secret to instantiate consumer object
#resp,content = client.request("http://api.linkedin.com/v1/people/~?format=json", "GET", "")
#resp, content = client.request(request_token_url, "POST")
#request_token = dict(urlparse.parse_qsl(content))
#return HttpResponse(access_token)
return HttpResponseRedirect(codeURL)
def loginsuccess(request):
authcode = request.GET.get('code')
redirect_uri = 'http://www.jelt.com'
#redirect_succ = 'http://www.127.0.0.1:8080/manage'
postdata = {
'grant_type': 'authorization_code',
'code': authcode,
'redirect_uri': redirect_uri,
'client_id': consumer_key,
'client_secret': consumer_secret,
}
r = requests.post(access_token_url, data=postdata)
#return HttpResponse(r.text)
#return HttpResponse(r.status_code)
return HttpResponseRedirect(redirect_uri)
def Manage(request):
return HttpResponseRedirect('http://www.xyz.com')
def success(request):
redirect_uri = urllib2.quote('http://www.xyz.com')
redirect_uri = "http://www.xyz.com"
return HttpResponseRedirect(redirect_uri)
推荐答案
p>您的登录
代码正在重定向到OAuth 2.0端点 https://www.linkedin.com/uas/oauth2/authorization
但您的回调 loginsuccess
正在尝试从 https://api.linkedin.com/uas/oauth/获取OAuth 1.0a令牌的accessToken
。您需要将您的 access_token_url
更新到OAuth 2.0端点 https://www.linkedin.com/uas/oauth2/accessToken
根据 LinkedIn文档。
Your login
code is redirecting to the OAuth 2.0 endpoint https://www.linkedin.com/uas/oauth2/authorization
but your callback loginsuccess
is trying to fetch the OAuth 1.0a token from https://api.linkedin.com/uas/oauth/accessToken
. You need to update your access_token_url
to the OAuth 2.0 endpoint https://www.linkedin.com/uas/oauth2/accessToken
per the LinkedIn docs.
这篇关于领带验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!