Skip to content

Commit

Permalink
feat(cognito): user pool - case sensitivity for sign in
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
kyle-kc authored May 20, 2020
1 parent 383cdb8 commit 460394f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cognito/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-cognito/lib/user-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions packages/@aws-cdk/aws-cognito/test/user-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 460394f

Please sign in to comment.