Laravel Passport - 不支持授权类型
Laravel Passport - Grant Type Not Supported
我已经根据文档安装了 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"
}
这些是我要发布到的字段 /oauth/token
client_id = 4
client_secret = SMiYE7XqDNtXKQnmkYmFnXxfAaV83vRhnJ9zwCtZ
username = jcrawford@domain.com
password = **************
grant_type = password
scope = *
我有运行php artisan passport:install
我也试过运行宁php artisan passport:client --password
两个命令都有效并且都创建了客户端和机密,但是,我似乎无法克服关于 grant_type 的错误。
有什么建议可以解决这个问题,以便密码授予令牌对我有用吗?
看来您必须将参数作为表单数据发送,而不是像我那样在 headers 中发送...菜鸟错误!
初始URL
https://restfulapi.test/oauth/authorize?client_id=3&redirect_url=http://restfulapi.test?response_type=code
解决方案
https://restfulapi.test/oauth/authorize?client_id=3&redirect_url=http://restfulapi.test&response_type=code
我不得不将 response_type 之前的问号替换为 &
我正在使用 Postman,并且我已将所有参数放入 Params。邮递员显示以下响应
{
"error": "unsupported_grant_type",
"message": "The authorization grant type is not supported by the authorization server.",
"hint": "Check the `grant_type` parameter"
}
现在我把所有的参数都放在 Body 里,然后按下 Send 按钮,效果很好。
对我来说,问题是我没有使用 Request $request
,我使用的是我创建的 RegisterRequest
$request。
阅读 Laravel 文档让我减轻了很多压力。 oauth\token
用于使用指定的授权类型检索令牌,路由将 return 包含 access_token、refresh_token 和 [=35= 的 JSON 响应] 属性。 expires_in 属性包含访问令牌过期前的秒数 (ref) 你应该
- 安装护照
- 发布服务提供商和迁移并迁移。
- 为 login/register 设置路由以创建帐户并登录。
- 在您的用户模型中,添加
HasApiTokens
from use Laravel\Passport\HasApiTokens;
- 在登录方法的响应中,将令牌添加为响应的一部分。
- 测试你对邮递员的反应
我已经根据文档安装了 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"
}
这些是我要发布到的字段 /oauth/token
client_id = 4
client_secret = SMiYE7XqDNtXKQnmkYmFnXxfAaV83vRhnJ9zwCtZ
username = jcrawford@domain.com
password = **************
grant_type = password
scope = *
我有运行php artisan passport:install
我也试过运行宁php artisan passport:client --password
两个命令都有效并且都创建了客户端和机密,但是,我似乎无法克服关于 grant_type 的错误。
有什么建议可以解决这个问题,以便密码授予令牌对我有用吗?
看来您必须将参数作为表单数据发送,而不是像我那样在 headers 中发送...菜鸟错误!
初始URL
https://restfulapi.test/oauth/authorize?client_id=3&redirect_url=http://restfulapi.test?response_type=code
解决方案
https://restfulapi.test/oauth/authorize?client_id=3&redirect_url=http://restfulapi.test&response_type=code
我不得不将 response_type 之前的问号替换为 &
我正在使用 Postman,并且我已将所有参数放入 Params。邮递员显示以下响应
{
"error": "unsupported_grant_type",
"message": "The authorization grant type is not supported by the authorization server.",
"hint": "Check the `grant_type` parameter"
}
现在我把所有的参数都放在 Body 里,然后按下 Send 按钮,效果很好。
对我来说,问题是我没有使用 Request $request
,我使用的是我创建的 RegisterRequest
$request。
阅读 Laravel 文档让我减轻了很多压力。 oauth\token
用于使用指定的授权类型检索令牌,路由将 return 包含 access_token、refresh_token 和 [=35= 的 JSON 响应] 属性。 expires_in 属性包含访问令牌过期前的秒数 (ref) 你应该
- 安装护照
- 发布服务提供商和迁移并迁移。
- 为 login/register 设置路由以创建帐户并登录。
- 在您的用户模型中,添加
HasApiTokens
from use Laravel\Passport\HasApiTokens; - 在登录方法的响应中,将令牌添加为响应的一部分。
- 测试你对邮递员的反应