From a31cc587fc7417161d07abbfae706aff2214d0d2 Mon Sep 17 00:00:00 2001 From: Kyle Cooley Date: Wed, 20 May 2020 10:33:34 -0700 Subject: [PATCH] feat(cognito): user pool - case sensitivity for sign in ### Commit Message feat(cognito): user pool - case sensitivity for sign in (#7988 fixes #7235 ### End Commit Message ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-cognito/README.md | 3 ++ .../@aws-cdk/aws-cognito/lib/user-pool.ts | 10 +++++++ .../aws-cognito/test/user-pool.test.ts | 30 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/packages/@aws-cdk/aws-cognito/README.md b/packages/@aws-cdk/aws-cognito/README.md index 9886fdbbd2442..192fd76826e64 100644 --- a/packages/@aws-cdk/aws-cognito/README.md +++ b/packages/@aws-cdk/aws-cognito/README.md @@ -148,6 +148,9 @@ new UserPool(this, 'myuserpool', { }); ``` +A user pool can optionally ignore case when evaluating sign-ins. When `signInCaseSensitive` is false, Cognito will not +check the capitalization of the alias when signing in. Default is true. + ### Attributes Attributes represent the various properties of each user that's collected and stored in the user pool. Cognito diff --git a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts index 38b89abf288d5..24fef0a42db70 100644 --- a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts +++ b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts @@ -500,6 +500,13 @@ export interface UserPoolProps { * @default - No Lambda triggers. */ readonly lambdaTriggers?: UserPoolTriggers; + + /** + * Whether sign-in aliases should be evaluated with case sensitivity. + * For example, when this option is set to false, users will be able to sign in using either `MyUsername` or `myusername`. + * @default true + */ + readonly signInCaseSensitive?: boolean; } /** @@ -637,6 +644,9 @@ export class UserPool extends Resource implements IUserPool { from: props.emailSettings?.from, replyToEmailAddress: props.emailSettings?.replyTo, }), + usernameConfiguration: undefinedIfNoKeys({ + caseSensitive: props.signInCaseSensitive, + }), }); this.userPoolId = userPool.ref; diff --git a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts index 449aa27403acb..e076d9e79bd2f 100644 --- a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts +++ b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts @@ -454,6 +454,36 @@ describe('User Pool', () => { }); }); + test('sign in case sensitive is correctly picked up', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new UserPool(stack, 'Pool', { + signInCaseSensitive: false, + }); + + // THEN + expect(stack).toHaveResourceLike('AWS::Cognito::UserPool', { + UsernameConfiguration: { + CaseSensitive: false, + }, + }); + }); + + test('sign in case sensitive is absent by default', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new UserPool(stack, 'Pool', {}); + + // THEN + expect(stack).toHaveResourceLike('AWS::Cognito::UserPool', { + UsernameConfiguration: ABSENT, + }); + }); + test('required attributes', () => { // GIVEN const stack = new Stack();