下午好,
我尝试在我的项目中使用 LexikJWTAuthenticationBundle,但我遇到了未生成令牌的问题。我已在 var/jwt 目录中设置私钥和公钥。
当我尝试使用登录路由时,API 返回此响应:
{
"code": 401,
"message": "JWT Token not found"
}
阿帕奇虚拟主机:
<VirtualHost *:80>
ServerName ypostirixi
DocumentRoot "/var/www/ypostirixi/public"
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</VirtualHost>
公共目录中的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
security.yaml 安全性:
encoders:
App\Entity\User:
algorithm: bcrypt
providers:
doctrine_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
api_doc:
pattern: ^/api/doc
security: false
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
main:
pattern: ^/
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
provider: doctrine_provider
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
我希望成功使用登录路由并在其他路由上生成有效令牌。
慕森王
函数式编程
阿晨1998