Replies: 1 comment 2 replies
-
Hi @mnylensc ! Usually there is no need to override JJWT As for an async API, we haven't looked into this, nor has anyone requested it yet in the 10 year history of the project, so, just in all honesty and transparency, it wouldn't exactly be high on our implementation/feature list when This is just my own opinion, but the (often very challenging) mental context shift for developers, quality error handling, and other challenges of directly using async APIs within Java code make it a very difficult landscape to navigate for most programming teams. And except in some very specific scenarios, JDK 19+ Virtual Threads may eliminate the need for developers to go down the async mental rabbit hole, further reducing any need to use I bring this up not to say that we wouldn't implement an async API, just that the likely need of it for most Java teams seems to be diminishing over time. For JJWT specifically, a good bit of work would be required to see the full scope of how this could be achieved - key lookup, as well as parsing, and My personal opinion is that I'd like to see how many people that use JJWT want something like this before we undertake such an effort. It's non-trivial, so the 'juice would need to be worth the squeeze' in my opinion. And that also needs to take into consideration maintaining these APIs over a very long period of time, which is a lot to ask if the demand isn't high. Just my two cents! |
Beta Was this translation helpful? Give feedback.
-
Hey! Thought to ask - has there been any discussions in the past about providing asynchronous API for
JwtParser
/JwtBuilder
?The use case would be to allow offloading any key operations to external service, such as AWS KMS, in an otherwise asynchronous server. The benefit of using services like these is that they use hardware security modules, where the keys are not extractable quite as easily. Things like supply chain attacks happen, so having the keys sitting in JVM memory or passed in via environment variables is not great in high security contexts.
Currently one can override the implementation of for example the ES256
SignatureAlgorithm
with a version wheredigest(SecureRequest<InputStream, PrivateKey>)
andverify(VerifySecureDigestRequest<PublicKey>)
methods do a network call to an external service. However, this must be done via synchronous API.Using the current API from asynchronous code with a
SignatureAlgorithm
implementation like this will require the caller to carefully wrap anyJwtParser#parseSignedClaims
andJwtBuilder#compact
calls with, for example,CompletableFuture.supplyAsync(() -> parser.parseSignedClaims(), executor)
to avoid blocking the event loop.This brings some added complexity in having to manage yet another thread pool for these operations when everything could just happen on the existing Netty event loop if an asynchronous API was provided.
Would it be possible for there to be
AsyncJwtParser
andAsyncJwtBuilder
where theparseSignedClaims()
would returnCompletableFuture<Jws<Claims>>
andcompact()
would returnCompletableFuture<String>
? This would then of course need some changes to the signature algorithm interfaces as well. Likely the same default implementations could implement both synchronous and asynchronous interfaces, where the asynchronous one would just be wrapped inCompletableFuture
.Best Regards,
Mikko Nylén
Beta Was this translation helpful? Give feedback.
All reactions