-
-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding JWTProvider #35
Comments
Hi, You're right, those member variables should be set to protected to allow easier overwrite. I'll add interfaces too to have more flexibility. |
Sounds good.. do let me know once done. Are you implying that there will be a configuration to override the JWTProvider used? While you're at this.. don't you think there should be a way to access the Request object within the JWTProvider class. The quickest way I deem this will be possible without breaking backwards compatibility is by adding the getRequest() function to the JWTManager class which already has the setRequest(..) function to inject the request. It only but makes sense that there should be a getter so the JWTProvider can access the Request context too.. For example, if I am building a multi-tenant API and I need to access the app id from the URL to ensure that the UserProvider returned belongs to the app id being requested, I will need access to the request object to access one or more attributes. |
That's a good idea, let's add the getRequest() method to the JWTManager. I've started a branch if you want to have a look at it. Basically, it allows to completely override the JWTProvider used in the For those who just don't want to authenticate users by username, I started moving out of the main methods the logic to extract user from token payload and to add user identity to payload. Overriding those methods in sub classes should be sufficient. Dispatching an event might also do the trick without having to create new classes. What do you think ? |
Also exposing this as a public getter |
OK for 1 and 2, it makes sense. About 3, I think you're right. But in the meantime, it might be a lot for the JWTManager to handle. The default implementation would only do what's done in the manager : add username as identity and the expiration date (that way the ttl parameter should be removed from the manager). The only downside I see to this is the overhead to maintain backward compatibility. |
Excuse my delayed reply. Have you made any release progress on this? I don't think anyone would find the need to remove the ttl parameter, and if they want to, removing it in the event listener seems fine. I don't see any of the above changes breaking BC. Which particular implementation do you think will break backwards compatibility? |
Hi, I just updated the branch and added a configuration option for the userIdentityField. No BC break included, I'll do the big refactoring later. Tell me if it's ok for you. #40 |
@slashfan Looks positive. Will update my composer and try this out locally this week. Will let you know if any feedback. |
Ok, I'll tag it soon. Might be time for a 1.1.0. |
There is a new method setUserIdentityField() on JWTProvider |
Compatible with Symfony 3
I need to override the JWTProvider class' authenticate function (
LexikJWTAuthenticationBundle/Security/Authentication/Provider/JWTProvider.php
Line 42 in 118758e
The first approach that comes to my mind to achieve the above is creating a new class that extends the JWTProvider and rewriting the class definition for the lexik_jwt_authentication.security.authentication.provider to my own class.
This approach will seem to solve my problem, but the bundle makes such implementation unfriendly as the member variables inside the JWTProvider class are declared as private.
Wouldn't it better to declare all such variables across this class and other classes as protected so they are well-extendable? It looks right now I will have to copy paste the entire class logic or at least the constructor and assigning of these member variables.
What's your thoughts on the above?
The text was updated successfully, but these errors were encountered: