Skip to content

Commit c5bcfdc

Browse files
danielholmesGavinZZmergify[bot]
authored
feat(cognito): support for ALLOW_USER_AUTH explicit auth flow (#32273)
### Reason for this change Cognito [released some new auth flow features](https://aws.amazon.com/blogs/aws/improve-your-app-authentication-workflow-with-new-amazon-cognito-features/) which have [made their way into cloudformation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolclient.html#cfn-cognito-userpoolclient-explicitauthflows). I want to be able to use the new `USER_AUTH` sign in on a `UserPoolClient`. ### Description of changes I've added a `user` option to the `AuthFlow` struct for `UserPoolClient`. This naming matches the naming convention for the other settings in `AuthFlow` so while `user` is a very generic label, I think it makes sense in the context of this `AuthFlow` struct. i.e. the current properties are: ``` adminUserPassword -> ADMIN_USER_PASSWORD_AUTH custom -> CUSTOM_AUTH userPassword -> USER_PASSWORD_AUTH userSrp -> USER_SRP_AUTH ``` This property then sets the `"ALLOW_USER_AUTH"` value in the `ExplicitAuthFlows` of the `UserPoolClient`. ### Description of how you validated changes I added the setting to both the unit and integration tests which have all auth types enabled. ### 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* Co-authored-by: GZ <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 935c06f commit c5bcfdc

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-client-explicit-props.js.snapshot/integ-user-pool-client-explicit-props.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"ALLOW_ADMIN_USER_PASSWORD_AUTH",
6767
"ALLOW_CUSTOM_AUTH",
6868
"ALLOW_USER_SRP_AUTH",
69+
"ALLOW_USER_AUTH",
6970
"ALLOW_REFRESH_TOKEN_AUTH"
7071
],
7172
"GenerateSecret": true,

packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-client-explicit-props.js.snapshot/tree.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cognito/test/integ.user-pool-client-explicit-props.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const client = userpool.addClient('myuserpoolclient', {
2020
custom: true,
2121
userPassword: true,
2222
userSrp: true,
23+
user: true,
2324
},
2425
generateSecret: true,
2526
oAuth: {

packages/aws-cdk-lib/aws-cognito/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ Custom authentication protocols can be configured by setting the `custom` proper
699699
functions for the corresponding user pool [triggers](#lambda-triggers). Learn more at [Custom Authentication
700700
Flow](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#amazon-cognito-user-pools-custom-authentication-flow).
701701

702+
Choice-based authentication can be configured by setting the `user` property under `authFlow`. This enables the
703+
`USER_AUTH` authentication flow. Learn more at [Choice-based authentication](https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flows-selection-sdk.html#authentication-flows-selection-choice).
704+
702705
In addition to these authentication mechanisms, Cognito user pools also support using OAuth 2.0 framework for
703706
authenticating users. User pool clients can be configured with OAuth 2.0 authorization flows and scopes. Learn more
704707
about the [OAuth 2.0 authorization framework](https://tools.ietf.org/html/rfc6749) and [Cognito user pool's

packages/aws-cdk-lib/aws-cognito/lib/user-pool-client.ts

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export interface AuthFlow {
3434
* @default false
3535
*/
3636
readonly userSrp?: boolean;
37+
38+
/**
39+
* Enable Choice-based authentication
40+
* @default false
41+
*/
42+
readonly user?: boolean;
3743
}
3844

3945
/**
@@ -525,6 +531,7 @@ export class UserPoolClient extends Resource implements IUserPoolClient {
525531
if (props.authFlows.adminUserPassword) { authFlows.push('ALLOW_ADMIN_USER_PASSWORD_AUTH'); }
526532
if (props.authFlows.custom) { authFlows.push('ALLOW_CUSTOM_AUTH'); }
527533
if (props.authFlows.userSrp) { authFlows.push('ALLOW_USER_SRP_AUTH'); }
534+
if (props.authFlows.user) { authFlows.push('ALLOW_USER_AUTH'); }
528535

529536
// refreshToken should always be allowed if authFlows are present
530537
authFlows.push('ALLOW_REFRESH_TOKEN_AUTH');

packages/aws-cdk-lib/aws-cognito/test/user-pool-client.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ describe('User Pool Client', () => {
255255
custom: true,
256256
userPassword: true,
257257
userSrp: true,
258+
user: true,
258259
},
259260
});
260261

@@ -264,6 +265,7 @@ describe('User Pool Client', () => {
264265
'ALLOW_ADMIN_USER_PASSWORD_AUTH',
265266
'ALLOW_CUSTOM_AUTH',
266267
'ALLOW_USER_SRP_AUTH',
268+
'ALLOW_USER_AUTH',
267269
'ALLOW_REFRESH_TOKEN_AUTH',
268270
],
269271
});
@@ -281,6 +283,7 @@ describe('User Pool Client', () => {
281283
custom: false,
282284
userPassword: false,
283285
userSrp: false,
286+
user: false,
284287
},
285288
});
286289

0 commit comments

Comments
 (0)