fix(cognito): run missing post-confirmation triggers (#5207)

* fix(cognito): run missing post-confirmation triggers

* fix(cognito): forward confirmation client metadata
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-09 10:23:06 -04:00
1 parent 0ec64add2d
commit 5dfb45d71f
3 files changed
+108 -17

No files matched your search

@@ -983,10 +983,13 @@ public class CognitoJsonHandler {
}
private Response handleConfirmSignUp(JsonNode request) {
Map<String, String> clientMetadata = new HashMap<>();
request.path("ClientMetadata").fields().forEachRemaining(e -> clientMetadata.put(e.getKey(), e.getValue().asText()));
service.confirmSignUp(
request.path("ClientId").asText(),
request.path("Username").asText(),
request.path("ConfirmationCode").asText()
request.path("ConfirmationCode").asText(),
clientMetadata
);
return Response.ok(objectMapper.createObjectNode()).build();
}
@@ -1005,9 +1008,12 @@ public class CognitoJsonHandler {
}
private Response handleAdminConfirmSignUp(JsonNode request) {
Map<String, String> clientMetadata = new HashMap<>();
request.path("ClientMetadata").fields().forEachRemaining(e -> clientMetadata.put(e.getKey(), e.getValue().asText()));
service.adminConfirmSignUp(
request.path("UserPoolId").asText(),
request.path("Username").asText()
request.path("Username").asText(),
clientMetadata
);
return Response.ok(objectMapper.createObjectNode()).build();
}
@@ -1035,11 +1041,14 @@ public class CognitoJsonHandler {
}
private Response handleConfirmForgotPassword(JsonNode request) {
Map<String, String> clientMetadata = new HashMap<>();
request.path("ClientMetadata").fields().forEachRemaining(e -> clientMetadata.put(e.getKey(), e.getValue().asText()));
service.confirmForgotPassword(
request.path("ClientId").asText(),
request.path("Username").asText(),
request.path("ConfirmationCode").asText(),
request.path("Password").asText()
request.path("Password").asText(),
clientMetadata
);
return Response.ok(objectMapper.createObjectNode()).build();
}
@@ -3073,21 +3073,26 @@ public class CognitoService implements ResourceProvider {
}
public void confirmSignUp(String clientId, String username) {
confirmSignUp(clientId, username, null);
confirmSignUp(clientId, username, null, Map.of());
}
public void confirmSignUp(String clientId, String username, String confirmationCode) {
confirmSignUp(clientId, username, confirmationCode, Map.of());
}
public void confirmSignUp(String clientId, String username, String confirmationCode,
Map<String, String> clientMetadata) {
UserPoolClient client = clientStore.get(clientId)
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Client not found",
400));
String userPoolId = client.getUserPoolId();
synchronized (userLock(userPoolId, username)) {
confirmSignUpUnderUserLock(client, userPoolId, username, confirmationCode);
confirmSignUpUnderUserLock(client, userPoolId, username, confirmationCode, clientMetadata);
}
}
private void confirmSignUpUnderUserLock(UserPoolClient client, String userPoolId, String username,
String confirmationCode) {
String confirmationCode, Map<String, String> clientMetadata) {
UserPool pool = poolStore.get(userPoolId)
.orElseThrow(() -> userPoolNotFound(userPoolId));
CognitoUser user = adminGetUser(client.getUserPoolId(), username);
@@ -3113,7 +3118,7 @@ public class CognitoService implements ResourceProvider {
user.setUserStatus("CONFIRMED");
user.setLastModifiedDate(System.currentTimeMillis() / 1000L);
userStore.put(userKey(client.getUserPoolId(), user.getUsername()), user);
authFlowHandler.firePostConfirmation(pool, client, user, Map.of(), "PostConfirmation_ConfirmSignUp");
authFlowHandler.firePostConfirmation(pool, client, user, clientMetadata, "PostConfirmation_ConfirmSignUp");
}
Map<String, String> signUpCodeDeliveryDetails(CognitoUser user) {
@@ -3177,18 +3182,26 @@ public class CognitoService implements ResourceProvider {
}
public void adminConfirmSignUp(String userPoolId, String username) {
CognitoUser resolvedUser = adminGetUser(userPoolId, username);
synchronized (userLock(userPoolId, resolvedUser.getUsername())) {
adminConfirmSignUpUnderUserLock(userPoolId, resolvedUser.getUsername());
}
adminConfirmSignUp(userPoolId, username, Map.of());
}
private void adminConfirmSignUpUnderUserLock(String userPoolId, String username) {
public void adminConfirmSignUp(String userPoolId, String username, Map<String, String> clientMetadata) {
CognitoUser resolvedUser = adminGetUser(userPoolId, username);
CognitoUser user;
synchronized (userLock(userPoolId, resolvedUser.getUsername())) {
user = adminConfirmSignUpUnderUserLock(userPoolId, resolvedUser.getUsername());
}
authFlowHandler.firePostConfirmation(describeUserPool(userPoolId), null, user,
clientMetadata, "PostConfirmation_ConfirmSignUp");
}
private CognitoUser adminConfirmSignUpUnderUserLock(String userPoolId, String username) {
CognitoUser user = adminGetUser(userPoolId, username);
user.setUserStatus("CONFIRMED");
user.setLastModifiedDate(System.currentTimeMillis() / 1000L);
userStore.put(userKey(userPoolId, user.getUsername()), user);
LOG.infov("Admin confirmed sign up for user {0} in pool {1}", username, userPoolId);
return user;
}
// ──────────────────────────── Auth ────────────────────────────
@@ -3362,6 +3375,11 @@ public class CognitoService implements ResourceProvider {
}
public void confirmForgotPassword(String clientId, String username, String confirmationCode, String newPassword) {
confirmForgotPassword(clientId, username, confirmationCode, newPassword, Map.of());
}
public void confirmForgotPassword(String clientId, String username, String confirmationCode, String newPassword,
Map<String, String> clientMetadata) {
UserPoolClient client = clientStore.get(clientId)
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Client not found", 400));
CognitoUser user = adminGetUser(client.getUserPoolId(), username);
@@ -3373,6 +3391,9 @@ public class CognitoService implements ResourceProvider {
throw mapVerificationCodeException(e);
}
adminSetUserPassword(client.getUserPoolId(), user.getUsername(), newPassword, true);
authFlowHandler.firePostConfirmation(describeUserPool(client.getUserPoolId()), client,
adminGetUser(client.getUserPoolId(), user.getUsername()), clientMetadata,
"PostConfirmation_ConfirmForgotPassword");
}
public Map<String, Object> getUser(String accessToken) {