fix(cognito): pass ClientMetadata to the pre token trigger on GetTokensFromRefreshToken (#9381)

GetTokensFromRefreshToken dropped the request's ClientMetadata, so the PreTokenGeneration trigger (TokenGeneration_RefreshTokens) always received an empty clientMetadata. The request's map now reaches the trigger, as the API reference documents for the action's ClientMetadata. The OAuth token endpoint's refresh_token grant still passes none, since it has no ClientMetadata.

Closes #9278
This commit is contained in:
Neil du Toit authored and GitHub committed 2026-11-24 20:00:58 -04:00
1 parent 615444a2aa
commit af0c646abb
5 files changed
+45 -6

No files matched your search

@@ -2700,8 +2700,9 @@ final class CognitoAuthFlowHandler {
/** {@code scopes} are those of the grant being refreshed, or null for a sign-in through the API. */
CognitoService.ClaimsOverride preTokenGenerationForRefresh(UserPool pool, UserPoolClient client, CognitoUser user,
List<String> scopes) {
return firePreTokenGeneration(pool, client, user, Map.of(), "TokenGeneration_RefreshTokens", scopes);
List<String> scopes,
Map<String, String> clientMetadata) {
return firePreTokenGeneration(pool, client, user, clientMetadata, "TokenGeneration_RefreshTokens", scopes);
}
/**
@@ -912,7 +912,8 @@ public class CognitoJsonHandler {
private Response handleGetTokensFromRefreshToken(JsonNode request) {
Map<String, Object> result = service.getTokensFromRefreshToken(
request.path("ClientId").asText(),
request.path("RefreshToken").asText()
request.path("RefreshToken").asText(),
clientMetadata(request)
);
return Response.ok(objectMapper.valueToTree(result)).build();
}
@@ -4927,9 +4927,16 @@ public class CognitoService implements ResourceProvider, StoredResourceArns {
/**
* Mints new access and ID tokens from a refresh token, as the sign-in that issued it did: an OAuth
* grant's access token keeps the grant's scopes, and has an ID token only with {@code openid}.
* Shared by {@code GetTokensFromRefreshToken} and the OAuth token endpoint's refresh_token grant.
* Shared by {@code GetTokensFromRefreshToken} and the OAuth token endpoint's refresh_token grant,
* which has no {@code ClientMetadata} to pass.
*/
public Map<String, Object> getTokensFromRefreshToken(String clientId, String refreshToken) {
return getTokensFromRefreshToken(clientId, refreshToken, Map.of());
}
/** As above, with the request's {@code ClientMetadata}, which reaches only the PreTokenGeneration trigger. */
public Map<String, Object> getTokensFromRefreshToken(String clientId, String refreshToken,
Map<String, String> clientMetadata) {
if (refreshToken == null) {
throw new AwsException("InvalidParameterException", "RefreshToken is required", 400);
}
@@ -4963,7 +4970,8 @@ public class CognitoService implements ResourceProvider, StoredResourceArns {
UserPool pool = describeUserPool(poolId);
CognitoUser user = adminGetUser(poolId, username);
ClaimsOverride override = authFlowHandler.preTokenGenerationForRefresh(pool, client, user, scopes);
ClaimsOverride override = authFlowHandler.preTokenGenerationForRefresh(pool, client, user, scopes,
clientMetadata);
// Use refresh token UUID as origin_jti for derived tokens
Map<String, Object> result = new HashMap<>();