Laravel Passport invalid_grant 用于密码 grant_type

Dam*_*mon 5 laravel laravel-passport laravel-6

我一直在尝试access_token为我的 api创建一个。我遵循了设置并使用 Postman 来测试/创建令牌。我似乎无法克服invalid_grant错误。

我已经尝试了我能找到的所有组合,但没有任何运气。这是我的设置:

发送POST请求至:http://mywebsite.local/oauth/token

在正文中,我设置form-data为这个(名称/值):

grant_type      password
client_id       1
client_secret   <super_long_string>
username        my@email.com
password        secret
Run Code Online (Sandbox Code Playgroud)

我使用 tinker 创建了一个虚拟用户:

factory('App\User')->create()
Run Code Online (Sandbox Code Playgroud)

我在上面使用新创建的用户作为我的用户名/密码。

不管我在做什么(没有传递任何东西),这是我总是看到的错误:

{
    "error": "invalid_grant",
    "error_description": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
    "hint": "",
    "message": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
}
Run Code Online (Sandbox Code Playgroud)

我已经阅读了很多次,这意味着grant_type我试图获得的与客户端不匹配。我正在使用php artisan passport:client --password创建客户端,所以我不明白为什么它无效。我只有一个客户端,所以我知道我使用的是正确的id. 这个问题似乎是同一件事,我看到了,但此后已关闭。

对于我的标头,我只设置了Content-Type application/json,而我没有为 Authorization 标头设置任何内容。

我不知道还有什么可以尝试的。感谢您的任何建议!

Mik*_*ike 7

正如此处所述,从 5.8 版本开始,默认密码“secret”已更新为“password”。所以你正在输入旧密码。