-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenID Connect standard claims in ATs for WLCG JWT profile (#651)
With IAM_ACCESS_TOKEN_INCLUDE_AUTHN_INFO=true and in the context of a WLCG JTW profile: if email scope is requested, the email claim is included in the AT; if profile scope is requested, name and preferred_username claims are included in the AT.
- Loading branch information
Showing
2 changed files
with
96 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ | |
@TestPropertySource(properties = { | ||
// @formatter:off | ||
"iam.jwt-profile.default-profile=wlcg", | ||
"iam.access_token.include_authn_info=true", | ||
"scope.matchers[0].name=storage.read", | ||
"scope.matchers[0].type=path", | ||
"scope.matchers[0].prefix=storage.read", | ||
|
@@ -747,7 +748,7 @@ public void attributesAreNotIncludedInAccessTokenWhenNotRequested() throws Excep | |
} | ||
|
||
@Test | ||
public void attributesAreIncludedInAccessTokenWhenNotRequested() throws Exception { | ||
public void attributesAreIncludedInAccessTokenWhenRequested() throws Exception { | ||
IamAccount testAccount = | ||
repo.findByUsername(TEST_USER).orElseThrow(assertionError(EXPECTED_USER_NOT_FOUND)); | ||
|
||
|
@@ -773,4 +774,55 @@ public void attributesAreIncludedInAccessTokenWhenNotRequested() throws Exceptio | |
assertThat(claims.getJSONObjectClaim("attr").get("test"), is("test")); | ||
} | ||
|
||
@Test | ||
public void additionalClaimsAreIncludedInAccessTokenWhenRequested() throws Exception { | ||
|
||
String tokenResponseJson = mvc | ||
.perform(post("/token").param("grant_type", "password") | ||
.param("client_id", CLIENT_ID) | ||
.param("client_secret", CLIENT_SECRET) | ||
.param("username", "test") | ||
.param("password", "password") | ||
.param("scope", "openid profile email")) | ||
.andExpect(status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
JWTClaimsSet claims = | ||
JWTParser.parse(mapper.readTree(tokenResponseJson).get("access_token").asText()) | ||
.getJWTClaimsSet(); | ||
|
||
assertThat(claims.getClaim("email"), notNullValue()); | ||
assertThat(claims.getClaim("email"), is("[email protected]")); | ||
assertThat(claims.getClaim("name"), notNullValue()); | ||
assertThat(claims.getClaim("name"), is("Test User")); | ||
assertThat(claims.getClaim("preferred_username"), notNullValue()); | ||
assertThat(claims.getClaim("preferred_username"), is("test")); | ||
} | ||
|
||
@Test | ||
public void additionalClaimsAreNotIncludedInAccessTokenWhenRNotequested() throws Exception { | ||
|
||
String tokenResponseJson = mvc | ||
.perform(post("/token").param("grant_type", "password") | ||
.param("client_id", CLIENT_ID) | ||
.param("client_secret", CLIENT_SECRET) | ||
.param("username", "test") | ||
.param("password", "password") | ||
.param("scope", "openid address")) | ||
.andExpect(status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
JWTClaimsSet claims = | ||
JWTParser.parse(mapper.readTree(tokenResponseJson).get("access_token").asText()) | ||
.getJWTClaimsSet(); | ||
|
||
assertThat(claims.getClaim("email"), nullValue()); | ||
assertThat(claims.getClaim("name"), nullValue()); | ||
assertThat(claims.getClaim("preferred_username"), nullValue()); | ||
} | ||
|
||
} |