【问题标题】:Unrecognized option "lexik_jwt" under "security.firewalls.api"“security.firewalls.api”下无法识别的选项“lexik_jwt”
【发布时间】:2021-11-10 01:42:10
【问题描述】:

我在运行数据库迁移期间收到此错误。直到最近它工作正常。问题始于运行管道时我们的 QA 服务器中的数据库迁移失败。当我在迁移容器中查看时,发生了上述错误。

所以,我尝试删除我的本地应用程序并从头开始设置它。在php bin/console doctrine:migrations:migrate期间,出现了错误。

我们正在使用 LexikJWTAuthenticationBundle 包来管理 API 的 JWT 身份验证。所以,我猜可能有一些我无法弄清楚的与 LexikJWTAuthenticationBundle 相关的缺失配置。

这是我的config\packages\security.yaml 文件的内容。

【问题讨论】:

标签: symfony lexikjwtauthbundle


【解决方案1】:

更新到 Symfony 5.3(或更高版本)后,请参阅:https://github.com/lexik/LexikJWTAuthenticationBundle/blob/2.x/Resources/doc/index.md#configuration

修复:

  1. lexis_jwt: 中删除所有并替换为jwt: ~
  2. enable_authenticator_manager: true 添加到安全性
  3. 从 api 部分中删除 anonymous: true
  4. 您不应更改 lexik_jwt_authentication.yaml 文件中的任何内容,但请确保其配置正确

我的示例安全文件(只有管理员可以访问 api 资源):

security:
    enable_authenticator_manager: true

    encoders:
        App\Entity\User:
            algorithm: bcrypt
    providers:
        database:
            entity:
                class: App\Entity\User
                property: username

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt|error)|css|images|js)/
            security: false

        login:
            pattern: ^/secured
            stateless: true
            provider: database
            json_login:
                check_path: /secured/login_check
                username_path: username
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
                require_previous_session: false

        api:
            pattern: ^/api
            stateless: true
            jwt: ~

    access_control:
        - { path: ^/secured/login_check$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/secured/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api, roles: ROLE_ADMIN }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-22
    • 2013-12-19
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 2015-04-19
    相关资源
    最近更新 更多