【问题标题】:Check the "grant_type" parameter检查“grant_type”参数
【发布时间】:2016-10-02 19:25:11
【问题描述】:

我根据本文档使用OAuth 2.0 进行授权:(https://developers.vendhq.com/documentation/oauth.html#oauth) 并出现此错误:

"error": "invalid_request", "error_description": "请求缺少必需的参数,包含无效的参数值,包含不止一次的参数,或者格式错误。检查“grant_type”参数。”

请求

方法:POST

Content-Type: application/x-www-form-urlencoded

URL : https://{domain_prefix}.vendhq.com/api/1.0/token

参数:

code          = {code}

client_id     = {app_id}

client_secret = {app_secret}

grant_type    = authorization_code

redirect_uri  = {redirect_uri}

【问题讨论】:

    标签: oauth-2.0


    【解决方案1】:

    根据RFC6749, section 4.1.3,POST 请求的编码正文应类似于code={code}&client_id={app_id}&client_secret={app_secret}&grant_type=authorization_code&redirect_uri={redirect_uri}

    例子:

    grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb&client_id=CLIENT_ID_1234&client_secret=CLIENT_SECRET

    不要忘记对重定向 Uri 进行编码:http://foo.bar/ => http%3A%2F%2Ffoo.bar%2F

    关于身份验证错误,可能是因为授权服务器不支持发布请求中的客户端密码(或者您的客户端不允许使用它)。 然后尝试使用基本身份验证方案添加授权标头。 此标头的值为Basic {ENCODED_AUTHENTICATION}{ENCODED_AUTHENTICATION} =base64(client_id + ':' + client_secret)

    使用此标头,必须删除 post 请求中的 client_idclient_secret。您的请求参数变为code={code}&grant_type=authorization_code&redirect_uri={redirect_uri}

    【讨论】:

    • 我没有对 uri 进行编码。感谢您给我正确的方向,现在我收到另一个错误 { "error": "invalid_client", "error_description": "Client authentication failed" }
    • 非常感谢您的帮助 :) 问题是我的代码在 10 分钟后过期。根据文档(此代码是一个短暂的对象(10 分钟)。但您的指导确实帮助了我。
    【解决方案2】:

    您需要检查您尝试将 POST 发送到的 URL。您尝试联系的服务不存在或当前不可用。

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 2019-05-16
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-14
      • 2021-01-04
      相关资源
      最近更新 更多