下午好,
我尝试在我的项目中使用LexikJWTAuthenticationBundle,但是没有生成的令牌有问题。我已经在var/jwt目录中设置了私钥和公钥。
当我尝试使用登录路由时,API返回此响应:
{
"code": 401,
"message": "JWT Token not found"
}Apache Virtualhost:
<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 }我希望成功地使用登录路由,并在其他路由上生成一个有效的令牌。
发布于 2020-08-11 09:25:18
谢谢你的帮助。
我发现了关于这次升级的一个问题,但我有一个解决方案。
在lexik_jwt_authentication.yaml文件中:
lexik_jwt_authentication:
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
token_ttl: '%env(JWT_TTL)%'
token_extractors:
authorization_header:
enabled: true
prefix: '%env(JWT_TOKEN_PREFIX)%'
name: Authorization
user_identity_field: emailhttps://stackoverflow.com/questions/63345059
复制相似问题