如何处理 laravel 护照中的 "unsupported_grant_type"

How to handle "unsupported_grant_type" from laravel passport

我正在尝试 laravel 并尝试启用客户端凭据授权以保护某些 api 端点。

提供一些背景信息: 我想创建一个位于数据库和多个网站(和 SPA)之间的 api。因此,我将能够进行一些监控(website/SPA 调用哪些资源)并通常增加一些安全性。因此,在这种不需要额外用户信息的情况下,机器对机器通信的客户端凭据授予应该是最好的方法。

我按照某人的教程(例如 this tutrial)实现了这些授权类型,但我卡住了...

我做了以下事情:

到目前为止一切顺利。现在我用 php artisan passport:client:

创建了一个示例客户端
New client created successfully.
Client ID: 3
Client secret: S5s9oEIRm5DNy5ySsr1H6jWlraOCZyF24gcpoDrJ

现在,当我想通过邮递员为这个客户端获取令牌时(添加到 body.formdata 中,如提供的 here

我收到以下错误。

{
    "error": "unsupported_grant_type",
    "error_description": "The authorization grant type is not supported by the authorization server.",
    "hint": "Check that all required parameters have been provided",
    "message": "The authorization grant type is not supported by the authorization server."
}

我错过了什么吗?我以为我做了所有必要的步骤来注册 grant type

提前致谢!!

如你所说,这是针对 SPA 的 所以

试试这个

grant_type: "password"
client_id:3
username:"your email"
password: "your password"
scope: "*"

把这个放在你的邮递员里

通过这个你会得到 access tokenrefresh token 对于那个特定的用户

ref link https://laravel.com/docs/5.8/passport#requesting-password-grant-tokens

您拼写错误 grant_type。在屏幕截图中显示 grand_type