-
Notifications
You must be signed in to change notification settings - Fork 6k
NimbusReactiveJwtDecoder should accept a custom processor #5937
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
Hello, I made an attempt to solve this: PR #6367 From the fact that:
For me there is only two solution. Either the decoder take a function SignedJWT -> Mono<jwtClaimsSet> but it means that the decoder will do almost nothing. Or the decoder take an optional option that provide the context (computed from the JWT header) so that we can call processor process method correctly. I choose to write this code. Now writing the nimbus reactive jwt decoder can be painful. I'm convince that there could be a "technically" better solution, but I'm not sure it will better to use it. |
I'm not sure that exposing Ideally, Nimbus would add a non-blocking API, and perhaps there is an opportunity for the community to help with that. Another possibility might be to introduce public interface ReactiveJWTProcessor<C extends SecurityContext> {
Mono<JWTClaimSet> process(SignedJWT signedJWT, C context);
} with a default implementation that performs the same workaround that It would help to know what particular problem you are trying to solve, @GregoireW. What is your specific need for passing in your own |
I wrote in my previous message that I saw 2 way of solving the issue. First is like you say with the interface. public interface ReactiveJWTProcessor {
Mono<JWTClaimSet> process(SignedJWT signedJWT);
} or the one I write in the PR with a processor and a initializer. In this use case, processor and initializer are coupled a little bit (not so great yes but ...) I choose the processor + initializer only because
But It is clearly a pure tail/head choice.
it is a simple refactoring. I can do it. ( who validate? ) Now going back to my usecase:
PS: I just saw that I got 2 errors in the build, I will check that... @Deprecated
public NimbusReactiveJwtDecoder(String jwksUri){
NimbusReactiveJwtDecoder r= NimbusReactiveJwtDecoderFactory.fromJWKS(jwksUri);
this.jwtProcessor=r.jwtProcessor;
this.initializer=r.initializer;
} |
I think let's go for our ideal first, which is to coordinate with Nimbus. They've been open to our suggestions and PRs in the past. If we can't find a path forward with them, then we can look at a PR. In the meantime, I think that your code will end up being fairly minimal to implement |
I've opened a ticket with Nimbus and we'll see where that goes: https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/296/consider-having-jwtprocessor-accept-key |
I read the ticket you open on Nimbus side, and I'm a little bit confuse on what you have in mind. You ask them to simply get a new method |
My point in the ticket was to highlight how Spring Security solves the problem today, via a custom Vladimir confirmed in his reply that this kind of scenario is what To your question, my point was not to ask for a specific method signature, but instead to be able to pass a key set as a parameter since "it seems that passing in a parameter is more amenable than changing several Nimbus interfaces to be reactive." And Vladimir's response is that the SecurityContext is that parameter. |
Ok, then how you want to play this? I can refactor the code with: A simple interface: public interface ReactiveJWTProcessor {
Mono<JWTClaimSet> process(JWT jwt);
} means people need to take care of or a specific public interface ReactiveJWTProcessor {
default Mono<JWTClaimSet> process(SignedJWT jwt){
throw new JwtException("Signed JWT not supported");
}
default Mono<JWTClaimSet> process(EncryptedJWT jwt){
throw new JwtException("Signed JWT not supported");
}
} Or another approach ? |
@GregoireW I think the next step is to work with Nimbus to see if we can get some of the Spring Security code accepted there, in order to legitimize and clarify the approach. Since it's Nimbus's position that it's okay, let's see if we can get a stronger API definition on that side of things. At the very least, In the meantime, the work that |
I already do something on my projects to make it works (and it is ok), My main issue is that some "common" classes are protected, it means I need to copy a lot of code (or create a beautiful package org.springframework.security.oauth2.jwt in my applications ) to be able to make this work. It is why I'm so motivated to upgrade this on spring side to drop those things as soon as possible ;) |
Anyway I refactor stuff to be cleaner with somehow what I use on my project now |
The Nimbus JwtDecoders, both servlet and reactive, simplify Nimbus configuration by exposing some basic use cases like using a JWK Set Uri or by using a single public key.
Many scenarios are more complex than this, and Nimbus is a full-featured API that allows users to configure for these more complex scenarios.
#5648 proposes addressing this on the servlet side by introducing a constructor that accepts a
JWTProcessor
instance.Because of certain preprocessing that
NimbusJwtReactiveDecoder
does in order to maintain its non-blocking nature as it interacts with Nimbus, it is not yet clear how we might expose theJWTProcessor
there; though coordinating with the Nimbus team may bear some fruit.UPDATE: Creating a
Converter
from scratch that reactively exercises the Nimbus API can be a challenge:So, as part of this ticket, let's also expose a builder for simply working with the keyset:
The text was updated successfully, but these errors were encountered: