Skip to content

NimbusJwtEncoder should simplify constructing with javax.security Keys #16267

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

Open
jzheaux opened this issue Dec 12, 2024 · 7 comments
Open

NimbusJwtEncoder should simplify constructing with javax.security Keys #16267

jzheaux opened this issue Dec 12, 2024 · 7 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Dec 12, 2024

Currently to construct a NimbusJwtEncoder with a single key takes something like the following:

OctetSequenceKey jwk = new OctetSequenceKeyGenerator(256)
    .keyID(UUID.randomUUID().toString())
    .algorithm(JWSAlgorithm.HS256)
    .issueTime(new Date())
    .generate();
JWKSource<SecurityContext> source = new ImmutableJWKSet<>(new JWKSet(jwk));
NimbusJwtEncoder encoder = new NimbusJwtEncoder(source);

whereas to do the converse in NimbusJwtDecoder is simpler:

NimbusJwtDecoder decoder = NimbusJwtDecoder.withSecretKey(key).build();

It would be nice if NimbusJwtEncoder offered similar behavior:

SecretKey key = ...
NimbusJwtEncoder.withSecretKey(key).build(); // or
NimbusJwtEncoder.withSecretKey(key).keyId(...).build(); // etc.

KeyPair keyPair = ... // RSA or EC
NimbusJwtEncoder.withKeyPair(keyPair).build(); // or
NimbusJwtEncoder.withKeyPair(keyPair).keyId(...).build(); // etc.
@jzheaux jzheaux added type: enhancement A general enhancement status: ideal-for-contribution An issue that we actively are looking for someone to help us with labels Dec 12, 2024
@jan-knoblich
Copy link

@jzheaux could you assign this to me?

@jzheaux jzheaux added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: ideal-for-contribution An issue that we actively are looking for someone to help us with labels Mar 20, 2025
@jzheaux
Copy link
Contributor Author

jzheaux commented Mar 20, 2025

Thanks, @jan-knoblich! I've assigned the issue to you.

@jan-knoblich
Copy link

@jzheaux quick question with regard to the keypair; do we want to dynamically check the keypair to get the used algorithm to create the correct ECkey/RSAkey/... or should we have the user specify?

@jzheaux
Copy link
Contributor Author

jzheaux commented Apr 8, 2025

Hi, @jan-knoblich. Can we do just one method? I like the idea of deducing the key for the user so that they don't accidentally call the wrong method.

@jan-knoblich
Copy link

Yeah sure, this seems doable.

Sorry my PC was broken for some time lol. Will get back to this soon.

@surajbh123
Copy link

Hi @jzheaux
I've implemented the builder method changes.
When you have a moment, please review the
PR: #17033

surajbh123 added a commit to surajbh123/spring-security that referenced this issue May 8, 2025
surajbh123 added a commit to surajbh123/spring-security that referenced this issue May 9, 2025
surajbh123 added a commit to surajbh123/spring-security that referenced this issue May 9, 2025
surajbh123 added a commit to surajbh123/spring-security that referenced this issue May 9, 2025
surajbh123 added a commit to surajbh123/spring-security that referenced this issue May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants