Skip to content
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

Allow adding a specified keyId during OIDC token exchange #17962

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ public static class Jwt {
@ConfigItem(defaultValue = "password")
public String keyPassword;

/**
* Key identifier of the signing key added as a JWT 'kid' header
*/
@ConfigItem
public Optional<String> tokenKeyId = Optional.empty();

/**
* JWT life-span in seconds. It will be added to the time it was issued at to calculate the expiration time.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.quarkus.runtime.TlsConfig;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.smallrye.jwt.build.Jwt;
import io.smallrye.jwt.build.JwtClaimsBuilder;
import io.smallrye.jwt.build.JwtSignatureBuilder;
import io.smallrye.jwt.util.KeyUtils;
import io.smallrye.jwt.util.ResourceUtils;
import io.vertx.core.http.HttpClientOptions;
Expand Down Expand Up @@ -220,11 +220,15 @@ public static String signJwt(OidcCommonConfig oidcConfig) {

public static String signJwtWithKey(OidcCommonConfig oidcConfig, Key key) {
// 'jti' and 'iat' claim is created by default, iat - is set to the current time
JwtClaimsBuilder builder = Jwt
JwtSignatureBuilder builder = Jwt
.issuer(oidcConfig.clientId.get())
.subject(oidcConfig.clientId.get())
.audience(getAuthServerUrl(oidcConfig))
.expiresIn(oidcConfig.credentials.jwt.lifespan);
.expiresIn(oidcConfig.credentials.jwt.lifespan)
.jws();
if (oidcConfig.credentials.jwt.tokenKeyId.isPresent()) {
builder.keyId(oidcConfig.credentials.jwt.tokenKeyId.get());
}
if (key instanceof SecretKey) {
return builder.sign((SecretKey) key);
} else {
Expand Down