Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Symfony app with LexikJWTAuthenticationBundle on Heroku

I have my app deployed to Heroku, then I added an api with LexikJWTAuthenticationBundle for authentication. I created public and private keys with a passphrase like the documentation says, and it works great on my local machine, yet I do not know how to create or copy those files to Heroku.

like image 475
John Armstrong Avatar asked Oct 20 '16 07:10

John Armstrong


1 Answers

With LexikJWTAuthenticationBundle v2.5.0, this is now possible to give keys as environment variables : commit 154c60e90b8f10e1fdca819a681b5f189e8ed9ef.

Replace keys path for string keys in lexik_jwt_authentication.yaml :

Before :

lexik_jwt_authentication:
    private_key_path: '%kernel.project_dir%/%env(JWT_PRIVATE_KEY_PATH)%'
    public_key_path: '%kernel.project_dir%/%env(JWT_PUBLIC_KEY_PATH)%'

After :

lexik_jwt_authentication:
    secret_key: '%env(JWT_SECRET_KEY)%'
    public_key: '%env(JWT_PUBLIC_KEY)%'

I didn't find a solution to paste full keys as string in .env file, so I kept private_key_path and public_key_path in config/dev/lexik_jwt_authentication.yaml for my dev environment, and used secret_key and public_key only in config/prod/lexik_jwt_authentication.yaml, for my Heroku production.

To finish, add env variables on Heroku, deploy and you're done :

JWT_PUBLIC_KEY

JWT_SECRET_KEY

like image 101
Sybio Avatar answered Nov 02 '22 07:11

Sybio