Salesforce返回“ unsupported_grant_type”

mob*_*kie 5 salesforce oauth-2.0

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

{"error":"unsupported_grant_type","error_description":"grant type not supported"}
Run Code Online (Sandbox Code Playgroud)

grant_type设置为authorization_code,绝对有效。

有什么原因会使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会通过向以下地址发出POST请求来代表客户端刷新令牌:https : //login.salesforce.com/services/oauth2/token(带有有效负载):

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

mob*_*kie 5

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

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