Skip to content

Commit 8e03ed6

Browse files
dotxlemRomainMuller
authored andcommitted
feat(cognito): Implement user pool and user pool client constructs (#1615)
This commit adds initial support for Cognito User Pools. `UserPool` allows selecting the type of sign-in (username vs email, etc) with options consistent with what is presented in the console. `UserPool` also supports setting alias attributes & auto-verified attributes, as well as setting Lambda function triggers. A basic implementation of app clients is implemented in `UserPoolClient`.
1 parent 93ae2d5 commit 8e03ed6

File tree

7 files changed

+815
-10
lines changed

7 files changed

+815
-10
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
// AWS::Cognito CloudFormation Resources:
22
export * from './cognito.generated';
3+
4+
export * from './user-pool';
5+
export * from './user-pool-client';
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import cdk = require('@aws-cdk/cdk');
2+
import { CfnUserPoolClient } from './cognito.generated';
3+
import { IUserPool } from './user-pool';
4+
5+
/**
6+
* Types of authentication flow
7+
*/
8+
export enum AuthFlow {
9+
/**
10+
* Enable flow for server-side or admin authentication (no client app)
11+
*/
12+
AdminNoSrp = 'ADMIN_NO_SRP_AUTH',
13+
14+
/**
15+
* Enable custom authentication flow
16+
*/
17+
CustomFlowOnly = 'CUSTOM_AUTH_FLOW_ONLY',
18+
19+
/**
20+
* Enable auth using username & password
21+
*/
22+
UserPassword = 'USER_PASSWORD_AUTH'
23+
}
24+
25+
export interface UserPoolClientProps {
26+
/**
27+
* Name of the application client
28+
* @default cloudformation generated name
29+
*/
30+
clientName?: string;
31+
32+
/**
33+
* The UserPool resource this client will have access to
34+
*/
35+
userPool: IUserPool;
36+
37+
/**
38+
* Whether to generate a client secret
39+
* @default false
40+
*/
41+
generateSecret?: boolean;
42+
43+
/**
44+
* List of enabled authentication flows
45+
* @default no enabled flows
46+
*/
47+
enabledAuthFlows?: AuthFlow[]
48+
}
49+
50+
/**
51+
* Define a UserPool App Client
52+
*/
53+
export class UserPoolClient extends cdk.Construct {
54+
public readonly clientId: string;
55+
56+
constructor(scope: cdk.Construct, id: string, props: UserPoolClientProps) {
57+
super(scope, id);
58+
59+
const userPoolClient = new CfnUserPoolClient(this, 'Resource', {
60+
clientName: props.clientName,
61+
generateSecret: props.generateSecret,
62+
userPoolId: props.userPool.userPoolId,
63+
explicitAuthFlows: props.enabledAuthFlows
64+
});
65+
this.clientId = userPoolClient.userPoolClientId;
66+
}
67+
}

0 commit comments

Comments
 (0)