Skip to content

Commit 1649db9

Browse files
committed
Do not update JWT authentication token audience
1 parent b6092fe commit 1649db9

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

extensions/oidc-client/deployment/src/test/resources/application-oidc-client-credentials-jwt-secret.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Disable Dev Services, Keycloak is started by a Maven plugin
22
quarkus.keycloak.devservices.enabled=false
33

4-
quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus4/
4+
quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus4
55
quarkus.oidc.client-id=quarkus-app
66
quarkus.oidc-client.client-enabled=false
77
quarkus.oidc-client.jwt.auth-server-url=${quarkus.oidc.auth-server-url}

extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/OidcCommonUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ public static String signJwtWithKey(OidcClientCommonConfig oidcConfig, String to
448448
.claims(additionalClaims(oidcConfig.credentials().jwt().claims()))
449449
.issuer(oidcConfig.credentials().jwt().issuer().orElse(oidcConfig.clientId().get()))
450450
.subject(oidcConfig.credentials().jwt().subject().orElse(oidcConfig.clientId().get()))
451-
.audience(oidcConfig.credentials().jwt().audience().isPresent()
452-
? removeLastPathSeparator(oidcConfig.credentials().jwt().audience().get())
453-
: tokenRequestUri)
451+
.audience(oidcConfig.credentials().jwt().audience().orElse(tokenRequestUri))
454452
.expiresIn(oidcConfig.credentials().jwt().lifespan()).jws();
455453
if (oidcConfig.credentials().jwt().tokenKeyId().isPresent()) {
456454
jwtSignatureBuilder.keyId(oidcConfig.credentials().jwt().tokenKeyId().get());

extensions/oidc-common/runtime/src/test/java/io/quarkus/oidc/common/runtime/OidcCommonUtilsTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,37 @@ public void testJwtTokenWithScope() throws Exception {
5656
cfg.setClientId("client");
5757
cfg.credentials.jwt.claims.put("scope", "read,write");
5858
PrivateKey key = KeyPairGenerator.getInstance("RSA").generateKeyPair().getPrivate();
59-
String jwt = OidcCommonUtils.signJwtWithKey(cfg, "http://localhost", key);
59+
String jwt = OidcCommonUtils.signJwtWithKey(cfg, "http://some.service.com", key);
6060
JsonObject json = decodeJwtContent(jwt);
6161
String scope = json.getString("scope");
6262
assertEquals("read,write", scope);
63+
assertEquals("http://some.service.com", json.getString("aud"));
64+
}
65+
66+
@Test
67+
public void testSignWithAudience() throws Exception {
68+
OidcClientCommonConfig cfg = new OidcClientCommonConfig() {
69+
};
70+
cfg.setClientId("client");
71+
cfg.credentials.jwt.audience = Optional.of("https://server.example.com");
72+
73+
PrivateKey key = KeyPairGenerator.getInstance("RSA").generateKeyPair().getPrivate();
74+
String jwt = OidcCommonUtils.signJwtWithKey(cfg, "http://localhost", key);
75+
JsonObject json = decodeJwtContent(jwt);
76+
assertEquals("https://server.example.com", json.getString("aud"));
77+
}
78+
79+
@Test
80+
public void testSignWithAudienceTrailingSlash() throws Exception {
81+
OidcClientCommonConfig cfg = new OidcClientCommonConfig() {
82+
};
83+
cfg.setClientId("client");
84+
cfg.credentials.jwt.audience = Optional.of("https://server.example.com/");
85+
86+
PrivateKey key = KeyPairGenerator.getInstance("RSA").generateKeyPair().getPrivate();
87+
String jwt = OidcCommonUtils.signJwtWithKey(cfg, "http://localhost", key);
88+
JsonObject json = decodeJwtContent(jwt);
89+
assertEquals("https://server.example.com/", json.getString("aud"));
6390
}
6491

6592
public static JsonObject decodeJwtContent(String jwt) {

0 commit comments

Comments
 (0)