如何解决如何在 Laravel Passport 中测试密码授予令牌流程?
我很迷茫,我想做一个测试来测试 Laravel Passport 的 Password Grant Tokens 流程,但我不知道如何。
我无法使用 php artisan client --password
生成的凭据,因为它们保存在原始数据库中,而不是保存在测试数据库中。
我尝试调用 Passport 提供的 JSON API 并返回凭据,但是当我想在令牌生成调用中使用它们时,它返回“无效凭据”,这是我的测试代码:
public function test_request_token() {
# Creating the user
$user = User::factory()->create();
Passport::actingAs($user);
# Creating credentials
$credentials = $this->post("oauth/clients",[
"name" => "Testa app","redirect" => "http://127.0.0.1/callback"
]);
# Until here all works fine,it returns me the credentials (I made a dd to check it),but now I want to ask for a token:
$response = $this->post("oauth/token",[
"grant_type" => "password","client_id" => $credentials["id"],"client_secret" => $credentials["plainSecret"],"username" => $user->email,"password" => Hash::make("password"),# Factory always have this password by default
"scope" => ""
]);
dd($response); # It returns me the error "Invalid clients"
}
所以,我不知道还能做什么来进行这个测试,我不知道我必须从哪里获得凭证来生成这个令牌......
当我通过 CURL 对其进行测试时,它可以与 Laravel 为 install
命令生成的凭据一起正常工作。
你能帮我吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。