Password Laravel Personal/Password Access Client Not Found
byWe must have stumbled on Laravel’s passport sometime for creating authentication api’s for our mobile apps providing full OAuth2 server implementation.
This post uses Laravel 7.x. Our passport installation is
composer require laravel/passport “~9.0”
We will perform the migration where Passport migrations will create the tables our application needs to store clients and access tokens. It will also create Users table for us.
php artisan migrate
We also updated the driver to use passport in config/auth.php
‘api’ => [
‘driver’ => ‘passport’,
‘provider’ => ‘users’,
‘hash’ => false,
],
Now in our registration api example when we try to generate access token
$user->createToken(‘MyApp Password Grant Client’)->accessToken;
It gives error:
Auth driver [passport] for guard [api] is not defined.
Personal access client not found.
The problem is that our password client and personal client isn’t created yet in our database tables. The clients are created into table “oauth_clients”. In my case I missed running
php artisan passport:install
passport:install
This command will create the encryption keys needed to generate secure access tokens. In addition, the command will create "personal access" and "password grant" clients which will be used to generate access tokensThat solved our issue.
You might also like: HTTPS not working on AWS Elastic Beanstalk
You might also like: AWS Elastic Beanstalk Swap Environment Urls