oauth2获取访问令牌时出现错误的凭据响应

2024-10-04 01:28:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从服务器获取acceses令牌oauth2,但响应总是说凭据不正确

    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'grant_type': 'client_credentials',
    }
    url = "http://172.15.39.95:8080/oauth/token"
    params = {"grant_type": "password", "username": "xxxxx", "password": "xxxxxx"}
    client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET)
    x = requests.get(url, params=params, auth=client_auth, headers=headers)

任何帮助都将不胜感激


Tags: 服务器clientauthurlapplicationtypepasswordparams
1条回答
网友
1楼 · 发布于 2024-10-04 01:28:05

我想您想使用资源所有者密码凭据授予。请求方法应该是POST,而不是GET(如果我正确地阅读了python代码)。请参见OAuth2 RFC中的示例。 我希望服务器返回“http405methodnotallowed”错误。在

您可能应该删除grant_type: client_credentials头,将grant_type指定为参数,其正确值为password。在

很难说“坏凭证”是什么意思,因为您没有使用POST-request方法。当你改变它时,你应该得到更具体的回应。如果您的基本身份验证客户机标识+客户机密码无效,您应该获得

 HTTP/1.1 401 Unauthorized
 Content-Type: application/json;charset=UTF-8
 Cache-Control: no-store
 Pragma: no-cache

 {
   "error":"invalid_client"
 }

如果您的username+password参数无效,您应该得到

^{pr2}$

有关更多错误代码,请参阅OAuth2 RFC。在

相关问题 更多 >