0

I am building an API. When I create a user I receive a token. But when I change the information of my user can not reconnect and I receive the 401 error code with the message Bad credentials. How to solve the problem, please?

I use FOSRestBundle, lexikJWTAuthenticator and NelmioCORSBundle

# security.yaml

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

    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email

    firewalls:

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

        signup:
            pattern: ^/api/signup
            stateless: true
            anonymous: true

        signin:
            pattern: ^/api/signin
            stateless: true
            anonymous: true
            json_login: 
                check_path: /api/signin
                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: true

            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#firewalls-authentication

            # https://symfony.com/doc/current/security/impersonating_user.html
            # switch_user: true
    role_hierarchy:
        ROLE_ADMIN: ROLE_USER

    # 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/signin, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api/signup, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        # - { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY, methods: GET }
        # - { path: ^/api, roles: IS_AUTHENTICATED_FULLY, methods: [PUT, DELETE, POST] }
        # - { path: ^/admin, roles: ROLE_ADMIN }
        # - { path: ^/profile, roles: ROLE_USER }

# 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)%'
    token_ttl: 3600

Thanks

2 Answers2

0

Try to regenerate the SSH keys again

here is the link LexikJWT Generate the SSH keys

and make sure about your pass_phrase in Configuration

habibun
  • 1,552
  • 2
  • 14
  • 29
-1

Did you try yo regenerate your token, or you get a 401 with your new token. If you changed the user information you should reconnect and get a new token

A. Ecrubit
  • 561
  • 6
  • 20