Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oauth-private.key does not exist or is not readable in laravel

Tags:

php

laravel

I clone a project from gitlab written by Laravel Framework 6.13.1 that use passport library. As usual I first executed composer install but i got this error :

   LogicException  : Key path "file://C:\xampp\htdocs\myproject\storage\oauth-private.key" does not exist or is not readable

  at C:\xampp\htdocs\myproject\vendor\league\oauth2-server\src\CryptKey.php:48
    44|             $keyPath = 'file://' . $keyPath;
    45|         }
    46|
    47|         if (!file_exists($keyPath) || !is_readable($keyPath)) {
  > 48|             throw new LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath));
    49|         }
    50|
    51|         if ($keyPermissionsCheck === true) {
    52|             // Verify the permissions of the key

  Exception trace:

  1   League\OAuth2\Server\CryptKey::__construct("file://C:\xampp\htdocs\myproject\storage\oauth-private.key")
      C:\xampp\htdocs\note-server\vendor\laravel\passport\src\PassportServiceProvider.php:248

  2   Laravel\Passport\PassportServiceProvider::makeCryptKey("private")
      C:\xampp\htdocs\note-server\vendor\laravel\passport\src\PassportServiceProvider.php:214

now i can not run php artisan command i got same Error

where is the problem? why i got this error? i search it in internet some one say run php artisan passport:install or other command but i can not now run php artiasan because got same error

like image 516
morteza moradi Avatar asked Oct 23 '25 15:10

morteza moradi


2 Answers

Since /storage/*.key is in .gitignore so if you pull the project, that might be missing the key by running

 php artisan passport:keys

will generate new keys for you.

like image 141
Anik Anwar Avatar answered Oct 26 '25 06:10

Anik Anwar


This is a hack and I just used it to get my test environment working so I wouldn't recommend to do this for production environments but I managed to get this working by doing the following before running composer install:

I first generated the keys manually:

ssh-keygen -t rsa -b 4096 -f ./storage/id_rsa && mv ./storage/id_rsa ./storage/oauth-private.key && mv ./storage/id_rsa.pub ./storage/oauth-public.key

Then I ensured that a valid APP_KEY was in my .env file by running php artisan key:generate on another machine and including it in the repository; you could also add it to the .env file manually. The main reason this is unsafe is because that key shouldn't be included in any repositories and should exist only on its own machine for security reasons.

This should get the build in a state where you can run composer install and afterwards run the following to install passport:

php artisan migrate
php artisan passport:install --force

Hopefully everything should then be in a working state.

Again, this is a hack I used to get my test environment working as I assumed there was some sort of compatibility issue with my versions of Laravel/Passport and the machine itself.

like image 23
Simon Avatar answered Oct 26 '25 05:10

Simon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!