Sabri Aziri
Sabri Aziri

Reputation: 4174

Laravel Passport Key path oauth-public.key does not exist or is not readable

Laravel passport showing this while trying to access resource

Key path "file://C:\xampp\htdocs\rental_5.0\storage\oauth-public.key" does not exist or is not readable

Upvotes: 75

Views: 129566

Answers (13)

Mahbub
Mahbub

Reputation: 4942

May be storage/oauth-private.key and storage/oauth-private.key are absent and you imported the old database. For this scenario please run the following command.

php artisan passport:keys

Try this solution if you imported the old database where passport related data already stored. Otherwise, follow the accepted answer.

Upvotes: 8

Amede Angel Aulerien
Amede Angel Aulerien

Reputation: 398

Adding this to composer.json did the trick for me:

"scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan optimize", "chmod -R 777 storage", "php artisan passport:keys" ], }

https://github.com/laravel/passport/issues/267#issuecomment-346627625

Upvotes: 0

Vakar
Vakar

Reputation: 81

go straight to .gitignore file in the root of laravel project and remove /storage/*.key line. Perhaps your server isn't allowing to write the keys file in the directory. Upload or publish your repo again.

Upvotes: 4

Nelson Katale
Nelson Katale

Reputation: 1539

This is because you didn't generate Oauth keys using passport keys.

Run

php artisan passport:keys

After that run the following command to generate a personal access client

php artisan passport:client --personal

Enter the details it asks you. Then you are done.

Upvotes: 59

Kamil Kiełczewski
Kamil Kiełczewski

Reputation: 92687

In my case It just doesnt work - I try everyging - probably problem with file access (however ls -la looks fine) - so i generate that keys in other machine and copy to serwer - and php artisan passport:install start works

Upvotes: 0

Elvis Kirui
Elvis Kirui

Reputation: 101

I don't know if this is the ideal solution but removing /storage/*.key from .gitignore then pushing did the trick for me.

Upvotes: -1

Ramesh Navi
Ramesh Navi

Reputation: 773

Everything worked fine on the local system, faced the same problem on production system. In my case, git ignored keys for good reason. Just executed php artisan passport:keys on production server everything worked.

Upvotes: 0

Udhav Sarvaiya
Udhav Sarvaiya

Reputation: 10111

We get this error because passport is not installed correctly

Solution is simple just run this command:

php artisan passport:install

Upvotes: 5

Allan Mwesigwa
Allan Mwesigwa

Reputation: 1298

I manually set my password_client value in the oauth_clients table to 1 and it worked.

Upvotes: 0

Sabri Aziri
Sabri Aziri

Reputation: 4174

OpenSSL was not installed on my windows machine

  1. Download GnuWi
  2. Extract bin/openssl.exe into a Environment Variable Path directory (You can create your own bin folder in your user folder or something and add that path to the Path Variable)
  3. Open a new command prompt(Existing ones may not have the newest environment variables)
  4. Run php artisan passport:install

https://github.com/laravel/passport/issues/48#issuecomment-241936338

Edited

In windows by using git BASH you don't need to install any additional software only run php artisan passport:install from BASH and it should work.

Upvotes: 3

Be Kind
Be Kind

Reputation: 5182

Had the same error with Ubuntu and in my case the problem was with permissions, running this solved the issue:

sudo chown www-data:www-data storage/oauth-*.key

Upvotes: 6

laze
laze

Reputation: 346

I use Heroku. As far as I know, Heroku add OpenSSL support by default (https://devcenter.heroku.com/articles/php-support).

All the things, like php artisan install:passport did run without any issue and my project is also available on the web.

When I asked for php artisan route:list then I received this exception:

[LogicException]
  Key path "file:///app/storage/oauth-private.key" does not exist or is not readable

What seems to me the same as above.

I did everything also local successfully. After these steps git showed I have the key filed in my storage folder, so I committed and pushed them to Heroku.

This solved the issue, now everything is okay also on Heroku.

(Is it okay, to have the same keys here and there?)

Upvotes: 2

Leon Vismer
Leon Vismer

Reputation: 5105

You do not mention your installation steps. Presume you did the following:

composer require laravel/passport

Register the service provider inside config/app.php

Laravel\Passport\PassportServiceProvider::class,

Run the migrations

php artisan migrate

Lastly generate the keys using

php artisan passport:install

I see you are trying it on Windows. I saw an OpenSSL problem on Windows, might help you.

Upvotes: 126

Related Questions