Laravel Passport - 不支持授权类型

Jos*_*ord 16 laravel-5.3 laravel-passport

我根据文档安装了Laravel Passport,并且修改了所需的代码的所有区域.

我正在设置密码授予令牌,以便用户在使用他们的站点用户名和密码登录时能够获得API令牌.当涉及到grant_type时,我遇到了一个问题.出于某种原因,Laravel抱怨无效的授权类型.

{
  "error": "unsupported_grant_type",
  "message": "The authorization grant type is not supported by the authorization server.",
  "hint": "Check the `grant_type` parameter"
}
Run Code Online (Sandbox Code Playgroud)

这些是我要发布的字段 /oauth/token

client_id = 4
client_secret = SMiYE7XqDNtXKQnmkYmFnXxfAaV83vRhnJ9zwCtZ
username = jcrawford@domain.com
password = **************
grant_type = password
scope = *
Run Code Online (Sandbox Code Playgroud)

我跑了php artisan passport:install,我也跑了php artisan passport:client --password

这两个命令都有效,并且都创建了客户端和机密,但是,我似乎无法通过grant_type的错误.

关于我应该怎样看待解决的任何建议,以便密码授予令牌对我有用?

Jos*_*ord 30

您似乎必须将参数作为表单数据发送,而不是像我一样在标题中发送...新手错误!

  • 更正它必须像表单数据一样进入正文。 (2认同)

小智 7

我正在使用Postman,并将所有参数都放在Params中。邮递员显示以下回应

{
    "error": "unsupported_grant_type",
    "message": "The authorization grant type is not supported by the authorization server.",
    "hint": "Check the `grant_type` parameter"
}
Run Code Online (Sandbox Code Playgroud)

现在,我将所有参数都放在“正文”中,然后按“发送”按钮,效果很好。