Home > Net >  JWTRefreshTokenBundle change user_identity_field Symfony 5.4 ApiPlatform
JWTRefreshTokenBundle change user_identity_field Symfony 5.4 ApiPlatform

Time:04-23

I am using : Symfony 5.4 ApiPlatform JWTRefreshTokenBundle 1.1

JWTRefreshTokenBundle => https://github.com/markitosgv/JWTRefreshTokenBundle

I need to change this parameter "user_identity_field" but there is no way to change this :

  • I tried to change the Yaml =>

    gesdinet_jwt_refresh_token:

    user_identity_field: email

    user_provider: app_user_provider

  • I tried to modify this function in my user provider (app_user_provider) entity User.php :

    public function getUserIdentifier(): string {

    return (string) $this->id; }

Right now the better I can get is to have the ID instead of the E-mail in the user name column in my database, but as soon as I try to refresh the token, I get this message => " 401 "Invalid credentials".

I am tried to have "ID" instead of "E-MAIL" as user_identity_field.

Has anyone found a solution ? Thanks.

CodePudding user response:

i think you need to change the app_user_provider in the security.yaml file :

app_user_provider:
        entity:
            class: App\Entity\User
            property: id
jwt:
        lexik_jwt:
            class: App\Entity\User 

i think the problem is : symfony try to authneticate user with the app_user_provider and you have a conflict because id's are in your JWT but framework search for email. For verify that you can check your tokens on : https://jwt.io/

CodePudding user response:

The JWTRefreshTokenBundle (gesdinet/jwt-refresh-token-bundle) is build upon the JWTAuthenticationBundle (lexik/jwt-authentication-bundle), which is the bundle that defines the user_identity_field configuration:

# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
    user_identity_field: 'email'
  • Related