Skip to content
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

Extending JWTTokenAuthenticator::getUser() #294

Closed
tcardonne opened this issue Dec 28, 2016 · 2 comments
Closed

Extending JWTTokenAuthenticator::getUser() #294

tcardonne opened this issue Dec 28, 2016 · 2 comments

Comments

@tcardonne
Copy link
Contributor

Hi,

Before upgrading, I was using a JWTProvider to allow a JWT Token to be "user less" (eg : a token to allow another system to call my API (eg : a JWT used by my WHMCS installation).
I was overriding the getUserFromPayload() function to return a user created by instancing a new User object.

As the JWTProvider has been deprecated in flavor of the JWTTokenAuthenticator class, I would like to do the same with this new class : extending the JWTTokenAuthenticator::getUser() method.

I saw in the issue #277 ( https://github.com/lexik/LexikJWTAuthenticationBundle/issues/277#issuecomment-264116280 ) that I should use the following line to make my custom JWTTokenAuthenticator work : https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Security/Guard/JWTTokenAuthenticator.php#L153.

The problem is that the $preAuthenticationTokenStorage property is declared as private ( see : https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Security/Guard/JWTTokenAuthenticator.php#L60 ) and thus cannot be accessed by my custom authenticator class.

Before going any further (like creating a new PR), am I doing something wrong ? Is this private declaration wanted ?
If not, could we declare this property as protected instead of private ?

Best regards.

@chalasr
Copy link
Collaborator

chalasr commented Dec 30, 2016

Hi @SmurfyFR,

Thank you for opening this issue.
You're right to discuss about before trying to solve it, I did not answer you before today because in fact we were about to merge a feature that should solve your problem and it needed to be finished, it is now.

In #278 we added a database-less user provider which creates user instances from JWTs payload. The user provider is not mandatory, any other provider can still be used instead, but you could be interested by the feature for your use case as we provide a JWTUserInterface and any class implementing this interface can be used with this user provider (the class needs a static createFromPayload($username, $payload): self to guarantee that we can instantiate it.

Even if you don't need the feature and keep creating your user instances by extending the authenticator, the PR will help you as we added a protected loadUser() method to the JWTTokenAuthenticator class, so you can just override it and return your custom user instance.

Anyway, you can already try it by upgrading the bundle to v2.1.0, hope you're all good with it.

Cheers

@tcardonne
Copy link
Contributor Author

Hi,

That update should do the trick 👍
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants