mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
1 parent
205a8f174b
commit
bb7c45ce1b
3 files changed
+145
No files matched your search
@@ -74,6 +74,7 @@ public class CognitoJsonHandler {
|
||||
case "AdminRespondToAuthChallenge" -> handleAdminRespondToAuthChallenge(request);
|
||||
case "SignUp" -> handleSignUp(request);
|
||||
case "ConfirmSignUp" -> handleConfirmSignUp(request);
|
||||
case "ResendConfirmationCode" -> handleResendConfirmationCode(request);
|
||||
case "AdminConfirmSignUp" -> handleAdminConfirmSignUp(request);
|
||||
case "ChangePassword" -> handleChangePassword(request);
|
||||
case "ForgotPassword" -> handleForgotPassword(request);
|
||||
@@ -559,6 +560,19 @@ public class CognitoJsonHandler {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response handleResendConfirmationCode(JsonNode request) {
|
||||
Map<String, String> deliveryDetails = service.resendConfirmationCode(
|
||||
request.path("ClientId").asText(),
|
||||
request.path("Username").asText()
|
||||
);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ObjectNode delivery = response.putObject("CodeDeliveryDetails");
|
||||
delivery.put("AttributeName", deliveryDetails.get("AttributeName"));
|
||||
delivery.put("DeliveryMedium", deliveryDetails.get("DeliveryMedium"));
|
||||
delivery.put("Destination", deliveryDetails.get("Destination"));
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleAdminConfirmSignUp(JsonNode request) {
|
||||
service.adminConfirmSignUp(
|
||||
request.path("UserPoolId").asText(),
|
||||
|
||||
@@ -1251,6 +1251,51 @@ public class CognitoService {
|
||||
deliveryTarget.deliveryMedium(), "Destination", deliveryTarget.destination());
|
||||
}
|
||||
|
||||
public Map<String, String> resendConfirmationCode(String clientId, String username) {
|
||||
UserPoolClient client = clientStore.get(clientId)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Client not found",
|
||||
400));
|
||||
UserPool pool = describeUserPool(client.getUserPoolId());
|
||||
CognitoUser user = adminGetUser(client.getUserPoolId(), username);
|
||||
if (!"UNCONFIRMED".equals(user.getUserStatus())) {
|
||||
throw new AwsException("NotAuthorizedException",
|
||||
"User cannot be confirmed. Current status is " + user.getUserStatus(), 400);
|
||||
}
|
||||
if (!isSignUpConfirmationEnabled(pool)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"User pool does not have sign-up confirmation delivery configured", 400);
|
||||
}
|
||||
|
||||
DeliveryTarget deliveryTarget = resolveSignUpDeliveryTarget(pool, user);
|
||||
if (deliveryTarget == null) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Cannot confirm user because email or phone_number is missing", 400);
|
||||
}
|
||||
|
||||
ensureVerificationWiring();
|
||||
verificationCodeService.invalidatePrevious(pool.getId(), user.getUsername(),
|
||||
VerificationCode.Purpose.SIGNUP_CONFIRMATION);
|
||||
try {
|
||||
String code = verificationCodeService.issue(pool.getId(), user.getUsername(),
|
||||
VerificationCode.Purpose.SIGNUP_CONFIRMATION, Duration.ofHours(24));
|
||||
messageDispatcher.dispatch(pool, user, VerificationCode.Purpose.SIGNUP_CONFIRMATION,
|
||||
code, List.of(deliveryTarget.deliveryMedium()));
|
||||
} catch (VerificationCodeException e) {
|
||||
throw mapVerificationCodeException(e);
|
||||
} catch (RuntimeException e) {
|
||||
verificationCodeService.invalidatePrevious(pool.getId(), user.getUsername(),
|
||||
VerificationCode.Purpose.SIGNUP_CONFIRMATION);
|
||||
throw new AwsException("CodeDeliveryFailureException",
|
||||
"Failed to deliver the message.", 400);
|
||||
}
|
||||
|
||||
return Map.of(
|
||||
"AttributeName", deliveryTarget.attributeName(),
|
||||
"DeliveryMedium", deliveryTarget.deliveryMedium(),
|
||||
"Destination", deliveryTarget.destination()
|
||||
);
|
||||
}
|
||||
|
||||
public void adminConfirmSignUp(String userPoolId, String username) {
|
||||
CognitoUser user = adminGetUser(userPoolId, username);
|
||||
user.setUserStatus("CONFIRMED");
|
||||
|
||||
Reference in new issue
Block a user