0

我在 symfony4 上开发了一个 api,并使用 LexikJWTAuthenticationBundle 管理我的令牌。

在 localhost 中一切正常,但在我的测试服务器(树莓派上的 ubuntu mate,apache,https)上,服务器向我发送 401 错误和无效的 JWT 令牌。

如自述文件(https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.md#generate-the-ssh-keys)中所述,我尝试添加

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

配置我的虚拟主机并重新启动 apache,但这并没有改变任何东西。

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

谢谢你的帮助

4

1 回答 1

0

通过生成 private.pem 解决了问题:

$ 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

代替

$ 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

解决方案: https ://github.com/attineos/tutotrompe/tree/master/tutotrompe-ep2

于 2019-08-26T11:30:09.483 回答