This article provides display different solutions if you are getting "Unable to read key from file auth.public.key" or "oauth-private.key does not exist or is not readable" while using Passwport authentication in Laravel framework.
Solution 1:
This command will create the encryption keys needed to generate secure access tokens. It will also create "personal access" and "password grant" clients which will be used to generate access tokens. Then consult solution 3.
php artisan passport:install
If you see a message like "Encryption keys exists" then use the following command to force overite exsting key. Then consult solution 3.
php artisan passport:install --force
Solution 2:
Make sure that following code is disaled in your config/app.php file
/* Laravel\Passport\PassportServiceProvider::class, App\Providers\CodeGrantProvider::class, Spatie\Permission\PermissionServiceProvider::class, */
And following code is not uncommented.
Laravel\Passport\PassportServiceProvider::class,
Solution 3:
php artisan config:clear php artisan key:generate php artisan config:clear
Solution 4:
If you have pulled the project from get then it might be possible that /storage/*.key is in your .gitignore file. Following command will generate a new key. Try solution 3 again after using solution 4.
php artisan passport:keys
Solution 5:
Make sure that storage directory exists. If exists then make sure it has proper permissions. Try following commands to change permissions.
chown www-data:www-data storage/oauth-*.key chmod 600 storage/oauth-*.key
Solution 6:
Remove Passport::loadKeysFrom(__DIR__.'/../secrets/oauth'); from App\Providers\AuthServiceProvider to fix the issue. You may need to do it if you are using Laravel 8.x.

Leave A comment
Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *