首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LexikJWTAuthenticationBundle中找不到Symfony 4- JWT

LexikJWTAuthenticationBundle中找不到Symfony 4- JWT
EN

Stack Overflow用户
提问于 2020-08-10 17:24:40
回答 3查看 607关注 0票数 0

下午好,

我尝试在我的项目中使用LexikJWTAuthenticationBundle,但是没有生成的令牌有问题。我已经在var/jwt目录中设置了私钥和公钥。

当我尝试使用登录路由时,API返回此响应:

代码语言:javascript
复制
{
    "code": 401,
    "message": "JWT Token not found"
}

Apache Virtualhost:

代码语言:javascript
复制
<VirtualHost *:80>
    ServerName ypostirixi
    DocumentRoot "/var/www/ypostirixi/public"

    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</VirtualHost>

公共目录中的.htaccess文件:

代码语言:javascript
复制
<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安全性:

代码语言:javascript
复制
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 }

我希望成功地使用登录路由,并在其他路由上生成一个有效的令牌。

EN

Stack Overflow用户

回答已采纳

发布于 2020-08-11 09:25:18

谢谢你的帮助。

我发现了关于这次升级的一个问题,但我有一个解决方案。

在lexik_jwt_authentication.yaml文件中:

代码语言:javascript
复制
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: email
票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63345059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档