Heroku and Laravel Passport

后端 未结 4 1577
执念已碎
执念已碎 2021-01-03 06:09

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

Whe

相关标签:
4条回答
  • 2021-01-03 06:47

    My solution was quite straight forward:

    1. go to your .gitignore file
    2. comment out /storage/*.key
    3. re-deploy to heroku

    It appears that the oauth-keys are ignored by default in Laravel (v.7)

    0 讨论(0)
  • 2021-01-03 06:56

    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

    0 讨论(0)
  • 2021-01-03 07:01

    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

    0 讨论(0)
  • 2021-01-03 07:04

    Laravel Passport has a configuration that allows to set public and private keys as environment variables.

    You can run php artisan vendor:publish --tag=passport-config on your local machine and commit the change.

    Then set PASSPORT_PRIVATE_KEY and PASSPORT_PUBLIC_KEY on Heroku config.

    Found from this blog

    0 讨论(0)
提交回复
热议问题