DEV Community

Stev Lasowski
Stev Lasowski

Posted on • Edited on

How to deploy OAuth keys on Heroku's ephemeral file system

Deploying a Laravel + Passport App on Heroku can cause some issues with OAuth Keys.

You may see this error

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

The problem is your Public and Private OAuth keys are quite rightly ignored in your .gitignore

I solved this issue by encrypting the keys and storing them in git, with the help of some custom artisan commands, they are now part of my project but you can grab them.

HerokuEncryptKeys.php

HerokuGenerateKey.php

HerokuInstallKey.php

Step 1

Generate OAuth keys ( if you don't already have some )

php artisan passport:keys

Step 2

Generate an encryption key and add the OENCRYPT_KEY env

php artisan heroku:generatekey

add to your local .env and also add it to Heroku's env settings

OENCRYPT_KEY={the output of php artisan heroku:generatekey}

Step 3

Encrypt your OAuth keys and commit to VCS

php artisan heroku:encryptkeys

Commit storage/app/oauth-private.key.encrypted and storage/app/oauth-pubblic.key.encrypted

Step 4

Add post-install-cmd to composer.json

"scripts": {
        ...
        "post-install-cmd": [ "php artisan heroku:installkeys" ]
    }
Enter fullscreen mode Exit fullscreen mode

Push to git or Heroku and the keys will be unencrypted and installed on build.

Top comments (1)

Collapse
 
lordfj profile image
lordfj

hello,

Please I gpt this error "No OENCRYPT_KEY env found!" even though I have the key in my .env file.