【问题标题】:error unsupported_grant_type with Doorkeeper device Authorization Request flow错误 unsupported_grant_type 与 Doorkeeper 设备授权请求流
【发布时间】:2022-08-08 18:32:46
【问题描述】:

当我发送访问令牌请求(轮询)时,我收到错误:\“unsupported_grant_type\”(见下文)。

注意:这是设备流程中的第二个请求,第一个请求有效。两者如下图所示。

第 1 步,设备授权请求:(有效)

POST http://localhost:3000/oauth/authorize_device
Content-Type: application/x-www-form-urlencoded 

client_id=2DIJRT72IRMycyeBS7PuGgYSJScCQ9bxnvo5_JyyKOA

(我使用 Insomnia 创建请求)

设备授权响应:(如预期)

{
    \"device_code\": \"IB7tQi1yGv2QddCUurWBsics26MZ8aUY1sriudewRn4\",
    \"user_code\": \"WTQB0W6S\",
    \"verification_uri\": \"http://localhost:3000/oauth/device\",
    \"verification_uri_complete\": \"http://localhost:3000/oauth/device?user_code=WTQB0W6S\",
    \"expires_in\": 300,
    \"interval\": 5
}

第 2 步,设备访问令牌请求/轮询:(失败)

POST http://localhost:3000/oauth/token 
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:device_code
&device_code=IB7tQi1yGv2QddCUurWBsics26MZ8aUY1sriudewRn4
&client_id=2DIJRT72IRMycyeBS7PuGgYSJScCQ9bxnvo5_JyyKOA

设备访问令牌响应:(400 错误请求)

{
    \"error\": \"unsupported_grant_type\",
    \"error_description\": \"The authorization grant type is not supported by the authorization server.\"
}

这是服务器日志显示的内容:

Started POST \"/oauth/token\" for 127.0.0.1 at 2022-07-21
Processing by Doorkeeper::TokensController#create as */*
  Parameters: {\"grant_type\"=>\"urn:ietf:params:oauth:grant-type:device_code&device_code=IB7tQi1yGv2QddCUurWBsics26MZ8aUY1sriudewRn4&client_id=2DIJRT72IRMycyeBS7PuGgYSJScCQ9bxnvo5_JyyKOA\"}
Completed 400 Bad Request in 0ms (ActiveRecord: 0.0ms | Allocations: 421)

关于我的代码:

  • 我创建了一个新的 Rails 7 项目(完整,不是仅 api 版本)
  • 已安装设计 gem
  • 安装门卫宝石
  • 已安装 doorkeeper-device_authorization_grant gem

我使用以下内容作为指南:

注意:我没有安装 rack-cors,我认为我现在不需要它,因为不要使用单独的前端,我可能会弄错。

有任何想法吗?

    标签: ruby-on-rails oauth request doorkeeper


    【解决方案1】:

    我发现了问题。这是我自己的 St#$!& 错。 我以错误的方式提交了投票请求的正文内容。全部在一行中,而不是单独的键值对。

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 2017-02-02
      相关资源
      最近更新 更多