WSO2 Oauth2身份验证 - 提供的授权授权无效

时间:2015-08-20 18:44:58

标签: oauth wso2 identity wso2is

我正在使用带有Python登录应用程序的Oauth 2.0测试WSO2 Identity服务器。在成功通过获取请求代码的步骤1之后,我从另一个IdP服务器调整的例程在令牌授权步骤中抛出错误。从WSO2服务器返回的错误是:

“提供的授权许可无效”

控制台日志

*** start of login ***
Code received = 23618215e0ee701b973f548a3f8e7dda
Token Request Answered = <Response [400]>
Token Request Text = {"error":"invalid_grant","error_description":"Provided Authorization Grant is invalid."}
Token Request URL = https://extbasicpacman05.podc.sl.edst.red.com:9443/oauth2/token
Token Request Encoding = None

代码:

#print "Send Token Request now"    
# prepare lookup of token using code as input
verify='/home/claudef/tmp/oauth_2/oauth/wso2.pem'
url  = "https://extbasicpacman05.podc.sl.edst.red.com:9443/oauth2/token"
payload = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'authorization_code', 'code': str(code), 'redirect_uri': 'http://localhost/resources/oauth2Callback' }
urllib.urlencode(payload)
headers = { 'application' : 'x-www-form-urlencoded' } 
r = requests.post(url, data=payload, headers=headers, verify=verify)
print "Token Request Answered = " + str(r)  
print "Token Request Text = " + str(r.text) 
print "Token Request URL = " + str(r.url)
print "Token Request Encoding = " + str(r.encoding)

欢迎使用代码值修改授权授权的任何提示。

1 个答案:

答案 0 :(得分:0)

刚刚确定了错误原因,实际上是编码错误,因为回调URL包含缺少的端口定义。我已将语句更正为新设置,并且从WSO2服务器成功返回令牌。问题已经解决了。

错误消息“无效授权”在某种程度上令人困惑,可能是一个建议 为了未来的改进。

verify='/home/claudef/tmp/oauth2/oauth/wso2.pem'
url  = "https://extbasicpacman05.podc.sl.edst.red.com:9443/oauth2/token"
payload = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'authorization_code', 'code': str(code), 'redirect_uri': 'http://localhost:8080/resources/oauth2Callback'}
urllib.urlencode(payload)
headers = { 'application' : 'x-www-form-urlencoded' } 
r = requests.post(url, data=payload, headers=headers, verify=verify)