Skip to content

Instantly share code, notes, and snippets.

@cal0610
Last active November 2, 2022 15:13
Show Gist options
  • Save cal0610/8a3596fe42e48a5a1948ceebff973bab to your computer and use it in GitHub Desktop.
Save cal0610/8a3596fe42e48a5a1948ceebff973bab to your computer and use it in GitHub Desktop.
creating cognito user pool, app client, and user
const userPool = new cognito.UserPool(this, 'medium-userpool', {
userPoolName: 'medium-userpool',
});
userPool.addClient('medium-client-1', {
oAuth: {
flows: {
authorizationCodeGrant: true,
},
callbackUrls: ['https://www.google.com.au/'],
},
userPoolClientName: 'medium-client-1',
generateSecret: false,
authFlows: {
userPassword: true,
userSrp: true,
},
enableTokenRevocation: true,
preventUserExistenceErrors: true,
idTokenValidity: Duration.hours(1),
accessTokenValidity: Duration.hours(1),
refreshTokenValidity: Duration.days(30),
});
userPool.addDomain('CognitoDomain', {
cognitoDomain: {
domainPrefix: 'my-medium-example',
},
});
const cognitoUserPoolsAuthorizer = new apigateway.CognitoUserPoolsAuthorizer(this, 'medium-cognito-authoriser', {
cognitoUserPools: [userPool],
});
const authorizer = {
authorizer: cognitoUserPoolsAuthorizer,
authorizationType: apigateway.AuthorizationType.COGNITO,
};
new cognito.CfnUserPoolUser(this, 'medium-admin-user', {
userPoolId: userPool.userPoolId,
forceAliasCreation: false,
userAttributes: [
{
name: 'email',
value: '[email protected]',
},
],
username: 'medium-admin-user',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment