From 188f52d5750274b86c5ebc6ce55ec7cdbc6fc8a7 Mon Sep 17 00:00:00 2001 From: Kazuho Cryer-Shinozuka Date: Sat, 25 Jan 2025 05:28:26 +0900 Subject: [PATCH] feat(cognito): managed login (#33097) ### Issue # (if applicable) None ### Reason for this change Cognito supports for the managed login for the user pool domain. https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-managed-login.html However, this feature is not supported by UserPoolDomain L2 construct. ### Description of changes - add `ManagedLoginVersion` enum - add `managedLoginVersion` prop to `UserpoolDomainOptions` ### Describe any new or updated permissions being added None ### Description of how you validated changes Add both unit and integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...efaultTestDeployAssertE3E7D2A4.assets.json | 19 ++ ...aultTestDeployAssertE3E7D2A4.template.json | 36 ++++ .../cdk.out | 1 + ...user-pool-domain-managed-login.assets.json | 19 ++ ...er-pool-domain-managed-login.template.json | 86 ++++++++ .../integ.json | 12 ++ .../manifest.json | 125 ++++++++++++ .../tree.json | 184 ++++++++++++++++++ .../integ.user-pool-domain-managed-login.ts | 23 +++ packages/aws-cdk-lib/aws-cognito/README.md | 23 +++ .../aws-cognito/lib/user-pool-domain.ts | 25 +++ .../aws-cognito/test/user-pool-domain.test.ts | 20 +- 12 files changed, 572 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json new file mode 100644 index 0000000000000..7fc0c7c6c51ec --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "IntegTestDefaultTestDeployAssertE3E7D2A4.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/IntegTestDefaultTestDeployAssertE3E7D2A4.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/cdk.out new file mode 100644 index 0000000000000..91e1a8b9901d5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"39.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.assets.json new file mode 100644 index 0000000000000..a252f06839d69 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.assets.json @@ -0,0 +1,19 @@ +{ + "version": "39.0.0", + "files": { + "a949af857f57caf7e908b76e4322ea64082ba113b8f980715c490ddb6ca25d4a": { + "source": { + "path": "integ-user-pool-domain-managed-login.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "a949af857f57caf7e908b76e4322ea64082ba113b8f980715c490ddb6ca25d4a.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.template.json new file mode 100644 index 0000000000000..e18ac948df6ea --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ-user-pool-domain-managed-login.template.json @@ -0,0 +1,86 @@ +{ + "Resources": { + "UserPool6BA7E5F2": { + "Type": "AWS::Cognito::UserPool", + "Properties": { + "AccountRecoverySetting": { + "RecoveryMechanisms": [ + { + "Name": "verified_phone_number", + "Priority": 1 + }, + { + "Name": "verified_email", + "Priority": 2 + } + ] + }, + "AdminCreateUserConfig": { + "AllowAdminCreateUserOnly": true + }, + "EmailVerificationMessage": "The verification code to your new account is {####}", + "EmailVerificationSubject": "Verify your new account", + "SmsVerificationMessage": "The verification code to your new account is {####}", + "VerificationMessageTemplate": { + "DefaultEmailOption": "CONFIRM_WITH_CODE", + "EmailMessage": "The verification code to your new account is {####}", + "EmailSubject": "Verify your new account", + "SmsMessage": "The verification code to your new account is {####}" + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "UserPoolDomainD0EA232A": { + "Type": "AWS::Cognito::UserPoolDomain", + "Properties": { + "Domain": "naonao-user-pool-domain", + "ManagedLoginVersion": 2, + "UserPoolId": { + "Ref": "UserPool6BA7E5F2" + } + } + } + }, + "Outputs": { + "Domain": { + "Value": { + "Ref": "UserPoolDomainD0EA232A" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ.json new file mode 100644 index 0000000000000..c9c2915d379a7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "39.0.0", + "testCases": { + "IntegTest/DefaultTest": { + "stacks": [ + "integ-user-pool-domain-managed-login" + ], + "assertionStack": "IntegTest/DefaultTest/DeployAssert", + "assertionStackName": "IntegTestDefaultTestDeployAssertE3E7D2A4" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/manifest.json new file mode 100644 index 0000000000000..c70a618739c1c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/manifest.json @@ -0,0 +1,125 @@ +{ + "version": "39.0.0", + "artifacts": { + "integ-user-pool-domain-managed-login.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integ-user-pool-domain-managed-login.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integ-user-pool-domain-managed-login": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "integ-user-pool-domain-managed-login.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/a949af857f57caf7e908b76e4322ea64082ba113b8f980715c490ddb6ca25d4a.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integ-user-pool-domain-managed-login.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "integ-user-pool-domain-managed-login.assets" + ], + "metadata": { + "/integ-user-pool-domain-managed-login/UserPool/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "UserPool6BA7E5F2" + } + ], + "/integ-user-pool-domain-managed-login/UserPool/Domain/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "UserPoolDomainD0EA232A" + } + ], + "/integ-user-pool-domain-managed-login/Domain": [ + { + "type": "aws:cdk:logicalId", + "data": "Domain" + } + ], + "/integ-user-pool-domain-managed-login/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-user-pool-domain-managed-login/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-user-pool-domain-managed-login" + }, + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "IntegTestDefaultTestDeployAssertE3E7D2A4.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "IntegTestDefaultTestDeployAssertE3E7D2A4": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "IntegTestDefaultTestDeployAssertE3E7D2A4.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "IntegTestDefaultTestDeployAssertE3E7D2A4.assets" + ], + "metadata": { + "/IntegTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/IntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "IntegTest/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/tree.json new file mode 100644 index 0000000000000..12a75904dbf50 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.js.snapshot/tree.json @@ -0,0 +1,184 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "integ-user-pool-domain-managed-login": { + "id": "integ-user-pool-domain-managed-login", + "path": "integ-user-pool-domain-managed-login", + "children": { + "UserPool": { + "id": "UserPool", + "path": "integ-user-pool-domain-managed-login/UserPool", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-user-pool-domain-managed-login/UserPool/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Cognito::UserPool", + "aws:cdk:cloudformation:props": { + "accountRecoverySetting": { + "recoveryMechanisms": [ + { + "name": "verified_phone_number", + "priority": 1 + }, + { + "name": "verified_email", + "priority": 2 + } + ] + }, + "adminCreateUserConfig": { + "allowAdminCreateUserOnly": true + }, + "emailVerificationMessage": "The verification code to your new account is {####}", + "emailVerificationSubject": "Verify your new account", + "smsVerificationMessage": "The verification code to your new account is {####}", + "verificationMessageTemplate": { + "defaultEmailOption": "CONFIRM_WITH_CODE", + "emailMessage": "The verification code to your new account is {####}", + "emailSubject": "Verify your new account", + "smsMessage": "The verification code to your new account is {####}" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cognito.CfnUserPool", + "version": "0.0.0" + } + }, + "Domain": { + "id": "Domain", + "path": "integ-user-pool-domain-managed-login/UserPool/Domain", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-user-pool-domain-managed-login/UserPool/Domain/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Cognito::UserPoolDomain", + "aws:cdk:cloudformation:props": { + "domain": "naonao-user-pool-domain", + "managedLoginVersion": 2, + "userPoolId": { + "Ref": "UserPool6BA7E5F2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cognito.CfnUserPoolDomain", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cognito.UserPoolDomain", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cognito.UserPool", + "version": "0.0.0" + } + }, + "Domain": { + "id": "Domain", + "path": "integ-user-pool-domain-managed-login/Domain", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnOutput", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-user-pool-domain-managed-login/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-user-pool-domain-managed-login/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "IntegTest": { + "id": "IntegTest", + "path": "IntegTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "IntegTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "IntegTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "IntegTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "IntegTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "IntegTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.4.2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.ts new file mode 100644 index 0000000000000..c1d1305920ffb --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-domain-managed-login.ts @@ -0,0 +1,23 @@ +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { App, CfnOutput, RemovalPolicy, Stack } from 'aws-cdk-lib'; +import * as cognito from 'aws-cdk-lib/aws-cognito'; + +const app = new App(); +const stack = new Stack(app, 'integ-user-pool-domain-managed-login'); + +const userpool = new cognito.UserPool(stack, 'UserPool', { + removalPolicy: RemovalPolicy.DESTROY, +}); + +const domain = userpool.addDomain('Domain', { + cognitoDomain: { + domainPrefix: 'naonao-user-pool-domain', + }, + managedLoginVersion: cognito.ManagedLoginVersion.NEWER_MANAGED_LOGIN, +}); + +new CfnOutput(stack, 'Domain', { + value: domain.domainName, +}); + +new IntegTest(app, 'IntegTest', { testCases: [stack] }); diff --git a/packages/aws-cdk-lib/aws-cognito/README.md b/packages/aws-cdk-lib/aws-cognito/README.md index 5aa67692d292c..0b6c504adc79f 100644 --- a/packages/aws-cdk-lib/aws-cognito/README.md +++ b/packages/aws-cdk-lib/aws-cognito/README.md @@ -981,6 +981,29 @@ Read more about [Using the Amazon Cognito Domain](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-assign-domain-prefix.html) and [Using Your Own Domain](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain.html). + +You can use the [managed login](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-managed-login.html) page provided by Amazon Cognito to sign in users. The managed login page has two versions: a classic version and a new version. You can switch between the two versions by using the `managedLoginVersion` property. + +```ts +const pool = new cognito.UserPool(this, 'Pool'); + +// Use the new managed login page +pool.addDomain('CognitoDomainWithBlandingDesignManagedLogin', { + cognitoDomain: { + domainPrefix: 'blanding-design-ui', + }, + managedLoginVersion: cognito.ManagedLoginVersion.NEWER_MANAGED_LOGIN, +}); + +// Use the classic hosted UI +pool.addDomain('DomainWithClassicHostedUi', { + cognitoDomain: { + domainPrefix: 'classic-hosted-ui', + }, + managedLoginVersion: cognito.ManagedLoginVersion.CLASSIC_HOSTED_UI, +}); +``` + The `signInUrl()` methods returns the fully qualified URL to the login page for the user pool. This page comes from the hosted UI configured with Cognito. Learn more at [Hosted UI with the Amazon Cognito Console](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-app-integration.html#cognito-user-pools-create-an-app-integration). diff --git a/packages/aws-cdk-lib/aws-cognito/lib/user-pool-domain.ts b/packages/aws-cdk-lib/aws-cognito/lib/user-pool-domain.ts index 889ee5782b258..229de8d624918 100644 --- a/packages/aws-cdk-lib/aws-cognito/lib/user-pool-domain.ts +++ b/packages/aws-cdk-lib/aws-cognito/lib/user-pool-domain.ts @@ -6,6 +6,20 @@ import { ICertificate } from '../../aws-certificatemanager'; import { IResource, Resource, Stack, Token } from '../../core'; import { AwsCustomResource, AwsCustomResourcePolicy, AwsSdkCall, PhysicalResourceId } from '../../custom-resources'; +/** + * The branding version of managed login for the domain. + */ +export enum ManagedLoginVersion { + /** + * The classic hosted UI. + */ + CLASSIC_HOSTED_UI = 1, + /** + * The newer managed login with the branding designer. + */ + NEWER_MANAGED_LOGIN = 2, +} + /** * Represents a user pool domain. */ @@ -65,6 +79,16 @@ export interface UserPoolDomainOptions { * @default - not set if `customDomain` is specified, otherwise, throws an error. */ readonly cognitoDomain?: CognitoDomainOptions; + + /** + * A version that indicates the state of managed login. + * This choice applies to all app clients that host services at the domain. + * + * @see https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-managed-login.html + * + * @default undefined - Cognito default setting is ManagedLoginVersion.CLASSIC_HOSTED_UI + */ + readonly managedLoginVersion?: ManagedLoginVersion; } /** @@ -119,6 +143,7 @@ export class UserPoolDomain extends Resource implements IUserPoolDomain { userPoolId: props.userPool.userPoolId, domain: domainName, customDomainConfig: props.customDomain ? { certificateArn: props.customDomain.certificate.certificateArn } : undefined, + managedLoginVersion: props.managedLoginVersion, }); this.domainName = this.resource.ref; diff --git a/packages/aws-cdk-lib/aws-cognito/test/user-pool-domain.test.ts b/packages/aws-cdk-lib/aws-cognito/test/user-pool-domain.test.ts index ef7514ebd178f..74457cd41bdc7 100644 --- a/packages/aws-cdk-lib/aws-cognito/test/user-pool-domain.test.ts +++ b/packages/aws-cdk-lib/aws-cognito/test/user-pool-domain.test.ts @@ -2,7 +2,7 @@ import { testDeprecated } from '@aws-cdk/cdk-build-tools'; import { Template } from '../../assertions'; import { Certificate } from '../../aws-certificatemanager'; import { CfnParameter, Stack } from '../../core'; -import { UserPool, UserPoolDomain } from '../lib'; +import { ManagedLoginVersion, UserPool, UserPoolDomain } from '../lib'; describe('User Pool Domain', () => { test('custom domain name', () => { @@ -304,4 +304,22 @@ describe('User Pool Domain', () => { expect(signInUrl).toMatch(/amazoncognito\.com\/testsignin\?/); }); }); + + test.each([ + ManagedLoginVersion.CLASSIC_HOSTED_UI, + ManagedLoginVersion.NEWER_MANAGED_LOGIN, + ])('managed login version %s', (managedLoginVersion) => { + const stack = new Stack(); + const pool = new UserPool(stack, 'Pool'); + pool.addDomain('Domain', { + cognitoDomain: { + domainPrefix: 'cognito-domain-prefix', + }, + managedLoginVersion, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPoolDomain', { + ManagedLoginVersion: managedLoginVersion, + }); + }); });