如何处理 Laravel Passport 中的“unsupported_grant_type”

Mat*_*ias 5 php oauth-2.0 laravel clientcredential

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

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

我按照某人的教程(例如本教程)来实现这些资助类型,但我陷入困境......

我做了以下事情:

  • 装载护照:composer require laravel/passport
  • 将服务提供商添加到config/app.phpLaravel\Passport\PassportServiceProvider::class,
  • 迁移:php artisan migrate
  • 安装:php artisan passport:install
  • 添加HasApiTokensApp\User.php
  • 添加Passport::routes()app/Providers/AuthServiceProvider.php
  • 最后但并非最不重要的一点是将身份验证防护的驱动程序选项设置为passportinconfig/auth.php

到目前为止,一切都很好。现在我创建了一个示例客户端php artisan passport:client

New client created successfully.
Client ID: 3
Client secret: S5s9oEIRm5DNy5ySsr1H6jWlraOCZyF24gcpoDrJ
Run Code Online (Sandbox Code Playgroud)

现在,当我想使用邮递员为该客户端获取令牌时(添加到此处body.formdata提供的类似内容中) 邮递员:调用 oauth/token

我收到以下错误。

{
    "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."
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我想我已经完成了注册grant type?的所有必要步骤。

提前致谢!!

nah*_*hri 3

你拼错了grant_type。屏幕截图中写着grand_type