首页 文章

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

提问于
浏览
1

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

“提供的授权许可无效”

Console Log

*** 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

Code:

#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

    刚刚确定了错误原因,实际上是编码错误,因为回调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)
    

相关问题