74

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
Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Sabri Aziri
  • 4,084
  • 5
  • 30
  • 45

13 Answers13

123

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.

Leon Vismer
  • 4,925
  • 1
  • 20
  • 22
  • Up for OpenSSL problem on windowns, GnuWin seems to be my issue – Sabri Aziri Sep 14 '16 at 16:11
  • anyone facing this issue in production laravel forge, you need to simply ssh into forge "ssh forge@ip_address_here" , then just run "php artisan passport:install --force" (force to overwrite the keys) This will generate the keys and have them in place – Manas Oct 02 '20 at 09:59
55

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.

Nelson Katale
  • 1,309
  • 15
  • 21
7

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.

Mahbub
  • 4,812
  • 1
  • 31
  • 34
4

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

Be Kind
  • 4,712
  • 1
  • 38
  • 45
4

We get this error because passport is not installed correctly

Solution is simple just run this command:

php artisan passport:install
Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
4

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.

Vakar
  • 81
  • 5
3

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.

Jono20201
  • 3,215
  • 3
  • 20
  • 33
Sabri Aziri
  • 4,084
  • 5
  • 30
  • 45
  • 1
    I opened git bash from project folder. then run php artisan passport:install then run php artisan serve from git bash. Next i give a request from postman and it works thanks for this edition – Rajib Jun 26 '19 at 14:31
2

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?)

laze
  • 237
  • 2
  • 7
  • 1
    If you are in windows, you should install openSSL(please read the post below) and I am not sure if is it ok or not but for security reasons please add another key in production. – Sabri Aziri Sep 14 '16 at 16:17
  • I think your answer deserves a vote up. For what ever reason , may be for safety purpose, it was ignored in the .gitignore and heroku is throwing error 500. So in my case i just have to remove it from .gitignore and pushed and it is working. I also tried running php artisan passport:install or passport:keys on heroku using the command line but it did not work. – Jerry Okafor Dec 10 '16 at 10:27
  • 1
    It's generally a bad practice to have private keys in version control. – jsphpl Sep 02 '17 at 21:14
  • 10
    I found a solution running with heroku cli `heroku ps:exec` then running command `php artisan passport:keys` – David L Oct 16 '17 at 19:18
0

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

Allan Mwesigwa
  • 1,210
  • 14
  • 13
0

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.

Ramesh Navi
  • 773
  • 1
  • 11
  • 24
0

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

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
0

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

-1

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

Elvis Kirui
  • 81
  • 1
  • 3
  • 11