{"code":401,"message":"Authentication request could not be processed due to a system problem."} - Symfony 5.0 - lexik/jwt-authentication-bundle

{"code":401,"message":"Authentication request could not be processed due to a system problem."} - Symfony 5.0 - lexik/jwt-authentication-bundle

我使用 Synfony 5.0 和 "lexik/jwt-authentication-bundle": "^2.6".

显示以下消息: {"code":401,"message":"Authentication request could not be processed due to a system problem."}

这个错误只发生在 postgres 上。当我切换到 mysql 时,它起作用了。 我该如何解决?

下面是我的security.yaml:

security:
  encoders:        
    App\Entity\User:
        algorithm: bcrypt

  providers:
    # used to reload user from session & other features (e.g. switch_user)
    app_user_provider:
        entity:
            class: App\Entity\User
            property: username
  firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false        

    login:
        pattern:  ^/api/login
        stateless: true
        anonymous: true
        json_login:
            check_path:               /api/login_check
            success_handler:          lexik_jwt_authentication.handler.authentication_success
            failure_handler:          lexik_jwt_authentication.handler.authentication_failure
    api:
        pattern:   ^/api
        stateless: true
        guard:
            authenticators:
                - lexik_jwt_authentication.jwt_token_authenticator 

    main:
        anonymous: lazy
        provider: app_user_provider       


  # Easy way to control access for large sections of your site
  # Note: Only the *first* access control that matches will be used
  access_control:
    - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY  }
    - { path: ^/api, roles: IS_AUTHENTICATED_FULLY  }`

在日志中:

3 月 30 日 10:19:51 |警告 |服务器 POST (401) /api/login_check host="127.0.0.1:8004" ip="127.0.0.1" scheme="https" [2020-03-30T10:19:51.769724-03:00] request.INFO:匹配的路线 "api_login_check"。 {"route":"api_login_check","route_parameters":{"_route":"api_login_check"},"request_uri":"http://127.0.0.1:8000/api/login_check","method" :"POST"} [] [2020-03-30T10:19:51.888870-03:00] security.INFO:身份验证请求失败。 {"exception":"[object] (Symfony\Component\Security\Core\Exception\AuthenticationServiceException(code: 0): 使用参数 ["my_username"]:\n\nSQLSTATE[42703 执行 'SELECT t0.id AS id_1, t0.username AS username_2, t0.roles AS roles_3, t0.password AS password_4 FROM user t0 WHERE t0.username = ? LIMIT 1' 时发生异常]:未定义的列:7 错误:列 t0.id 不 exist\nLINE 1:SELECT t0.id AS id_1,t0.username AS username_2, t0.roles AS...\n ^ 在 C:\Projetos\Projetos\mp\vendor\symfony\security-core\Authentication\Provider\DaoAuthenticationProvider.php:96)\n[前一个异常] [对象] (Doctrine\DBAL\Exception\InvalidFieldNameException(代码: 0 ): 使用参数 ["wagner"]:\n\nSQLSTATE[42703] 执行 'SELECT t0.id AS id_1, t0.username AS username_2, t0.roles AS roles_3, t0.password AS password_4 FROM user t0 WHERE t0.username = ? LIMIT 1' 时发生异常:未定义的列:7 错误:列 t0.id 不 exist\nLINE 1: SELECT t0.id AS id_1, t0.username AS username_2, t0.roles AS...\n ^ 在 C:\Projetos\Projetos\mp\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\AbstractPostgreSQLDriver.php:60)\n[上一个异常] [对象](Doctrine\DBAL\Driver\PDOException(代码:42703):SQLSTATE[42703]:未定义的列:7 错误:列 t0.id 不 exist\nLINE 1:SELECT t0.id AS id_1, t0.username AS username_2, t0.roles AS...\n ^ 在 C:\Projetos\Projetos\mp\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:123)\ n[previous exception] [object] (PDOException(code: 42703): SQLSTATE[42703]: Undefined column: 7 ERROR: 列 t0.id does not exist\nLINE 1: SELECT t0.id AS id_1, t0.username AS username_2, t0.roles AS...\n ^ 在 C:\Projetos\Projetos\mp\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:121) "} []

此问题已通过更改用户名解决class,因为在 Postgres 中“用户”一词是保留词,查询解释中存在错误。

您必须更改用户 class 名称。