diff --git a/docs/services/cognito.md b/docs/services/cognito.md
index 54cc64c608..772e1afd51 100644
--- a/docs/services/cognito.md
+++ b/docs/services/cognito.md
@@ -145,6 +145,46 @@ further divergences, both deliberate:
| AdminRemoveUserFromGroup | Removes a user from a group. |
| AdminListGroupsForUser | Lists the groups assigned to a user. |
+### Managed Login Branding
+
+| Action | Description |
+|--------|-------------|
+| CreateManagedLoginBranding | Creates the branding for an app client. |
+| DescribeManagedLoginBranding | Returns a branding by its id. |
+| DescribeManagedLoginBrandingByClient | Returns the branding attached to an app client. |
+| UpdateManagedLoginBranding | Updates a branding's settings, assets or provided-values flag. |
+| DeleteManagedLoginBranding | Deletes a branding from its app client. |
+
+`CreateManagedLoginBranding` must name either `UseCognitoProvidedValues` or `Settings`; a
+request with neither is rejected. One branding per app client: a second
+`CreateManagedLoginBranding` for the same client is rejected with
+`ManagedLoginBrandingExistsException`. `ManagedLoginBrandingId` must be a
+version 4 UUID, and a malformed one is rejected before the lookup, as AWS does.
+`Assets` holds at most 40 entries on create and on update.
+`Settings` is omitted from the response when the caller supplied none, while `Assets` is
+always returned. Members an update omits are left unchanged.
+
+The asset-count and branding-id checks run before the pool, client or branding is looked
+up, so an oversized request naming something that does not exist reports the request
+problem rather than `ResourceNotFoundException`, and an update violating both reports them
+in one message with the asset list first.
+
+Branding is presentation for the hosted UI, which Floci does not serve, so it is stored
+and returned rather than rendered. Two divergences follow from that:
+
+- **`Settings` is stored opaquely.** AWS validates it against a deep schema, rejecting
+ unknown properties with `Invalid settings provided. Validation errors: [{property:
+ $.components...., errorType: UnknownProperty}]`. That schema is not published, so Floci
+ accepts any object.
+- **A wrongly typed `Settings` returns a client error.** AWS answers that particular input
+ with `InternalErrorException` and a 500; Floci returns
+ `SerializationException: Unexpected field type`, which is what AWS returns for a wrongly
+ typed `Assets`. Reproducing someone else's 500 seemed worse than being consistent.
+- **`ReturnMergedResources` is not honoured.** Against AWS it merges Cognito's own default
+ settings and assets into the response: on a pool with 8 configured assets it returns 38.
+ Reproducing that needs Cognito's default corpus, so Floci returns the stored branding
+ either way.
+
## Well-Known And OAuth Endpoints
| Endpoint | Description |
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
index b7431f7791..bdca6f26bb 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
@@ -15,12 +15,14 @@ import io.github.hectorvent.floci.services.cognito.model.UserPool;
import io.github.hectorvent.floci.services.cognito.model.UserPoolClient;
import io.github.hectorvent.floci.services.cognito.model.UserPoolClientSecret;
import io.github.hectorvent.floci.services.cognito.model.UserPoolDomain;
+import io.github.hectorvent.floci.services.cognito.model.ManagedLoginBranding;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -75,6 +77,11 @@ public class CognitoJsonHandler {
case "AdminEnableUser" -> handleAdminEnableUser(request);
case "AdminDisableUser" -> handleAdminDisableUser(request);
case "AdminLinkProviderForUser" -> handleAdminLinkProviderForUser(request);
+ case "CreateManagedLoginBranding" -> handleCreateManagedLoginBranding(request);
+ case "DescribeManagedLoginBranding" -> handleDescribeManagedLoginBranding(request);
+ case "DescribeManagedLoginBrandingByClient" -> handleDescribeManagedLoginBrandingByClient(request);
+ case "UpdateManagedLoginBranding" -> handleUpdateManagedLoginBranding(request);
+ case "DeleteManagedLoginBranding" -> handleDeleteManagedLoginBranding(request);
case "ListUsers" -> handleListUsers(request);
case "InitiateAuth" -> handleInitiateAuth(request);
case "AdminInitiateAuth" -> handleAdminInitiateAuth(request);
@@ -555,6 +562,139 @@ public class CognitoJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
+ /**
+ * AWS coerces a JSON string in this member instead of rejecting it, and rejects every
+ * other non-boolean type. Measured against Cognito in ap-southeast-1:
+ *
+ *
+ * absent accepted, stored false
+ * true / false accepted as given
+ * "true", "yes" accepted, stored true
+ * "false" accepted, stored false
+ * 1, null, {}, [] SerializationException
+ *
+ *
+ * Jackson would map all of those last four to false through {@code asBoolean()},
+ * which is how a malformed flag used to be accepted alongside valid settings and
+ * persisted as unintended branding state.
+ */
+ private static Boolean readUseCognitoProvidedValues(JsonNode request) {
+ if (!request.has("UseCognitoProvidedValues")) {
+ return null;
+ }
+ JsonNode node = request.path("UseCognitoProvidedValues");
+ if (node.isBoolean()) {
+ return node.booleanValue();
+ }
+ if (node.isTextual()) {
+ return !"false".equalsIgnoreCase(node.asText());
+ }
+ throw new AwsException("SerializationException", null, 400);
+ }
+
+ private Response handleCreateManagedLoginBranding(JsonNode request) {
+ ManagedLoginBranding branding = service.createManagedLoginBranding(
+ request.path("UserPoolId").asText(),
+ request.path("ClientId").asText(),
+ readUseCognitoProvidedValues(request),
+ readObjectMap(request, "Settings"),
+ readMapList(request, "Assets")
+ );
+ return brandingResponse(branding);
+ }
+
+ private Response handleDescribeManagedLoginBranding(JsonNode request) {
+ return brandingResponse(service.describeManagedLoginBranding(
+ request.path("UserPoolId").asText(),
+ request.path("ManagedLoginBrandingId").asText(null)));
+ }
+
+ private Response handleDescribeManagedLoginBrandingByClient(JsonNode request) {
+ return brandingResponse(service.describeManagedLoginBrandingByClient(
+ request.path("UserPoolId").asText(),
+ request.path("ClientId").asText()));
+ }
+
+ private Response handleUpdateManagedLoginBranding(JsonNode request) {
+ return brandingResponse(service.updateManagedLoginBranding(
+ request.path("UserPoolId").asText(),
+ request.path("ManagedLoginBrandingId").asText(null),
+ readUseCognitoProvidedValues(request),
+ readObjectMap(request, "Settings"),
+ readMapList(request, "Assets")));
+ }
+
+ private Response handleDeleteManagedLoginBranding(JsonNode request) {
+ service.deleteManagedLoginBranding(
+ request.path("UserPoolId").asText(),
+ request.path("ManagedLoginBrandingId").asText(null));
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response brandingResponse(ManagedLoginBranding branding) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ManagedLoginBranding", managedLoginBrandingToNode(branding));
+ return Response.ok(response).build();
+ }
+
+ /** AWS omits Settings entirely when none was supplied, but always returns Assets. */
+ private ObjectNode managedLoginBrandingToNode(ManagedLoginBranding branding) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("ManagedLoginBrandingId", branding.getManagedLoginBrandingId());
+ node.put("UserPoolId", branding.getUserPoolId());
+ node.put("UseCognitoProvidedValues", branding.isUseCognitoProvidedValues());
+ if (branding.getSettings() != null) {
+ node.set("Settings", objectMapper.valueToTree(branding.getSettings()));
+ }
+ ArrayNode assets = node.putArray("Assets");
+ branding.getAssets().forEach(asset -> assets.add(objectMapper.valueToTree(asset)));
+ node.put("CreationDate", branding.getCreationDate());
+ node.put("LastModifiedDate", branding.getLastModifiedDate());
+ return node;
+ }
+
+ /** Absent or null yields null; a value of the wrong JSON type is a deserialization failure. */
+ private Map readObjectMap(JsonNode request, String member) {
+ JsonNode node = request.get(member);
+ if (node == null || node.isNull()) {
+ return null;
+ }
+ if (!node.isObject()) {
+ throw new AwsException("SerializationException", "Unexpected field type", 400);
+ }
+ return objectMapper.convertValue(node, new TypeReference>() {});
+ }
+
+ /**
+ * Elements are checked before conversion so a scalar cannot escape as an IllegalArgumentException.
+ * AWS separates the two failures: a null element is a validation error, a non-object element a
+ * deserialization one. Note this differs from LogConfigurations, where a null element is dropped.
+ */
+ private List