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
[Security] Support loading UserBadge directly from accessToken #48285
Conversation
Hey! Thanks for your PR. You are targeting branch "6.2" but it seems your PR description refers to branch "6.3". Cheers! Carsonbot |
The proposal here makes the UserProvider responsible for implementing all the token validation. To me, this risks encouraging bad implementations because the UserProvider is currently responsible for none of the validation. I'd rather have a specific interface to be implemented by the AccessTokenHandler to return a UserBadge directly instead of only the identifier (or something like that). |
Looks sensible to me. |
I've changed it to use the |
Widening the return type of the interface will be a BC break for consumers of the interface though. So if we delay that to 6.3, we'll have to use a separate method |
@stof I thought a |
@Jeroeny yes, it's OK for implementations, but consumers have to take care of another type when calling the method - which would be a BC break. |
@Jeroeny the BC break concerns consumers, not implementors. For implementors, the covariance rule indeed makes it BC. Btw, that's the reason why a child class is not allowed to widen a return type as it would break consumers. And also the main consumer is in the core and will be updated, any decorator class is both an implementation and a consumer and will be impacted by the widened type. |
Since some on-going implementations already need this, I'd be fine merging this on 6.2 as a feature-freeze adjustment. |
Ah or course, for consumers. Allowing it in 6.2 would be cool. |
src/Symfony/Component/Security/Http/Authenticator/AccessTokenAuthenticator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/AccessToken/AccessTokenHandlerInterface.php
Outdated
Show resolved
Hide resolved
Should |
None indeed, can you make the change in this PR? |
src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator_access_token.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/Authenticator/AccessTokenAuthenticator.php
Outdated
Show resolved
Hide resolved
@chalasr Added, I have 2 open questions about the consequences, see comments :). |
src/Symfony/Component/Security/Http/AccessToken/AccessTokenHandlerInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator_access_token.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator_access_token.php
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php
Outdated
Show resolved
Hide resolved
Thank you @Jeroeny. |
Thanks all |
I attended @welcoMattic 's nice talk at SymfonyCon Paris last week, after which we and @wouterj discussed the way tokens need to be parsed to obtain a
userIdentifier
. With JWT tokens, there is usually no need to make a call to a database to instantiate a User object. Because the token is signed, we can guarantee the user details inside it are valid. See example code: https://github.com/welcoMattic/painless-authentication-with-access-token/blob/main/slides/slides.md#62-jwthandlerIn Symfony's authentication system, retrieving the
userIdentifier
and theUser
is a two-step process. However with both theuserIdentifier
and theUser
object coming from the token, we either have to parse the token twice or store it in memory.I think this can be improved by allowing a single step to go from $token (string) -> parsed token (implementation specific) -> User object.
The suggested change in this PR is probably not yet the way to go, but I'd like to hear from the Security contributers if they have any ideas.