Skip to content

Commit

Permalink
feat(cognito): Implement user pool and user pool client constructs (#…
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
dotxlem authored and RomainMuller committed Feb 5, 2019
1 parent 93ae2d5 commit 8e03ed6
Show file tree
Hide file tree
Showing 7 changed files with 815 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cognito/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// AWS::Cognito CloudFormation Resources:
export * from './cognito.generated';

export * from './user-pool';
export * from './user-pool-client';
67 changes: 67 additions & 0 deletions packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import cdk = require('@aws-cdk/cdk');
import { CfnUserPoolClient } from './cognito.generated';
import { IUserPool } from './user-pool';

/**
* Types of authentication flow
*/
export enum AuthFlow {
/**
* Enable flow for server-side or admin authentication (no client app)
*/
AdminNoSrp = 'ADMIN_NO_SRP_AUTH',

/**
* Enable custom authentication flow
*/
CustomFlowOnly = 'CUSTOM_AUTH_FLOW_ONLY',

/**
* Enable auth using username & password
*/
UserPassword = 'USER_PASSWORD_AUTH'
}

export interface UserPoolClientProps {
/**
* Name of the application client
* @default cloudformation generated name
*/
clientName?: string;

/**
* The UserPool resource this client will have access to
*/
userPool: IUserPool;

/**
* Whether to generate a client secret
* @default false
*/
generateSecret?: boolean;

/**
* List of enabled authentication flows
* @default no enabled flows
*/
enabledAuthFlows?: AuthFlow[]
}

/**
* Define a UserPool App Client
*/
export class UserPoolClient extends cdk.Construct {
public readonly clientId: string;

constructor(scope: cdk.Construct, id: string, props: UserPoolClientProps) {
super(scope, id);

const userPoolClient = new CfnUserPoolClient(this, 'Resource', {
clientName: props.clientName,
generateSecret: props.generateSecret,
userPoolId: props.userPool.userPoolId,
explicitAuthFlows: props.enabledAuthFlows
});
this.clientId = userPoolClient.userPoolClientId;
}
}
Loading

0 comments on commit 8e03ed6

Please sign in to comment.