Comments (4)
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.
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.
thanks , it works now
from lexikjwtauthenticationbundle.
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)
- Missing description from OpenAPI Factory
- LexikJWTAuth unexpected identifier Encoder expecting variable (500 Internal Server Error) HOT 1
- Unrecognized option "enabled" under "lexik_jwt_authentication.api_platform" HOT 13
- multiple entity same identity
- How to rename tag "Login Check" on swagger ui HOT 4
- oAuth2 (JWT) Secured request too slow HOT 1
- Split cookie renewal not working as expected when calling api endpoints HOT 1
- Support for partitioned authentication cookies
- Please provide support for Symfony 7 HOT 2
- If i generate token within one second it provides for me the same combination
- symfony 7 HOT 1
- [BUG] EnableEncryptionConfigCommand not supporting php7 HOT 1
- GHA improvements
- Version 2.20+ requiring php 7.1 >= but using arrow functions HOT 2
- Not compatible with PHP 8.2 HOT 2
- How to autowire cookieProvider dynamically (without cookie name)? HOT 1
- Split cookies are all set in the same string
- Generate JWT token using dynamic configuration
- Feature Request: Method for Manually Destroying Tokens HOT 3
- Custom JWT token key
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lexikjwtauthenticationbundle.