1
votes

Good afternoon. Please i'm using LexikJWTAuthenticationBundle in a symfony 4 api project. I'm using UserProvider for Doctrine.

After Configure Doctrine User Provider, I've install and configure LexikJWTAuthenticationBundle. But when i tried to athentificate using Postman on the url http://localhost:8000/api/login_check whith this JSON {"username":"ak", "password":"ak"} I've this error: { "code": 401, "message": "Bad credentials" }. See below my Security.yaml config file. I've read forums to tried to solve this issue but i've not yet found the solution. Can you please help me?

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 }
2

2 Answers

4
votes

Have you missed a piece of configuration during installation? I dont see the lexik one:

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
-1
votes

Good morning All. I've found the solution of my problem. In fact, i was typing a bad User Password.

To solve this article, i've used this article https://numa-bord.com/miniblog/symfony-4-les-base-dune-gestion-des-utilisateurs-inscription-connexion-droits-dacces/ I've created au database user by using create user command implemented in the article.

After i have been connected with this previous created user sucessfully. ApiPlatform generate a web tocken for me.

Thank you very much