From 4bd43020d5e05ca221ca1b896e79a0ff1d42135e Mon Sep 17 00:00:00 2001 From: MAN$I VERMA Date: Sat, 20 Jun 2026 02:05:27 +0530 Subject: [PATCH] fix(cfn): support oauth and callback configurations in UserPoolClient (#1458) --- .../CloudFormationResourceProvisioner.java | 59 +++++++++- .../CloudFormationIntegrationTest.java | 102 ++++++++++++++++++ 2 files changed, 157 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java index 19b203883a..b83bdf3909 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java @@ -2827,13 +2827,39 @@ public class CloudFormationResourceProvisioner { List allowedOAuthFlows = resolveStringListOrEmpty(props, "AllowedOAuthFlows", engine); List allowedOAuthScopes = resolveStringListOrEmpty(props, "AllowedOAuthScopes", engine); + Map analyticsConfiguration = resolveMapOrDefault(props, "AnalyticsConfiguration", engine, null); + List callbackURLs = resolveStringListOrEmpty(props, "CallbackURLs", engine); + String defaultRedirectURI = resolveOptional(props, "DefaultRedirectURI", engine); + List explicitAuthFlows = resolveStringListOrEmpty(props, "ExplicitAuthFlows", engine); + Integer accessTokenValidity = parseIntegerPropOrNull(props, "AccessTokenValidity", engine); + Integer idTokenValidity = parseIntegerPropOrNull(props, "IdTokenValidity", engine); + List logoutURLs = resolveStringListOrEmpty(props, "LogoutURLs", engine); + String preventUserExistenceErrors = resolveOptional(props, "PreventUserExistenceErrors", engine); + List readAttributes = resolveStringListOrEmpty(props, "ReadAttributes", engine); + Integer refreshTokenValidity = parseIntegerPropOrNull(props, "RefreshTokenValidity", engine); + List supportedIdentityProviders = resolveStringListOrEmpty(props, "SupportedIdentityProviders", engine); + Map tokenValidityUnits = resolveStringMapOrNull(props, "TokenValidityUnits", engine); + List writeAttributes = resolveStringListOrEmpty(props, "WriteAttributes", engine); + Map refreshTokenRotation = resolveMapOrDefault(props, "RefreshTokenRotation", engine, null); + Boolean enableTokenRevocation = parseBooleanOrNull(resolveOptional(props, "EnableTokenRevocation", engine)); + UserPoolClient client; if (r.getPhysicalId() == null) { - client = cognitoService.createUserPoolClient(userPoolId, clientName, generateSecret, - allowedOAuthFlowsUserPoolClient, allowedOAuthFlows, allowedOAuthScopes); + client = cognitoService.createUserPoolClient( + userPoolId, clientName, generateSecret, allowedOAuthFlowsUserPoolClient, + allowedOAuthFlows, allowedOAuthScopes, analyticsConfiguration, callbackURLs, + defaultRedirectURI, explicitAuthFlows, accessTokenValidity, idTokenValidity, + logoutURLs, preventUserExistenceErrors, readAttributes, refreshTokenValidity, + supportedIdentityProviders, tokenValidityUnits, writeAttributes, + refreshTokenRotation, enableTokenRevocation); } else { - client = cognitoService.updateUserPoolClient(userPoolId, r.getPhysicalId(), clientName, - allowedOAuthFlowsUserPoolClient, allowedOAuthFlows, allowedOAuthScopes); + client = cognitoService.updateUserPoolClient( + userPoolId, r.getPhysicalId(), clientName, allowedOAuthFlowsUserPoolClient, + allowedOAuthFlows, allowedOAuthScopes, analyticsConfiguration, callbackURLs, + defaultRedirectURI, explicitAuthFlows, accessTokenValidity, idTokenValidity, + logoutURLs, preventUserExistenceErrors, readAttributes, refreshTokenValidity, + supportedIdentityProviders, tokenValidityUnits, writeAttributes, + refreshTokenRotation, enableTokenRevocation); } r.setPhysicalId(client.getClientId()); @@ -2844,6 +2870,31 @@ public class CloudFormationResourceProvisioner { } } + private Integer parseIntegerPropOrNull(JsonNode props, String name, CloudFormationTemplateEngine engine) { + String value = resolveOptional(props, name, engine); + if (value == null || value.isBlank()) { + return null; + } + try { + return Integer.valueOf(value.trim()); + } catch (NumberFormatException e) { + return null; + } + } + + private Map resolveStringMapOrNull(JsonNode props, String source, CloudFormationTemplateEngine engine) { + if (props == null || !props.has(source) || props.get(source).isNull()) { + return null; + } + JsonNode resolved = engine.resolveNode(props.get(source)); + if (resolved == null || !resolved.isObject()) { + return null; + } + Map out = new LinkedHashMap<>(); + resolved.fields().forEachRemaining(e -> out.put(e.getKey(), e.getValue().asText())); + return out; + } + // ── Lambda LayerVersion ────────────────────────────────────────────────── // // Without this, layer versions (e.g. CDK's AwsCliLayer) fall through to the stub, so the diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java index 60de055cf6..f3505082b9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationIntegrationTest.java @@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.matchesRegex; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; @@ -4717,6 +4718,107 @@ class CloudFormationIntegrationTest { .statusCode(404); } + @Test + void createStack_withCognitoUserPoolClientOAuthFlowsAndCallbacks() { + String template = """ + { + "Resources": { + "Pool": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "UserPoolName": "cfn-oauth-test-pool" + } + }, + "Client": { + "Type": "AWS::Cognito::UserPoolClient", + "Properties": { + "ClientName": "web-client", + "UserPoolId": {"Ref": "Pool"}, + "AllowedOAuthFlows": ["implicit", "code"], + "AllowedOAuthFlowsUserPoolClient": true, + "AllowedOAuthScopes": ["openid", "profile", "email"], + "CallbackURLs": ["https://example.local/signin-redirect"], + "LogoutURLs": ["https://example.local"], + "SupportedIdentityProviders": ["COGNITO"], + "GenerateSecret": false + } + } + }, + "Outputs": { + "PoolId": { "Value": { "Ref": "Pool" } }, + "ClientId": { "Value": { "Ref": "Client" } } + } + } + """; + + String stackName = "cognito-oauth-stack"; + + // 1. Create Stack + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "CreateStack") + .formParam("StackName", stackName) + .formParam("TemplateBody", template) + .when() + .post("/") + .then() + .statusCode(200) + .body(containsString("")); + + // 2. Describe Stacks and capture outputs + String describeXml = given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "DescribeStacks") + .formParam("StackName", stackName) + .when() + .post("/") + .then() + .statusCode(200) + .body(containsString("CREATE_COMPLETE")) + .extract().asString(); + + String poolId = describeXml.split("PoolId")[1].split("")[1].split("")[0]; + String clientId = describeXml.split("ClientId")[1].split("")[1].split("")[0]; + + // 3. Verify UserPoolClient via Cognito API + given() + .header("X-Amz-Target", "AWSCognitoIdentityProviderService.DescribeUserPoolClient") + .contentType(COGNITO_CONTENT_TYPE) + .body("{\"UserPoolId\": \"" + poolId + "\", \"ClientId\": \"" + clientId + "\"}") + .when() + .post("/") + .then() + .statusCode(200) + .body("UserPoolClient.ClientName", equalTo("web-client")) + .body("UserPoolClient.UserPoolId", equalTo(poolId)) + .body("UserPoolClient.AllowedOAuthFlowsUserPoolClient", equalTo(true)) + .body("UserPoolClient.AllowedOAuthFlows", hasItems("implicit", "code")) + .body("UserPoolClient.AllowedOAuthScopes", hasItems("openid", "profile", "email")) + .body("UserPoolClient.CallbackURLs", hasItems("https://example.local/signin-redirect")) + .body("UserPoolClient.LogoutURLs", hasItems("https://example.local")) + .body("UserPoolClient.SupportedIdentityProviders", hasItems("COGNITO")); + + // 4. Delete Stack + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "DeleteStack") + .formParam("StackName", stackName) + .when() + .post("/") + .then() + .statusCode(200); + + // 5. Verify resources are deleted + given() + .header("X-Amz-Target", "AWSCognitoIdentityProviderService.DescribeUserPoolClient") + .contentType(COGNITO_CONTENT_TYPE) + .body("{\"UserPoolId\": \"" + poolId + "\", \"ClientId\": \"" + clientId + "\"}") + .when() + .post("/") + .then() + .statusCode(404); + } + @Test void createStack_withNestedStack_resourcesAreProvisioned() { String childTemplate = """