Giter Club home page Giter Club logo

Comments (4)

slashfan avatar slashfan commented on May 21, 2024

Hi,

First, thanks ! About your problem, the cause might not be the use of an entity provider but the property email. As you can see here https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Services/JWTManager.php#L102 the bundle stores the username of the user inside the token. So when the entity provider tries to load the user form your database it actually compares its username to its email.

To change this behavior, you could override the JWTManager to change the property used to store in the token. Or you could simply listen to the JWTCreatedEvent and override the value under the username key in the event's data property https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/2-data-customization.md#eventsjwt_created---add-data-to-the-jwt-payload.

There will soon be another way to do that but it's still work in progress !

from lexikjwtauthenticationbundle.

AnwarAbdelkabir avatar AnwarAbdelkabir commented on May 21, 2024

Hi ,
Thank you for your help,
I have the same problem, after inspection of the code of your bundre I find that it is based on the username of the entitie, so I change the GetUserName in my entity to returns the email attribute :
public function getUsername() {
return $this->email;
}
like that when the jwtBundle looks for username it get the value of email. 👍
So I resolve the probleme without override the JWTManager because if I do that , I will have a probleme when I do an update
do not forget the parameter provider twice, in login: and the other in api:
login_Condidat:
pattern: ^/Condidat/api_REST/login
stateless: true
provider: main_candidat
anonymous: true
form_login:
check_path: /Condidat/api_REST/login_check
require_previous_session: false
username_parameter: _username
password_parameter: _password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api_condidat:
pattern: ^/Condidat/api_REST
provider: main_candidat
anonymous: true
stateless: true
lexik_jwt: ~
I finally want to thank the team who work on this bundle and Mr slashfan who anwser all our questions 👍

from lexikjwtauthenticationbundle.

ramrami avatar ramrami commented on May 21, 2024

thanks , it works now

from lexikjwtauthenticationbundle.

slashfan avatar slashfan commented on May 21, 2024

Thanks @AnwarAbdelkabir ! Username and email are often the same, in which case the solution you describe works perfectly. In fact that's what I do too !

from lexikjwtauthenticationbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.