尝试使用授权码进行授权时,Salesforce 错误:{'error': 'invalid_grant', 'error_description': '身份验证失败'}

问题描述 投票:0回答:1

尝试使用 auth_code 流程获取访问令牌时,出现以下错误:{'error': 'invalid_grant', 'error_description': 'authentication failure'} 这是我使用 python 的请求 https://mysalesforceurl.my.salesforce.com/services/oauth2/token

data = { "grant_type": "authorization_code", "redirect_uri": redirect_uri, "code": auth_code, "code_verifier": code_verifier, "client_id": SALESFORCE_CLIENT_ID, "client_secret": SALESFORCE_CLIENT_SECRET } headers = { "Authorization": f"Basic {auth_header}", "Content-Type": "application/x-www-form-urlencoded" } response = requests.post(token_url, data=data, headers=headers)
我见过很多人有类似的错误,但没有人使用身份验证代码流程。

我已经选择了“允许用户自我验证”并放宽了我的应用程序中的 IP 限制。 还有其他建议吗?

authentication oauth-2.0 salesforce
1个回答
0
投票
就我而言,这是由于错误的“主机”标头而发生的。它应该设置为与您设置的redirect_uri相同的值,或者,如果您要连接到具有自定义域的客户端,则该域应该位于“Host”标头中,例如“mydomain.my.salesforce.com” ”.

我找不到任何与此相关的文档,因此只是通过使用不同的值进行测试来解决。

© www.soinside.com 2019 - 2024. All rights reserved.