-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Expose ID Token JwtDecoderFactory #6379
Comments
Hi Joe, is this already taken? |
I was planning on it but would be happy to hand it over to you :) |
The 2 things to keep in mind for this task:
|
@raphaelDL Just a heads up that I'm hoping to get this merged before end of day Monday as 5.2.0.M1 is being released on Tue. Do you think you'll be able to have something for review by end of day today or tomorrow morning? No pressure at all if you don't have the cycles. Either way let me know and if you don't have the time than I can wrap this up fairly quickly. |
Sure, I'm working on it, can you give me ideas on the multiple clock skew settings in |
As far as being able to support a different clock skew setting per provider, I think this will do the trick. public final class OidcIdTokenDecoderFactory implements JwtDecoderFactory<ClientRegistration> {
// This provides the default
private Function<ClientRegistration, OAuth2TokenValidator<Jwt>> jwtValidatorFactory = OidcIdTokenValidator::new;
// The user can supply their own factory that will allow them to adjust the clock skew or whatever else they choose to customize
public final void setJwtValidatorFactory(Function<ClientRegistration, OAuth2TokenValidator<Jwt>> jwtValidatorFactory) {
...
}
} Let's go with this for now and we can refine from here. |
Btw, the current implementations compose 2 OAuth2TokenValidator<Jwt> jwtValidator = new DelegatingOAuth2TokenValidator<>(new JwtTimestampValidator(), new OidcIdTokenValidator(clientRegistration));
|
Ok Joe, thank you for your help.. I committed additional changes. I'm working on a test for the customization |
hey Joe, I was looking at the code of public final void setJwtValidatorFactory(Function<ClientRegistration, OAuth2TokenValidator<Jwt>> jwtCustomValidatorFactory, ClientRegistration clientRegistration) {
jwtDecoders.computeIfPresent(clientRegistration.getRegistrationId(), ( key , decoder ) ->
{
OAuth2TokenValidator<Jwt> jwtCustomValidator = jwtCustomValidatorFactory.apply(clientRegistration);
NimbusReactiveJwtDecoder jwtDecoder = new NimbusReactiveJwtDecoder(
clientRegistration.getProviderDetails().getJwkSetUri());
jwtDecoder.setJwtValidator(jwtCustomValidator);
return jwtDecoder;
});
} maybe I am missing something? what do you think? |
I'm not sure I follow? When the |
Yes I understand, I was thinking what happens when yo do this: you call |
This is what I'm envisioning the user would provide: public Function<ClientRegistration, OAuth2TokenValidator<Jwt>> customJwtValidatorFactory() {
return clientRegistration -> {
OidcIdTokenValidator idTokenValidator = new OidcIdTokenValidator(clientRegistration);
if (clientRegistration.getRegistrationId().equals("google")) {
idTokenValidator.setClockSkew(Duration.ofSeconds(30));
} else if (clientRegistration.getRegistrationId().equals("okta")) {
idTokenValidator.setClockSkew(Duration.ofSeconds(60));
} else {
// Default clock skew
}
return idTokenValidator;
};
} With this custom Makes sense? |
it totally makes sense, thanks.... then I should add the tests and open the PR, thanks |
This commit ensures that the JwtDecoder is not a private field inside the Oidc authentication provider by extracting this class and giving the possibility to customize the way different providers are validated. Fixes: spring-projectsgh-6379
DefaultJwtDecoderFactory
inOidcAuthorizationCodeAuthenticationProvider
andOidcAuthorizationCodeReactiveAuthenticationManager
is responsible for providing theJwtDecoder
used for ID Token verification. Both are declared asprivate static
.The user may need to customize the
JwtDecoder
in certain scenarios, for example, configuring a clock skew (#5839). Given this, we should extract bothDefaultJwtDecoderFactory
to allow for reuse and customization/configuration.The text was updated successfully, but these errors were encountered: