I'm working under TDD, and I'm making a test to get a token using Password Grant Tokens with Laravel Passport, I've made the test manually (sending a curl with the client id, client secret, user and password) to the endpoint, and it works! It returns me a token, I'm using a client id and a client secret generated by the php artisan passport:install --uuids
command (I've already made all previous configurations)
But now I want to write the test to generate that token, I have this code:
public function test_request_token() {
$email = "user@test.com";
$password = "123456";
// Create the user
$this->post("api/register", [
"email" => $email,
"password" => $password,
"password_confirmation" => $password
]);
// Ask for a token
$response = $this->post("oauth/token", [
'grant_type' => 'password',
'client_id' => '92d16637-6c65-42c4-9ba2-b940d8dc3d0b',
'client_secret' => 'Sx20PJJkmED46X2HzvhoLPHeXnoE7sNp6hNqTdBw',
'username' => $email,
'password' => $password,
'scope' => ''
]);
dd($response);
$response->assertStatus(200);
}
But it doesn't work, those credentials (client id and client secret) are the credentials that the php artisan passport:install --uuids
command gave me (and are the same credentials that I've used to make the manual test with a curl that works)
I've putted a dd()
function there to see what was happening, and the error is Client authentication failed
so I think the test aren't reading the credentials generated by Laravel, how can I do to use those credentials?
I've tried to get credentials from the POST /oauth/clients
endpoint but it says that it needs a user logged in, but I don't want to create users, my application doesn't allow clients creation, I just need one client on my application, and that client is the generated by Laravel Passport, so how can I do this?
Aucun commentaire:
Enregistrer un commentaire