Home > Net >  Laravel Passport - unable create key file
Laravel Passport - unable create key file

Time:07-07

I have a project in Laravel 8.0. This project is living on server. Now I'm trying setup it on my local environment using docker.

I almost done it but I have one issue with laravel/passport. When I try run any artisan command (even "php artisan passport:keys") always I have following error.

In CryptKey.php line 69: Unable to read key from file file:///var/www/html/storage/oauth-private.key

So it's correct because keys are not created yet. But I'm not able generate new one.

It looks like laravel/passport checking this keys with every command even when I try to create it.

How can I skip this checking when command fired. Or how to fix this issue?

Thank you.

CodePudding user response:

I found the problem.

In class AuthServiceProvider in boot() method where following instructions:

$server = $this->app->make(AuthorizationServer::class);
$server->enableGrantType(new PersonalAccessGrant(), new DateInterval("P{$tokenLifetime}D"));

So this method is always fired not only on request but on command call too.

To solve issue we need just add checking before $this->app->make( call.

if (app()->runningInConsole()) {
   return;
};

CodePudding user response:

I think the key itself is not generated. So use the below command to generate key first.

php artisan key:generate

And then run,

php artisan passport:keys

If this din't work, Then It must be the permission issue. Provide enough read permission to storage folder. Try the below command in the terminal,

sudo chmod 755 -R storage
  • Related