Search code examples
phplaravelcurllaravel-passport

How do I set the password on a Laravel Passport client?


I'm trying to set up laravel as an API. I've gone through their documentation on passport and have set up a client with the command php artisan passport:client --password. I gave the client a name and it gave me the id and the secret. But the documentation also asks for the password and none has been set. I tried to connect to it using curl, but all I get back is {"error":"invalid_client","message":"Client authentication failed"}. Where do I set the password for a laravel passport client?

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:8000/oauth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ("X-Requested-With: XMLHttpRequest"));

$postData = array(
  'client_id' => '2',
  'client_secret' => 'RSR6H3nRaVH0HQIfdC27eY98y1dhbi09UyFm5ckR',
  'grant_type' => 'password',
  'username' => 'Test',
  'password' => '????',
  'scope' => '*'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
print_r( curl_exec ($ch));

Solution

  • From the look of it you are using password grant as your auth grant type. For this grant type the username and password is your user's username and password. Password grant uses user login info to generate a unique token for a paticular user.