-
Notifications
You must be signed in to change notification settings - Fork 6k
JwtDecoder for multiple issuers #10943
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
Comments
Hi, @ch4mpy, thanks for the suggestion. Have you already tried |
@jzheaux thanks for quick answer. No I had not tried We do not use Side note: turning |
Makes sense. You can provide your own @Bean
JwtIssuerAuthenticationManagerResolver byIssuer(MyJwtConverter converter) {
Map<String, AuthenticationManager> managers = new HashMap<>();
for (String issuer : issuers) {
JwtDecoder decoder = new SupplierJwtDecoder(() -> JwtDecoders.fromIssuerLocation(issuer));
JwtAuthenticationProvider provider = new JwtAuthenticationProvider(decoder);
provider.setJwtAuthenticationConverter(converter);
managers.put(issuer, provider::authenticate);
}
return new JwtIssuerAuthenticationManagerResolver(managers::get);
} Agreed that changing to an array would simplify things. It's yet to be seen if multiple issuers is a common enough practice to merit adding to Boot. If you like, you can create a ticket in Spring Boot about it and then we can see if there are enough votes for it from the community. |
Also, #9096 may provide some helpful further reading about |
spring-boot ticket created |
Expected Behavior
It would be nice to have
Current Behavior
spring.security.oauth2.resourceserver.jwt.issuer-uri
is single valued and spring-boot provides withSupplierJwtDecoder
orReactiveJwtDecoder
which are both designed to work with single issuerContext
The company I currently work for has two different authorization-servers: one for intranet users and a different one for internet ones.
Some back-end services (resource-servers) are expected to provide data to users identified against either one or the other of the authorization-servers.
I came with following solution:
SupplierJwtDecoder
(orReactiveJwtDecoder
) for each issuer-uri. When it is asked to decode a JWT, it first extractiss
claim from the payload and then delegates JWT validation and conversion to the rightSupplierJwtDecoder
(orReactiveJwtDecoder
)spring.security.oauth2.resourceserver.jwt.issuer-uri
and a private multi-valued property) and providing as JwtDecoder@bean
, either this new JwtDecoder (if two or more issuers) or the former ones (no over-head for single issuer)Notes:
spring.security.oauth2.resourceserver.jwt.issuer-uri
into a string array while keeping backward compatibilityThe text was updated successfully, but these errors were encountered: