Skip to content

Commit

Permalink
Show acr claim in the introspection response
Browse files Browse the repository at this point in the history
  • Loading branch information
rmiccoli committed Feb 19, 2025
1 parent 347f25e commit 2a16b96
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public Map<String, Object> assembleIntrospectionResult(OAuth2AccessTokenEntity a
}
}

addAcrClaimIfNeeded(accessToken, result);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ protected void addAudience(Map<String, Object> introspectionResult,

}

protected void addAcrClaimIfNeeded(OAuth2AccessTokenEntity accessToken,
Map<String, Object> introspectionResult) {

try {
Object acr = accessToken.getJwt().getJWTClaimsSet().getClaim("acr");
if (acr instanceof String acrString) {
introspectionResult.put("acr", acrString);
}
} catch (ParseException e) {
LOG.error("Error getting acr claim out of access token: {}", e.getMessage(), e);
}

}

protected Set<String> filterScopes(OAuth2AccessTokenEntity accessToken, Set<String> authScopes) {

Set<ScopeMatcher> matchers = authScopes.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public Map<String, Object> assembleIntrospectionResult(OAuth2AccessTokenEntity a

// Intersection of scopes authorized for the client and scopes linked to the
// access token, using the scope matchers registry

Set<String> scopes = filterScopes(accessToken, authScopes);

addScopeClaim(result, scopes);

if (userInfo != null) {
Expand All @@ -80,6 +80,8 @@ public Map<String, Object> assembleIntrospectionResult(OAuth2AccessTokenEntity a
}
}

addAcrClaimIfNeeded(accessToken, result);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ public Map<String, Object> assembleIntrospectionResult(OAuth2AccessTokenEntity a
addIssuerClaim(result);
addAudience(result, accessToken);
addScopeClaim(result, filterScopes(accessToken, authScopes));

Set<String> groups =
groupHelper.resolveGroupNames(((UserInfoAdapter) userInfo).getUserinfo());

Set<String> groups = groupHelper.resolveGroupNames(((UserInfoAdapter) userInfo).getUserinfo());

if (!groups.isEmpty()) {
result.put(KeycloakGroupHelper.KEYCLOAK_ROLES_CLAIM, groups);
}

addAcrClaimIfNeeded(accessToken, result);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ public Map<String, Object> assembleIntrospectionResult(OAuth2AccessTokenEntity a
addIssuerClaim(result);
addAudience(result, accessToken);
addScopeClaim(result, filterScopes(accessToken, authScopes));

Set<String> groups =
groupHelper.resolveGroupNames(accessToken, ((UserInfoAdapter) userInfo).getUserinfo());

if (!groups.isEmpty()) {
result.put(WLCGGroupHelper.WLCG_GROUPS_SCOPE, groups);
}

addAcrClaimIfNeeded(accessToken, result);

return result;
}

Expand Down

0 comments on commit 2a16b96

Please sign in to comment.