mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(cognito): include all standard attributes in DescribeUserPool Schema (#642)
* feat(cognito): include all standard attributes in DescribeUserPool SchemaAttributes AWS Cognito always returns all 20 standard OIDC attributes (sub, name, email, phone_number, etc.) in SchemaAttributes when describing a user pool, even if none were explicitly configured. Floci was returning only what was passed in Schema during creation. Adds CognitoStandardAttributes with the full default set and a merge() helper that overlays explicit schema overrides and appends custom: attributes after the standard ones. * test(cognito): add compat tests for standard SchemaAttributes across all SDKs Adds DescribeUserPool SchemaAttributes coverage to all compatibility test suites (AWS CLI/bats, Go, Java, Node, Python, Rust), verifying that all 20 standard OIDC attributes are returned and that sub is required and immutable.
This commit is contained in:
12 files changed
+620
-3
No files matched your search
@@ -495,7 +495,7 @@ public class CognitoJsonHandler {
|
||||
node.set("Policies", objectMapper.valueToTree(p.getPolicies() != null ? p.getPolicies() : new HashMap<>()));
|
||||
node.put("DeletionProtection", p.getDeletionProtection() != null ? p.getDeletionProtection() : "INACTIVE");
|
||||
node.set("LambdaConfig", objectMapper.valueToTree(p.getLambdaConfig() != null ? p.getLambdaConfig() : new HashMap<>()));
|
||||
node.set("SchemaAttributes", objectMapper.valueToTree(p.getSchemaAttributes() != null ? p.getSchemaAttributes() : new java.util.ArrayList<>()));
|
||||
node.set("SchemaAttributes", objectMapper.valueToTree(CognitoStandardAttributes.merge(p.getSchemaAttributes())));
|
||||
node.set("AutoVerifiedAttributes", objectMapper.valueToTree(p.getAutoVerifiedAttributes() != null ? p.getAutoVerifiedAttributes() : new java.util.ArrayList<>()));
|
||||
node.set("AliasAttributes", objectMapper.valueToTree(p.getAliasAttributes() != null ? p.getAliasAttributes() : new java.util.ArrayList<>()));
|
||||
node.set("UsernameAttributes", objectMapper.valueToTree(p.getUsernameAttributes() != null ? p.getUsernameAttributes() : new java.util.ArrayList<>()));
|
||||
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package io.github.hectorvent.floci.services.cognito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class CognitoStandardAttributes {
|
||||
|
||||
private CognitoStandardAttributes() {}
|
||||
|
||||
static final List<Map<String, Object>> DEFAULTS = buildDefaults();
|
||||
|
||||
private static List<Map<String, Object>> buildDefaults() {
|
||||
List<Map<String, Object>> attrs = new ArrayList<>();
|
||||
|
||||
attrs.add(stringAttr("sub", "1", "2048", false, true));
|
||||
attrs.add(stringAttr("name", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("given_name", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("family_name", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("middle_name", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("nickname", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("preferred_username", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("profile", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("picture", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("website", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("email", "0", "2048", true, false));
|
||||
attrs.add(booleanAttr("email_verified"));
|
||||
attrs.add(stringAttr("gender", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("birthdate", "10", "10", true, false));
|
||||
attrs.add(stringAttr("zoneinfo", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("locale", "0", "2048", true, false));
|
||||
attrs.add(stringAttr("phone_number", "0", "2048", true, false));
|
||||
attrs.add(booleanAttr("phone_number_verified"));
|
||||
attrs.add(stringAttr("address", "0", "2048", true, false));
|
||||
attrs.add(numberAttr("updated_at"));
|
||||
|
||||
return List.copyOf(attrs);
|
||||
}
|
||||
|
||||
private static Map<String, Object> stringAttr(String name, String minLength, String maxLength,
|
||||
boolean mutable, boolean required) {
|
||||
Map<String, Object> attr = new LinkedHashMap<>();
|
||||
attr.put("Name", name);
|
||||
attr.put("AttributeDataType", "String");
|
||||
attr.put("DeveloperOnlyAttribute", false);
|
||||
attr.put("Mutable", mutable);
|
||||
attr.put("Required", required);
|
||||
attr.put("StringAttributeConstraints", Map.of("MinLength", minLength, "MaxLength", maxLength));
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static Map<String, Object> booleanAttr(String name) {
|
||||
Map<String, Object> attr = new LinkedHashMap<>();
|
||||
attr.put("Name", name);
|
||||
attr.put("AttributeDataType", "Boolean");
|
||||
attr.put("DeveloperOnlyAttribute", false);
|
||||
attr.put("Mutable", true);
|
||||
attr.put("Required", false);
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static Map<String, Object> numberAttr(String name) {
|
||||
Map<String, Object> attr = new LinkedHashMap<>();
|
||||
attr.put("Name", name);
|
||||
attr.put("AttributeDataType", "Number");
|
||||
attr.put("DeveloperOnlyAttribute", false);
|
||||
attr.put("Mutable", true);
|
||||
attr.put("Required", false);
|
||||
attr.put("NumberAttributeConstraints", Map.of("MinValue", "0"));
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges standard attributes with any pool-defined schema.
|
||||
* Custom attributes (name starts with "custom:") are appended after standard ones.
|
||||
* Standard attributes explicitly included in the schema override the defaults.
|
||||
*/
|
||||
static List<Map<String, Object>> merge(List<Map<String, Object>> poolSchema) {
|
||||
if (poolSchema == null || poolSchema.isEmpty()) {
|
||||
return DEFAULTS;
|
||||
}
|
||||
|
||||
Map<String, Map<String, Object>> byName = new LinkedHashMap<>();
|
||||
for (Map<String, Object> attr : DEFAULTS) {
|
||||
byName.put((String) attr.get("Name"), attr);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> custom = new ArrayList<>();
|
||||
for (Map<String, Object> attr : poolSchema) {
|
||||
String name = (String) attr.get("Name");
|
||||
if (name != null && name.startsWith("custom:")) {
|
||||
custom.add(attr);
|
||||
} else if (name != null && byName.containsKey(name)) {
|
||||
byName.put(name, attr);
|
||||
} else if (name != null) {
|
||||
custom.add(attr);
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, Object>> result = new ArrayList<>(byName.values());
|
||||
result.addAll(custom);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user