【问题标题】:Salesforce returning "unsupported_grant_type"Salesforce 返回“unsupported_grant_type”
【发布时间】:2012-12-31 14:52:35
【问题描述】:

我们使用 Web 服务器身份验证流程实现了 OAuth 2.0。它在 10 月/ 11 月运行良好,但突然停止运行。每当我们尝试授权另一个客户端时,服务器都会返回 (400) 带有正文的错误请求

{"error":"unsupported_grant_type","error_description":"grant type not supported"}

grant_type 设置为授权码,绝对有效。

OAuth 突然停止工作有什么原因吗?


这就是我们实施 OAuth 的方式:

第一个用户被定向到:https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=blah.id&redirect_uri=https://domain.com/Web/Salesforce/Callback.aspx&scope=api%20refresh_token

Salesforce 提示用户登录他们的帐户。

一旦用户通过身份验证,Salesforce 调用 Callback.aspx,Callback.aspx 代表客户端请求刷新令牌,方法是向:https://login.salesforce.com/services/oauth2/token 发出 POST 请求,负载:

grant_type=authorization_code&code=blah.code&client_id=blah.Id&client_secret=11111111&redirect_uri=https://domain.com/Web/Salesforce/Callback.aspx

内容类型肯定是:application/x-www-form-urlencoded

【问题讨论】:

标签: salesforce oauth-2.0


【解决方案1】:

经过大量摆弄提琴手后,发现 HTTP POST 有效负载中的 grant_type=authorization_code 之前有一个空格导致了问题。

有趣的是,自 7 月以来,代码库中一直存在空间,并且此问题在 1 月 14 日首次发现。Salesforce 可能修复了错误或进行了内部更改以在 grant_type=authorization_code 之前拒绝空间。

【讨论】:

【解决方案2】:

确保您使用的是“https”而不是 http

如果您在通过终端 sfdx 命令授权 Org 时遇到此错误 -

error authenticating with auth code due to: grant type not supported

为我工作的“https”解决了我的授权类型不受支持的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2018-09-22
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多