Skip to content

feat: add CognitoUserPoolConstruct with managed login branding support#62

Merged
ncipollina merged 4 commits intomainfrom
feat/cognito-user-pool-construct
Apr 3, 2026
Merged

feat: add CognitoUserPoolConstruct with managed login branding support#62
ncipollina merged 4 commits intomainfrom
feat/cognito-user-pool-construct

Conversation

@ncipollina
Copy link
Copy Markdown
Contributor

Summary

Introduces CognitoUserPoolConstruct, a new CDK L3 construct that provisions a fully configured Cognito User Pool. It covers the entire Cognito surface needed for production apps: custom or Cognito-hosted domains, app clients, resource servers with scopes, user groups, AWS Managed Login branding (v2), and CloudFormation exports for cross-stack consumption.

Changes

New construct — CognitoUserPoolConstruct

  • Creates a UserPool with sensible defaults (email sign-in, auto-verify, configurable password policy, MFA, removal policy)
  • Configures a Cognito-hosted or custom domain (with ACM certificate + Route 53 alias record)
  • Creates resource servers and scopes
  • Creates app clients with full OAuth settings (flows, scopes, callback/logout URLs, identity providers)
  • Creates CfnManagedLoginBranding resources linked to app clients, with a dependency on the domain and JSII-compatible JSON serialization via ToJsiiCompatible
  • Creates user pool groups
  • Emits CfnOutput CloudFormation exports: {stack}-{id}-user-pool-id, {stack}-{id}-user-pool-arn, {stack}-{id}-client-{name}-id

New models

  • ICognitoUserPoolConstructProps / CognitoUserPoolConstructProps
  • ICognitoUserPoolDomainProps / CognitoUserPoolDomainProps (supports Cognito prefix or custom domain)
  • ICognitoUserPoolAppClientProps / CognitoUserPoolAppClientProps
  • ICognitoResourceServerProps / CognitoResourceServerProps
  • ICognitoResourceServerScopeProps / CognitoResourceServerScopeProps
  • ICognitoUserPoolGroupProps / CognitoUserPoolGroupProps
  • ICognitoManagedLoginBrandingProps / CognitoManagedLoginBrandingProps (settings JSON + optional assets)
  • ICognitoManagedLoginBrandingAssetProps / CognitoManagedLoginBrandingAssetProps
  • CognitoManagedLoginVersion enum (ManagedLogin / ClassicHostedUi)

Testing helpers (shipped in the library)

  • CognitoUserPoolConstructPropsBuilder — fluent builder for test props
  • CognitoUserPoolConstructAssertionsShouldHaveUserPool, ShouldHaveCognitoUserPoolDomain, ShouldHaveUserPoolClient, ShouldHaveResourceServer, ShouldHaveUserPoolGroup, ShouldHaveManagedLoginBranding, ShouldNotHaveManagedLoginBranding, ShouldExportUserPoolId, ShouldExportUserPoolArn, ShouldExportAppClientId
  • CdkTestHelper.CreateCognitoUserPoolPropsBuilder factory method

Unit tests

  • 16 tests in CognitoUserPoolConstructTests covering all construct behaviors including branding present/absent, empty settings JSON guard, and all three CloudFormation exports

Build scripts

  • scripts/pack-local.ps1 / scripts/pack-local.sh — pack and install to local NuGet cache for consuming repos

Validation

  • dotnet test — all 16 new tests pass alongside existing suite
  • dotnet build — no errors, pre-existing warnings only

Release Notes

CognitoUserPoolConstruct — new L3 construct for Cognito User Pools with managed login branding, cross-stack exports, and a full suite of shipped test helpers.

Notes for Reviewers

The JSII runtime cannot serialize System.Text.Json.JsonElement directly. The ToJsiiCompatible method recursively converts the parsed branding JSON into plain CLR types (Dictionary<string,object>, arrays, primitives) before passing it to CfnManagedLoginBrandingProps.Settings. The branding resource is also given an explicit CDK dependency on the domain to ensure correct CloudFormation creation order when using Managed Login v2.

Introduces a new CDK construct for provisioning Cognito User Pools with
full support for custom domains, app clients, resource servers, user
groups, CloudFormation outputs, and AWS Managed Login branding (v2).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb43fa5e6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ncipollina and others added 3 commits April 3, 2026 08:05
Document CognitoUserPoolConstruct covering domain modes (Cognito-hosted
and custom), resource servers, app clients, user groups, Managed Login
branding, CloudFormation exports, testing helpers, and AutoFixture
integration. Update docs/index.md, docs/testing/index.md, README.md,
mkdocs.yml, and the .slnx solution file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cognito custom domains require an ACM certificate in us-east-1.
The Certificate construct has no Region property in CDK v2 (DnsValidatedCertificate
which had one is deprecated). Add an optional ICertificate property to
ICognitoUserPoolDomainProps so callers deploying outside us-east-1 can
provide a pre-created certificate from a us-east-1 stack. When null,
the construct creates one in the stack's region as before (valid for
stacks already in us-east-1).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a synth-time guard that throws when a custom domain is configured
without a caller-supplied certificate and the stack region is resolved
to something other than us-east-1. Cognito requires certificates in
us-east-1; this surfaces the misconfiguration immediately with a clear
message instead of failing at CloudFormation deploy time.

Environment-agnostic stacks (Token.IsUnresolved) are skipped since the
region is not known at synth.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ncipollina ncipollina merged commit ad1f48f into main Apr 3, 2026
3 checks passed
@ncipollina ncipollina deleted the feat/cognito-user-pool-construct branch April 3, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant