jwt - LexikJWTAuthenticationBundle 的 JWT 令牌无效
问题描述
我在 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>
谢谢你的帮助
解决方案
通过生成 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
推荐阅读
- php - Swagger-php 如何排除整个 /vendor 文件夹但附加一个带有共享模型的子文件夹
- bash - 在 jenkins 中使用脚本在不同阶段运行
- makefile - 相同的规则,不同的先决条件
- javascript - 用户使用框架 7 关闭应用程序后如何维护用户会话?
- c# - Rx Extensions 刷新 Buffered observable 中的剩余项目
- c++ - D 和 C++ 目前的互操作性状态
- javascript - 如何从日期类型输入元素中获得最终日期选择?
- python - 具有多个可调用对象的 df.loc[]
- java - 关于 Java Web 应用程序“堆空间内存”错误,如何增加 Google App Engine 开发服务器内存大小?
- docker - 在构建 docker/gcloud 上保留目录