@lafken/auth 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENCE +21 -0
- package/README.md +493 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/main/attribute/attribute.d.ts +86 -0
- package/lib/main/attribute/attribute.js +109 -0
- package/lib/main/attribute/attribute.types.d.ts +90 -0
- package/lib/main/attribute/attribute.types.js +13 -0
- package/lib/main/attribute/index.d.ts +2 -0
- package/lib/main/attribute/index.js +18 -0
- package/lib/main/event/event.d.ts +19 -0
- package/lib/main/event/event.js +26 -0
- package/lib/main/extension/extension.d.ts +60 -0
- package/lib/main/extension/extension.js +74 -0
- package/lib/main/extension/extension.types.d.ts +37 -0
- package/lib/main/extension/extension.types.js +2 -0
- package/lib/main/extension/index.d.ts +1 -0
- package/lib/main/extension/index.js +2 -0
- package/lib/main/index.d.ts +1 -0
- package/lib/main/index.js +17 -0
- package/lib/resolver/auth/auth.d.ts +11 -0
- package/lib/resolver/auth/auth.js +50 -0
- package/lib/resolver/auth/auth.utils.d.ts +2 -0
- package/lib/resolver/auth/auth.utils.js +23 -0
- package/lib/resolver/auth/user-pool/extension/extension.d.ts +8 -0
- package/lib/resolver/auth/user-pool/extension/extension.js +51 -0
- package/lib/resolver/auth/user-pool/extension/extension.types.d.ts +6 -0
- package/lib/resolver/auth/user-pool/extension/extension.types.js +2 -0
- package/lib/resolver/auth/user-pool/external/external.d.ts +14 -0
- package/lib/resolver/auth/user-pool/external/external.js +14 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.d.ts +13 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.js +120 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.types.d.ts +6 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.types.js +2 -0
- package/lib/resolver/auth/user-pool/internal/internal.d.ts +30 -0
- package/lib/resolver/auth/user-pool/internal/internal.js +332 -0
- package/lib/resolver/auth/user-pool/user-pool.types.d.ts +263 -0
- package/lib/resolver/auth/user-pool/user-pool.types.js +2 -0
- package/lib/resolver/auth/user-pool-client/external/external.d.ts +7 -0
- package/lib/resolver/auth/user-pool-client/external/external.js +16 -0
- package/lib/resolver/auth/user-pool-client/internal/internal.d.ts +14 -0
- package/lib/resolver/auth/user-pool-client/internal/internal.js +115 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.d.ts +169 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.js +2 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/resolver.d.ts +12 -0
- package/lib/resolver/resolver.js +25 -0
- package/lib/resolver/resolver.types.d.ts +62 -0
- package/lib/resolver/resolver.types.js +2 -0
- package/package.json +87 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExternalUserPool = void 0;
|
|
4
|
+
const data_aws_cognito_user_pool_1 = require("@cdktn/provider-aws/lib/data-aws-cognito-user-pool");
|
|
5
|
+
const resolver_1 = require("@lafken/resolver");
|
|
6
|
+
class ExternalUserPool extends resolver_1.lafkenResource.make(data_aws_cognito_user_pool_1.DataAwsCognitoUserPool) {
|
|
7
|
+
constructor(scope, id, props) {
|
|
8
|
+
super(scope, `${id}-user-pool`, {
|
|
9
|
+
userPoolId: props.userPoolId,
|
|
10
|
+
});
|
|
11
|
+
this.isGlobal('auth', id);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ExternalUserPool = ExternalUserPool;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import type { IdentityProviderProps } from './identity-provider.types';
|
|
3
|
+
export declare class IdentityProvider extends Construct {
|
|
4
|
+
private id;
|
|
5
|
+
private props;
|
|
6
|
+
constructor(scope: Construct, id: string, props: IdentityProviderProps);
|
|
7
|
+
private createGoogleProvider;
|
|
8
|
+
private createFacebookProvider;
|
|
9
|
+
private createAmazonProvider;
|
|
10
|
+
private createAppleProvider;
|
|
11
|
+
private createOidcProvider;
|
|
12
|
+
private getProviderAttributes;
|
|
13
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdentityProvider = void 0;
|
|
4
|
+
const cognito_identity_provider_1 = require("@cdktn/provider-aws/lib/cognito-identity-provider");
|
|
5
|
+
const constructs_1 = require("constructs");
|
|
6
|
+
const auth_utils_1 = require("../../auth.utils");
|
|
7
|
+
class IdentityProvider extends constructs_1.Construct {
|
|
8
|
+
id;
|
|
9
|
+
props;
|
|
10
|
+
constructor(scope, id, props) {
|
|
11
|
+
super(scope, id);
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.props = props;
|
|
14
|
+
switch (props.type) {
|
|
15
|
+
case 'google':
|
|
16
|
+
this.createGoogleProvider(props);
|
|
17
|
+
break;
|
|
18
|
+
case 'facebook':
|
|
19
|
+
this.createFacebookProvider(props);
|
|
20
|
+
break;
|
|
21
|
+
case 'amazon':
|
|
22
|
+
this.createAmazonProvider(props);
|
|
23
|
+
break;
|
|
24
|
+
case 'apple':
|
|
25
|
+
this.createAppleProvider(props);
|
|
26
|
+
break;
|
|
27
|
+
case 'oidc':
|
|
28
|
+
this.createOidcProvider(props);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
createGoogleProvider(props) {
|
|
33
|
+
new cognito_identity_provider_1.CognitoIdentityProvider(this, 'google-identity-provider', {
|
|
34
|
+
userPoolId: this.props.userPoolId,
|
|
35
|
+
providerName: `${this.id}-identity-provider`,
|
|
36
|
+
providerType: 'Google',
|
|
37
|
+
providerDetails: {
|
|
38
|
+
client_id: props.clientId,
|
|
39
|
+
client_secret: props.clientSecret,
|
|
40
|
+
authorize_scopes: props.scopes.join(' '),
|
|
41
|
+
},
|
|
42
|
+
attributeMapping: this.getProviderAttributes(props.attributes),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
createFacebookProvider(props) {
|
|
46
|
+
new cognito_identity_provider_1.CognitoIdentityProvider(this, 'facebook-identity-provider', {
|
|
47
|
+
userPoolId: this.props.userPoolId,
|
|
48
|
+
providerName: `${this.id}-identity-provider`,
|
|
49
|
+
providerType: 'Facebook',
|
|
50
|
+
providerDetails: {
|
|
51
|
+
client_id: props.clientId,
|
|
52
|
+
client_secret: props.clientSecret,
|
|
53
|
+
authorize_scopes: props.scopes.join(','),
|
|
54
|
+
...(props.apiVersion ? { api_version: props.apiVersion } : {}),
|
|
55
|
+
},
|
|
56
|
+
attributeMapping: this.getProviderAttributes(props.attributes),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
createAmazonProvider(props) {
|
|
60
|
+
new cognito_identity_provider_1.CognitoIdentityProvider(this, 'amazon-identity-provider', {
|
|
61
|
+
userPoolId: this.props.userPoolId,
|
|
62
|
+
providerName: `${this.id}-identity-provider`,
|
|
63
|
+
providerType: 'LoginWithAmazon',
|
|
64
|
+
providerDetails: {
|
|
65
|
+
client_id: props.clientId,
|
|
66
|
+
client_secret: props.clientSecret,
|
|
67
|
+
authorize_scopes: props.scopes.join(' '),
|
|
68
|
+
},
|
|
69
|
+
attributeMapping: this.getProviderAttributes(props.attributes),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
createAppleProvider(props) {
|
|
73
|
+
new cognito_identity_provider_1.CognitoIdentityProvider(this, 'apple-identity-provider', {
|
|
74
|
+
userPoolId: this.props.userPoolId,
|
|
75
|
+
providerName: `${this.id}-identity-provider`,
|
|
76
|
+
providerType: 'SignInWithApple',
|
|
77
|
+
providerDetails: {
|
|
78
|
+
client_id: props.clientId,
|
|
79
|
+
team_id: props.teamId,
|
|
80
|
+
key_id: props.keyId,
|
|
81
|
+
private_key: props.privateKeyValue,
|
|
82
|
+
authorize_scopes: props.scopes.join(' '),
|
|
83
|
+
},
|
|
84
|
+
attributeMapping: this.getProviderAttributes(props.attributes),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
createOidcProvider(props) {
|
|
88
|
+
new cognito_identity_provider_1.CognitoIdentityProvider(this, 'oidc-identity-provider', {
|
|
89
|
+
userPoolId: this.props.userPoolId,
|
|
90
|
+
providerName: `${this.id}-identity-provider`,
|
|
91
|
+
providerType: 'OIDC',
|
|
92
|
+
providerDetails: {
|
|
93
|
+
client_id: props.clientId,
|
|
94
|
+
client_secret: props.clientSecret,
|
|
95
|
+
authorize_scopes: props.scopes.join(' '),
|
|
96
|
+
attributes_request_method: props.attributesRequestMethod,
|
|
97
|
+
authorize_url: props.authorizeUrl,
|
|
98
|
+
token_url: props.tokenUrl,
|
|
99
|
+
attributes_url: props.attributesUrl,
|
|
100
|
+
jwks_uri: props.jwksUri,
|
|
101
|
+
},
|
|
102
|
+
attributeMapping: this.getProviderAttributes(props.attributes),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
getProviderAttributes(providerAttributes) {
|
|
106
|
+
const attributes = {};
|
|
107
|
+
for (const providerAttribute in providerAttributes) {
|
|
108
|
+
const attribute = this.props.attributeByName[providerAttribute];
|
|
109
|
+
if (!attribute) {
|
|
110
|
+
throw new Error(`Attribute ${providerAttribute} not exist in attribute class`);
|
|
111
|
+
}
|
|
112
|
+
const attributeName = attribute.attributeType === 'standard'
|
|
113
|
+
? auth_utils_1.mapUserAttributes[attribute.name]
|
|
114
|
+
: `custom:${attribute.name}`;
|
|
115
|
+
attributes[attributeName] = providerAttributes[providerAttribute];
|
|
116
|
+
}
|
|
117
|
+
return attributes;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.IdentityProvider = IdentityProvider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CustomAttributesMetadata, StandardAttributeMetadata } from '../../../../main';
|
|
2
|
+
import type { IdentityProvider } from '../user-pool.types';
|
|
3
|
+
export type IdentityProviderProps = IdentityProvider<any> & {
|
|
4
|
+
userPoolId: string;
|
|
5
|
+
attributeByName: Record<string, CustomAttributesMetadata | StandardAttributeMetadata>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CognitoUserPool } from '@cdktn/provider-aws/lib/cognito-user-pool';
|
|
2
|
+
import type { Construct } from 'constructs';
|
|
3
|
+
import { type CustomAttributesMetadata, type StandardAttributeMetadata } from '../../../../main';
|
|
4
|
+
import type { InternalUserPoolProps } from '../user-pool.types';
|
|
5
|
+
declare const InternalUserPool_base: (new (...args: any[]) => {
|
|
6
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
7
|
+
isDependent(resolveDependency: () => void): void;
|
|
8
|
+
readonly node: import("constructs").Node;
|
|
9
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
10
|
+
toString(): string;
|
|
11
|
+
}) & typeof CognitoUserPool;
|
|
12
|
+
export declare class InternalUserPool extends InternalUserPool_base {
|
|
13
|
+
attributeByName: Record<string, CustomAttributesMetadata | StandardAttributeMetadata>;
|
|
14
|
+
constructor(scope: Construct, id: string, props: InternalUserPoolProps<any>);
|
|
15
|
+
private assignIdentityProviders;
|
|
16
|
+
private addLambdaConfig;
|
|
17
|
+
private static getSmsConfig;
|
|
18
|
+
private static getMfaConfig;
|
|
19
|
+
private static getUserAttributes;
|
|
20
|
+
private static getUserVerification;
|
|
21
|
+
private static getSignInCaseSensitive;
|
|
22
|
+
private static getCognitoPlan;
|
|
23
|
+
private static getEmailConfig;
|
|
24
|
+
private static getAutoVerifiedAttributes;
|
|
25
|
+
private static getPasswordPolicy;
|
|
26
|
+
private static getAdminCreateUserConfig;
|
|
27
|
+
private static getAccountRecoverySettings;
|
|
28
|
+
private static getAliasAttributes;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalUserPool = void 0;
|
|
4
|
+
const cognito_user_pool_1 = require("@cdktn/provider-aws/lib/cognito-user-pool");
|
|
5
|
+
const iam_role_1 = require("@cdktn/provider-aws/lib/iam-role");
|
|
6
|
+
const iam_role_policy_1 = require("@cdktn/provider-aws/lib/iam-role-policy");
|
|
7
|
+
const common_1 = require("@lafken/common");
|
|
8
|
+
const resolver_1 = require("@lafken/resolver");
|
|
9
|
+
const cdktn_1 = require("cdktn");
|
|
10
|
+
const main_1 = require("../../../../main");
|
|
11
|
+
const extension_1 = require("../../../../main/extension/extension");
|
|
12
|
+
const auth_utils_1 = require("../../auth.utils");
|
|
13
|
+
const extension_2 = require("../extension/extension");
|
|
14
|
+
const identity_provider_1 = require("../identity-provider/identity-provider");
|
|
15
|
+
class InternalUserPool extends resolver_1.lafkenResource.make(cognito_user_pool_1.CognitoUserPool) {
|
|
16
|
+
attributeByName = {};
|
|
17
|
+
constructor(scope, id, props) {
|
|
18
|
+
const attributes = InternalUserPool.getUserAttributes(props.attributes);
|
|
19
|
+
super(scope, `${id}-user-pool`, {
|
|
20
|
+
...InternalUserPool.getMfaConfig(props.mfa),
|
|
21
|
+
name: id,
|
|
22
|
+
autoVerifiedAttributes: InternalUserPool.getAutoVerifiedAttributes(props.autoVerifyAttributes),
|
|
23
|
+
accountRecoverySetting: InternalUserPool.getAccountRecoverySettings(props.accountRecovery),
|
|
24
|
+
aliasAttributes: InternalUserPool.getAliasAttributes(props.signInAliases),
|
|
25
|
+
adminCreateUserConfig: InternalUserPool.getAdminCreateUserConfig(props.selfSignUpEnabled, props.invitationMessage),
|
|
26
|
+
passwordPolicy: InternalUserPool.getPasswordPolicy(props.passwordPolicy),
|
|
27
|
+
emailConfiguration: InternalUserPool.getEmailConfig(props.email),
|
|
28
|
+
userPoolTier: InternalUserPool.getCognitoPlan(props.cognitoPlan),
|
|
29
|
+
usernameConfiguration: InternalUserPool.getSignInCaseSensitive(props.signInCaseSensitive),
|
|
30
|
+
verificationMessageTemplate: InternalUserPool.getUserVerification(props.userVerification),
|
|
31
|
+
schema: attributes?.schema,
|
|
32
|
+
smsConfiguration: InternalUserPool.getSmsConfig(scope, id, props.mfa, props.userVerification),
|
|
33
|
+
usernameAttributes: InternalUserPool.getAliasAttributes(props.usernameAttributes),
|
|
34
|
+
lifecycle: {
|
|
35
|
+
ignoreChanges: ['schema'],
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
this.addLambdaConfig();
|
|
39
|
+
if (attributes?.attributeByName) {
|
|
40
|
+
this.attributeByName = attributes.attributeByName;
|
|
41
|
+
}
|
|
42
|
+
this.isGlobal('auth', id);
|
|
43
|
+
this.assignIdentityProviders(props.identityProviders);
|
|
44
|
+
new resolver_1.ResourceOutput(this, props.outputs);
|
|
45
|
+
}
|
|
46
|
+
assignIdentityProviders(identityProviders) {
|
|
47
|
+
if (identityProviders?.length) {
|
|
48
|
+
for (const identityProvider of identityProviders) {
|
|
49
|
+
new identity_provider_1.IdentityProvider(this, identityProvider.type, {
|
|
50
|
+
...identityProvider,
|
|
51
|
+
attributeByName: this.attributeByName,
|
|
52
|
+
userPoolId: this.id,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
addLambdaConfig(extensions = []) {
|
|
58
|
+
let lambdaConfig = {};
|
|
59
|
+
for (const extension of extensions) {
|
|
60
|
+
const metadata = (0, common_1.getResourceMetadata)(extension);
|
|
61
|
+
if (metadata.type !== extension_1.RESOURCE_TYPE) {
|
|
62
|
+
throw new Error(`extension should have @AuthExtension decorator`);
|
|
63
|
+
}
|
|
64
|
+
const handlers = (0, common_1.getResourceHandlerMetadata)(extension);
|
|
65
|
+
const trigger = new extension_2.Extension(this, `${metadata.name}-extension`, {
|
|
66
|
+
handlers,
|
|
67
|
+
resourceMetadata: metadata,
|
|
68
|
+
});
|
|
69
|
+
const triggers = trigger.createTriggers(this.arn);
|
|
70
|
+
for (const key in triggers) {
|
|
71
|
+
const configKey = key;
|
|
72
|
+
if (lambdaConfig[configKey] !== undefined) {
|
|
73
|
+
throw new Error(`trigger ${key} already exist`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
lambdaConfig = {
|
|
77
|
+
...lambdaConfig,
|
|
78
|
+
...triggers,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (Object.keys(lambdaConfig).length === 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.putLambdaConfig(lambdaConfig);
|
|
85
|
+
}
|
|
86
|
+
static getSmsConfig(scope, id, mfa, userVerification) {
|
|
87
|
+
if ((!mfa || mfa.status === 'off' || !mfa.sms) && !userVerification) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const externalId = `${id}-sms-config`;
|
|
91
|
+
const roleId = `${id}-cognito-sms-role`;
|
|
92
|
+
const snsRole = new iam_role_1.IamRole(scope, roleId, {
|
|
93
|
+
name: roleId,
|
|
94
|
+
assumeRolePolicy: JSON.stringify({
|
|
95
|
+
Version: '2012-10-17',
|
|
96
|
+
Statement: [
|
|
97
|
+
{
|
|
98
|
+
Effect: 'Allow',
|
|
99
|
+
Principal: { Service: 'cognito-idp.amazonaws.com' },
|
|
100
|
+
Action: 'sts:AssumeRole',
|
|
101
|
+
Condition: {
|
|
102
|
+
StringEquals: {
|
|
103
|
+
'sts:ExternalId': externalId,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
new iam_role_policy_1.IamRolePolicy(scope, `${roleId}-policy`, {
|
|
111
|
+
name: 'AllowSnsPublish',
|
|
112
|
+
role: snsRole.name,
|
|
113
|
+
policy: JSON.stringify({
|
|
114
|
+
Version: '2012-10-17',
|
|
115
|
+
Statement: [
|
|
116
|
+
{
|
|
117
|
+
Effect: 'Allow',
|
|
118
|
+
Action: ['sns:Publish'],
|
|
119
|
+
Resource: '*',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
externalId,
|
|
126
|
+
snsCallerArn: snsRole.arn,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
static getMfaConfig(mfa) {
|
|
130
|
+
if (!mfa || mfa.status === 'off') {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const config = {
|
|
134
|
+
mfaConfiguration: mfa.status === 'optional' ? 'OPTIONAL' : 'ON',
|
|
135
|
+
};
|
|
136
|
+
if (mfa.sms) {
|
|
137
|
+
config.smsAuthenticationMessage = mfa.sms;
|
|
138
|
+
}
|
|
139
|
+
if (mfa.email) {
|
|
140
|
+
config.emailMfaConfiguration = {
|
|
141
|
+
message: mfa.email.body,
|
|
142
|
+
subject: mfa.email.subject,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (mfa.opt) {
|
|
146
|
+
config.softwareTokenMfaConfiguration = {
|
|
147
|
+
enabled: mfa.opt,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return config;
|
|
151
|
+
}
|
|
152
|
+
static getUserAttributes(attributeClass) {
|
|
153
|
+
if (!attributeClass) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const attributeByName = {};
|
|
157
|
+
const schema = [];
|
|
158
|
+
const attributeMetadata = (0, common_1.getMetadataPrototypeByKey)(attributeClass, main_1.authFieldKey);
|
|
159
|
+
for (const attribute of attributeMetadata) {
|
|
160
|
+
attributeByName[attribute.name] = attribute;
|
|
161
|
+
if (attribute.attributeType === 'standard') {
|
|
162
|
+
const attributeName = auth_utils_1.mapUserAttributes[attribute.name];
|
|
163
|
+
if (!attributeName) {
|
|
164
|
+
throw new Error(`${attribute.name} is not a standard cognito attribute`);
|
|
165
|
+
}
|
|
166
|
+
schema.push({
|
|
167
|
+
attributeDataType: attribute.type,
|
|
168
|
+
name: attributeName,
|
|
169
|
+
mutable: attribute.mutable,
|
|
170
|
+
required: attribute.required,
|
|
171
|
+
...(attribute.type === 'String' && {
|
|
172
|
+
stringAttributeConstraints: {
|
|
173
|
+
minLength: cdktn_1.Token.asString(1),
|
|
174
|
+
maxLength: cdktn_1.Token.asString(2048),
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
177
|
+
...(attribute.type === 'Number' && {
|
|
178
|
+
numberAttributeConstraints: {
|
|
179
|
+
minValue: cdktn_1.Token.asString(0),
|
|
180
|
+
maxValue: cdktn_1.Token.asString(999999),
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
let constrains;
|
|
187
|
+
if (attribute.type === 'Number') {
|
|
188
|
+
constrains = {
|
|
189
|
+
minValue: cdktn_1.Token.asString(attribute.min ?? 0),
|
|
190
|
+
maxValue: cdktn_1.Token.asString(attribute.max ?? 999999),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
else if (attribute.type === 'String') {
|
|
194
|
+
constrains = {
|
|
195
|
+
minLength: cdktn_1.Token.asString(attribute.minLen ?? 0),
|
|
196
|
+
maxLength: cdktn_1.Token.asString(attribute.maxLen ?? 2048),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
schema.push({
|
|
200
|
+
attributeDataType: attribute.type === 'Object' ? 'DateTime' : attribute.type,
|
|
201
|
+
name: attribute.name,
|
|
202
|
+
mutable: attribute.mutable,
|
|
203
|
+
numberAttributeConstraints: attribute.type === 'Number'
|
|
204
|
+
? constrains
|
|
205
|
+
: undefined,
|
|
206
|
+
stringAttributeConstraints: attribute.type === 'String'
|
|
207
|
+
? constrains
|
|
208
|
+
: undefined,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
schema,
|
|
214
|
+
attributeByName,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
static getUserVerification(userVerification) {
|
|
218
|
+
if (!userVerification) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const verificationTemplate = {
|
|
222
|
+
smsMessage: userVerification.sms,
|
|
223
|
+
};
|
|
224
|
+
if (!userVerification.email) {
|
|
225
|
+
return verificationTemplate;
|
|
226
|
+
}
|
|
227
|
+
if (userVerification.email.type === 'code') {
|
|
228
|
+
verificationTemplate.defaultEmailOption = 'CONFIRM_WITH_CODE';
|
|
229
|
+
verificationTemplate.emailMessage = userVerification.email.body;
|
|
230
|
+
verificationTemplate.emailSubject = userVerification.email.subject;
|
|
231
|
+
return verificationTemplate;
|
|
232
|
+
}
|
|
233
|
+
verificationTemplate.defaultEmailOption = 'CONFIRM_WITH_LINK';
|
|
234
|
+
verificationTemplate.emailMessageByLink = userVerification.email.body;
|
|
235
|
+
verificationTemplate.emailSubjectByLink = userVerification.email.subject;
|
|
236
|
+
return verificationTemplate;
|
|
237
|
+
}
|
|
238
|
+
static getSignInCaseSensitive(signInCaseSensitive) {
|
|
239
|
+
if (signInCaseSensitive === undefined) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
caseSensitive: signInCaseSensitive,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
static getCognitoPlan(plan) {
|
|
247
|
+
if (!plan) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
return plan.toUpperCase();
|
|
251
|
+
}
|
|
252
|
+
static getEmailConfig(email) {
|
|
253
|
+
if (!email) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (email.account === 'ses') {
|
|
257
|
+
return {
|
|
258
|
+
emailSendingAccount: 'DEVELOPER',
|
|
259
|
+
sourceArn: email.arn,
|
|
260
|
+
fromEmailAddress: email.from,
|
|
261
|
+
replyToEmailAddress: email.reply,
|
|
262
|
+
configurationSet: email.configurationSet,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
emailSendingAccount: 'COGNITO_DEFAULT',
|
|
267
|
+
fromEmailAddress: email.from,
|
|
268
|
+
replyToEmailAddress: email.reply,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
static getAutoVerifiedAttributes(attributes) {
|
|
272
|
+
if (!attributes) {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
const verifyAttributes = {
|
|
276
|
+
email: 'email',
|
|
277
|
+
phone: 'phone_number',
|
|
278
|
+
};
|
|
279
|
+
return attributes.map((attr) => verifyAttributes[attr]);
|
|
280
|
+
}
|
|
281
|
+
static getPasswordPolicy(policy) {
|
|
282
|
+
if (!policy) {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
minimumLength: policy.minLength,
|
|
287
|
+
requireLowercase: policy.requireLowercase,
|
|
288
|
+
requireNumbers: policy.requireDigits,
|
|
289
|
+
requireSymbols: policy.requireSymbols,
|
|
290
|
+
requireUppercase: policy.requireUppercase,
|
|
291
|
+
temporaryPasswordValidityDays: policy.validityDays,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
static getAdminCreateUserConfig(selfSignUpEnabled, invitationMessage) {
|
|
295
|
+
if (selfSignUpEnabled === undefined && !invitationMessage) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
allowAdminCreateUserOnly: selfSignUpEnabled !== undefined ? !selfSignUpEnabled : undefined,
|
|
300
|
+
inviteMessageTemplate: invitationMessage
|
|
301
|
+
? {
|
|
302
|
+
emailMessage: invitationMessage?.email?.body,
|
|
303
|
+
emailSubject: invitationMessage?.email?.subject,
|
|
304
|
+
smsMessage: invitationMessage?.sms,
|
|
305
|
+
}
|
|
306
|
+
: undefined,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
static getAccountRecoverySettings(accountRecovery) {
|
|
310
|
+
if (!accountRecovery) {
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
recoveryMechanism: accountRecovery.map((name, index) => ({
|
|
315
|
+
name,
|
|
316
|
+
priority: index + 1,
|
|
317
|
+
})),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
static getAliasAttributes(signInAliases) {
|
|
321
|
+
if (!signInAliases) {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
const aliases = {
|
|
325
|
+
email: 'email',
|
|
326
|
+
phone: 'phoneNumber',
|
|
327
|
+
preferred_username: 'preferred_username',
|
|
328
|
+
};
|
|
329
|
+
return signInAliases.map((alias) => aliases[alias]);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
exports.InternalUserPool = InternalUserPool;
|