Invalid JWT Token with LexikJWTAuthenticationBundle

887 Views Asked by At

i developed an api on symfony4 and I manage my tokens with LexikJWTAuthenticationBundle.

In localhost everything works fine but on my test server (ubuntu mate on raspbery pi,apache, https) the server sends me a 401 error and Invalid JWT Token.

As stated on the readme (https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.md#generate-the-ssh-keys) I tried to add

SetEnvIf Authorization "(. *)" HTTP_AUTHORIZATION = $ 1 

to configure my virtualhost and restart apache but that does not change anything.

<IfModule mod_ssl.c>
<VirtualHost *:443>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/current/rest_api/public

        <Directory /var/www/html/current/rest_api/public>
         # enable the .htaccess rewrites
         AllowOverride All
         Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


ServerName mydomain
SSLCertificateFile /etc/letsencrypt/live/mydomain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</VirtualHost>
</IfModule>

Thanks for your help

1

There are 1 best solutions below

0
On

Problem solved by generating private.pem with:

$ mkdir -p config/jwt
$ openssl genrsa -out config/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem

instead of

$ mkdir -p config/jwt
$ openssl genpkey -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096
$ openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout

solved solution by: https://github.com/attineos/tutotrompe/tree/master/tutotrompe-ep2