【问题标题】:Symfony 4 + API Plantform +LexikJWTAuthenticationBundle Bad CredentialSymfony 4 + API Plantform +LexikJWTAuthenticationBundle 坏凭证
【发布时间】:2019-01-27 14:42:57
【问题描述】:

下午好。请我在 symfony 4 api 项目中使用 LexikJWTAuthenticationBundle。我正在将 UserProvider 用于 Doctrine。

在配置 Doctrine User Provider 之后,我已经安装并配置了 LexikJWTAuthenticationBundle。但是,当我尝试在 url http://localhost:8000/api/login_check 上使用 Postman 验证这个 JSON {"username":"ak", “密码”:“ak”}我有这个错误:{ “代码”:401, “消息”:“凭据错误” }。 请参阅下面我的 Security.yaml 配置文件。我已经阅读论坛试图解决这个问题,但我还没有找到解决方案。你能帮帮我吗?

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

providers:
    #in_memory: { memory: ~ }
    our_db_provider:
        entity:
            class: App\Entity\Utilisateur

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:
        pattern:    ^/
        user_checker: App\Security\UtilisateurChecker
        anonymous: true
        provider: our_db_provider         

access_control:
    - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }

【问题讨论】:

    标签: symfony lexikjwtauthbundle


    【解决方案1】:

    installation 期间有没有遗漏配置?我没有看到lexik:

    lexik_jwt_authentication:
        secret_key:       '%kernel.project_dir%/config/jwt/private.pem' # required for token creation
        public_key:       '%kernel.project_dir%/config/jwt/public.pem'  # required for token verification
        pass_phrase:      'your_secret_passphrase' # required for token creation, usage of an environment variable is recommended
        token_ttl:        3600
    

    【讨论】:

    • 我已将此配置放入我的 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)%' 在 .env 文件中我有这个 ###> lexik/ jwt-authentication-bundle ### JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem JWT_PASSPHRASE=5c2561dc331622e14a6ff0377bdb3cc0 ###
    【解决方案2】:

    大家早上好。我找到了我的问题的解决方案。事实上,我输入了错误的用户密码。

    为了解决这篇文章,我使用了这篇文章https://numa-bord.com/miniblog/symfony-4-les-base-dune-gestion-des-utilisateurs-inscription-connexion-droits-dacces/ 我已经使用文章中实现的 create user 命令创建了 au 数据库用户。

    在我成功连接到这个之前创建的用户之后。 ApiPlatform 为我生成一个网络令牌。

    非常感谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 2019-09-23
      • 2020-11-30
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 2020-06-12
      相关资源
      最近更新 更多