问题
I try to install my app on heroku. This app is a php-laravel app with the "passport" for the authentication. All is running fine in my local machine (mac os).
When I try to do a simple 'post' with postman, I have this error :
2018-03-17T17:05:22.059708+00:00 app[web.1]: [17-Mar-2018 17:05:22 UTC] [2018-03-17 17:05:22] production.ERROR: Key path "file:///app/storage/oauth-private.key" does not exist or is not readable {"exception":"[object] (LogicException(code: 0): Key path \"file:///app/storage/oauth-private.key\" does not exist or is not readable at /app/vendor/league/oauth2-server/src/CryptKey.php:45)"} []
To setup passport, I generated the keys with :
php artisan passport:install
And I see the keys in my database in heroku. So the command worked properly.
So what is this error ?
I tried also to regenerate the keys, to stop and restart the application. Without successes.
Thanks for your suggestions. Merci
Dominique
EDIT : in fact, the key files are not generated in the folder app/storage, that's why there is this error. But why these files are not generated ?
回答1:
the solution is here : https://github.com/laravel/passport/issues/267
Add these few lines into your composer.json under the "scripts" property, then commit et deploy into heroku.
"post-install-cmd": [
"php artisan clear-compiled",
"chmod -R 777 storage",
"php artisan passport:keys"
]
BUT : after that you have to delete the keys from the table "oauth-clients" , then regenerate these keys with :
php artisan passport:install
and it worked for me.
Hope it will help.
Dominique
回答2:
About the @Dom answer, It will log out your users with every deployment, so if you're really using Heroku and not Dokku (as in my case), I recommend you to generate the keys by using that command: php artisan passport:keys and then via Nano copy the keys generated in storage/oauth-public.key and storage/oauth-private.key into multiline env variables, then you can use this post install script in composer.json:
"post-install-cmd": [ "php artisan clear-compiled", "chmod -R 777 storage", "echo -n $OAUTH_PRIVATE_KEY > storage/oauth-private.key", "echo -n $OAUTH_PUBLIC_KEY > storage/oauth-public.key" ]
That will regenerate the keys from ENV with every deployment and keep your users logged in.
If that solution doesn't work, you could still remove '/storage/*.key' line from .gitignore
来源:https://stackoverflow.com/questions/49339711/heroku-and-laravel-passport