@stacksjs/ts-cloud-core 0.1.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/LICENSE.md +21 -0
- package/README.md +321 -0
- package/package.json +31 -0
- package/src/advanced-features.test.ts +465 -0
- package/src/aws/cloudformation.ts +421 -0
- package/src/aws/cloudfront.ts +158 -0
- package/src/aws/credentials.test.ts +132 -0
- package/src/aws/credentials.ts +545 -0
- package/src/aws/index.ts +87 -0
- package/src/aws/s3.test.ts +188 -0
- package/src/aws/s3.ts +1088 -0
- package/src/aws/signature.test.ts +670 -0
- package/src/aws/signature.ts +1155 -0
- package/src/backup/disaster-recovery.test.ts +726 -0
- package/src/backup/disaster-recovery.ts +500 -0
- package/src/backup/index.ts +34 -0
- package/src/backup/manager.test.ts +498 -0
- package/src/backup/manager.ts +432 -0
- package/src/cicd/circleci.ts +430 -0
- package/src/cicd/github-actions.ts +424 -0
- package/src/cicd/gitlab-ci.ts +255 -0
- package/src/cicd/index.ts +8 -0
- package/src/cli/history.ts +396 -0
- package/src/cli/index.ts +10 -0
- package/src/cli/progress.ts +458 -0
- package/src/cli/repl.ts +454 -0
- package/src/cli/suggestions.ts +327 -0
- package/src/cli/table.test.ts +319 -0
- package/src/cli/table.ts +332 -0
- package/src/cloudformation/builder.test.ts +327 -0
- package/src/cloudformation/builder.ts +378 -0
- package/src/cloudformation/builders/api-gateway.ts +449 -0
- package/src/cloudformation/builders/cache.ts +334 -0
- package/src/cloudformation/builders/cdn.ts +278 -0
- package/src/cloudformation/builders/compute.ts +485 -0
- package/src/cloudformation/builders/database.ts +392 -0
- package/src/cloudformation/builders/functions.ts +343 -0
- package/src/cloudformation/builders/messaging.ts +140 -0
- package/src/cloudformation/builders/monitoring.ts +300 -0
- package/src/cloudformation/builders/network.ts +264 -0
- package/src/cloudformation/builders/queue.ts +147 -0
- package/src/cloudformation/builders/security.ts +399 -0
- package/src/cloudformation/builders/storage.ts +285 -0
- package/src/cloudformation/index.ts +30 -0
- package/src/cloudformation/types.ts +173 -0
- package/src/compliance/aws-config.ts +543 -0
- package/src/compliance/cloudtrail.ts +376 -0
- package/src/compliance/compliance.test.ts +423 -0
- package/src/compliance/guardduty.ts +446 -0
- package/src/compliance/index.ts +66 -0
- package/src/compliance/security-hub.ts +456 -0
- package/src/containers/build-optimization.ts +416 -0
- package/src/containers/containers.test.ts +508 -0
- package/src/containers/image-scanning.ts +360 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/registry.ts +293 -0
- package/src/containers/service-mesh.ts +520 -0
- package/src/database/database.test.ts +762 -0
- package/src/database/index.ts +9 -0
- package/src/database/migrations.ts +444 -0
- package/src/database/performance.ts +528 -0
- package/src/database/replicas.ts +534 -0
- package/src/database/users.ts +494 -0
- package/src/dependency-graph.ts +143 -0
- package/src/deployment/ab-testing.ts +582 -0
- package/src/deployment/blue-green.ts +452 -0
- package/src/deployment/canary.ts +500 -0
- package/src/deployment/deployment.test.ts +526 -0
- package/src/deployment/index.ts +61 -0
- package/src/deployment/progressive.ts +62 -0
- package/src/dns/dns.test.ts +641 -0
- package/src/dns/dnssec.ts +315 -0
- package/src/dns/index.ts +8 -0
- package/src/dns/resolver.ts +496 -0
- package/src/dns/routing.ts +593 -0
- package/src/email/advanced/analytics.ts +445 -0
- package/src/email/advanced/index.ts +11 -0
- package/src/email/advanced/rules.ts +465 -0
- package/src/email/advanced/scheduling.ts +352 -0
- package/src/email/advanced/search.ts +412 -0
- package/src/email/advanced/shared-mailboxes.ts +404 -0
- package/src/email/advanced/templates.ts +455 -0
- package/src/email/advanced/threading.ts +281 -0
- package/src/email/analytics.ts +467 -0
- package/src/email/bounce-handling.ts +425 -0
- package/src/email/email.test.ts +431 -0
- package/src/email/handlers/__tests__/inbound.test.ts +38 -0
- package/src/email/handlers/__tests__/outbound.test.ts +37 -0
- package/src/email/handlers/converter.ts +227 -0
- package/src/email/handlers/feedback.ts +228 -0
- package/src/email/handlers/inbound.ts +169 -0
- package/src/email/handlers/outbound.ts +178 -0
- package/src/email/index.ts +15 -0
- package/src/email/reputation.ts +303 -0
- package/src/email/templates.ts +352 -0
- package/src/errors/index.test.ts +434 -0
- package/src/errors/index.ts +416 -0
- package/src/health-checks/index.ts +40 -0
- package/src/index.ts +360 -0
- package/src/intrinsic-functions.ts +118 -0
- package/src/lambda/concurrency.ts +330 -0
- package/src/lambda/destinations.ts +345 -0
- package/src/lambda/dlq.ts +425 -0
- package/src/lambda/index.ts +11 -0
- package/src/lambda/lambda.test.ts +840 -0
- package/src/lambda/layers.ts +263 -0
- package/src/lambda/versions.ts +376 -0
- package/src/lambda/vpc.ts +399 -0
- package/src/local/config.ts +114 -0
- package/src/local/index.ts +6 -0
- package/src/local/mock-aws.ts +351 -0
- package/src/modules/ai.ts +340 -0
- package/src/modules/api.ts +478 -0
- package/src/modules/auth.ts +805 -0
- package/src/modules/cache.ts +417 -0
- package/src/modules/cdn.ts +1062 -0
- package/src/modules/communication.ts +1094 -0
- package/src/modules/compute.ts +3348 -0
- package/src/modules/database.ts +554 -0
- package/src/modules/deployment.ts +1079 -0
- package/src/modules/dns.ts +337 -0
- package/src/modules/email.ts +1538 -0
- package/src/modules/filesystem.ts +515 -0
- package/src/modules/index.ts +32 -0
- package/src/modules/messaging.ts +486 -0
- package/src/modules/monitoring.ts +2086 -0
- package/src/modules/network.ts +664 -0
- package/src/modules/parameter-store.ts +325 -0
- package/src/modules/permissions.ts +1081 -0
- package/src/modules/phone.ts +494 -0
- package/src/modules/queue.ts +1260 -0
- package/src/modules/redirects.ts +464 -0
- package/src/modules/registry.ts +699 -0
- package/src/modules/search.ts +401 -0
- package/src/modules/secrets.ts +416 -0
- package/src/modules/security.ts +731 -0
- package/src/modules/sms.ts +389 -0
- package/src/modules/storage.ts +1120 -0
- package/src/modules/workflow.ts +680 -0
- package/src/multi-account/config.ts +521 -0
- package/src/multi-account/index.ts +7 -0
- package/src/multi-account/manager.ts +427 -0
- package/src/multi-region/cross-region.ts +410 -0
- package/src/multi-region/index.ts +8 -0
- package/src/multi-region/manager.ts +483 -0
- package/src/multi-region/regions.ts +435 -0
- package/src/network-security/index.ts +48 -0
- package/src/observability/index.ts +9 -0
- package/src/observability/logs.ts +522 -0
- package/src/observability/metrics.ts +460 -0
- package/src/observability/observability.test.ts +782 -0
- package/src/observability/synthetics.ts +568 -0
- package/src/observability/xray.ts +358 -0
- package/src/phone/advanced/analytics.ts +349 -0
- package/src/phone/advanced/callbacks.ts +428 -0
- package/src/phone/advanced/index.ts +8 -0
- package/src/phone/advanced/ivr-builder.ts +504 -0
- package/src/phone/advanced/recording.ts +310 -0
- package/src/phone/handlers/__tests__/incoming-call.test.ts +40 -0
- package/src/phone/handlers/incoming-call.ts +117 -0
- package/src/phone/handlers/missed-call.ts +116 -0
- package/src/phone/handlers/voicemail.ts +179 -0
- package/src/phone/index.ts +9 -0
- package/src/presets/api-backend.ts +134 -0
- package/src/presets/data-pipeline.ts +204 -0
- package/src/presets/extend.test.ts +295 -0
- package/src/presets/extend.ts +297 -0
- package/src/presets/fullstack-app.ts +144 -0
- package/src/presets/index.ts +27 -0
- package/src/presets/jamstack.ts +135 -0
- package/src/presets/microservices.ts +167 -0
- package/src/presets/ml-api.ts +208 -0
- package/src/presets/nodejs-server.ts +104 -0
- package/src/presets/nodejs-serverless.ts +114 -0
- package/src/presets/realtime-app.ts +184 -0
- package/src/presets/static-site.ts +64 -0
- package/src/presets/traditional-web-app.ts +339 -0
- package/src/presets/wordpress.ts +138 -0
- package/src/preview/github.test.ts +249 -0
- package/src/preview/github.ts +297 -0
- package/src/preview/index.ts +37 -0
- package/src/preview/manager.test.ts +440 -0
- package/src/preview/manager.ts +326 -0
- package/src/preview/notifications.test.ts +582 -0
- package/src/preview/notifications.ts +341 -0
- package/src/queue/batch-processing.ts +402 -0
- package/src/queue/dlq-monitoring.ts +402 -0
- package/src/queue/fifo.ts +342 -0
- package/src/queue/index.ts +9 -0
- package/src/queue/management.ts +428 -0
- package/src/queue/queue.test.ts +429 -0
- package/src/resource-mgmt/index.ts +39 -0
- package/src/resource-naming.ts +62 -0
- package/src/s3/index.ts +523 -0
- package/src/schema/cloud-config.schema.json +554 -0
- package/src/schema/index.ts +68 -0
- package/src/security/certificate-manager.ts +492 -0
- package/src/security/index.ts +9 -0
- package/src/security/scanning.ts +545 -0
- package/src/security/secrets-manager.ts +476 -0
- package/src/security/secrets-rotation.ts +456 -0
- package/src/security/security.test.ts +738 -0
- package/src/sms/advanced/ab-testing.ts +389 -0
- package/src/sms/advanced/analytics.ts +336 -0
- package/src/sms/advanced/campaigns.ts +523 -0
- package/src/sms/advanced/chatbot.ts +224 -0
- package/src/sms/advanced/index.ts +10 -0
- package/src/sms/advanced/link-tracking.ts +248 -0
- package/src/sms/advanced/mms.ts +308 -0
- package/src/sms/handlers/__tests__/send.test.ts +40 -0
- package/src/sms/handlers/delivery-status.ts +133 -0
- package/src/sms/handlers/receive.ts +162 -0
- package/src/sms/handlers/send.ts +174 -0
- package/src/sms/index.ts +9 -0
- package/src/stack-diff.ts +389 -0
- package/src/static-site/index.ts +85 -0
- package/src/template-builder.ts +110 -0
- package/src/template-validator.ts +574 -0
- package/src/utils/cache.ts +291 -0
- package/src/utils/diff.ts +269 -0
- package/src/utils/hash.ts +227 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parallel.ts +294 -0
- package/src/validators/credentials.test.ts +274 -0
- package/src/validators/credentials.ts +233 -0
- package/src/validators/quotas.test.ts +434 -0
- package/src/validators/quotas.ts +217 -0
- package/test/ai.test.ts +327 -0
- package/test/api.test.ts +511 -0
- package/test/auth.test.ts +632 -0
- package/test/cache.test.ts +406 -0
- package/test/cdn.test.ts +247 -0
- package/test/compute.test.ts +861 -0
- package/test/database.test.ts +523 -0
- package/test/deployment.test.ts +499 -0
- package/test/dns.test.ts +270 -0
- package/test/email.test.ts +439 -0
- package/test/filesystem.test.ts +382 -0
- package/test/integration.test.ts +350 -0
- package/test/messaging.test.ts +514 -0
- package/test/monitoring.test.ts +634 -0
- package/test/network.test.ts +425 -0
- package/test/permissions.test.ts +488 -0
- package/test/queue.test.ts +484 -0
- package/test/registry.test.ts +306 -0
- package/test/security.test.ts +462 -0
- package/test/storage.test.ts +463 -0
- package/test/template-validator.test.ts +559 -0
- package/test/workflow.test.ts +592 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,805 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CognitoUserPool,
|
|
3
|
+
CognitoUserPoolClient,
|
|
4
|
+
CognitoUserPoolDomain,
|
|
5
|
+
CognitoIdentityPool,
|
|
6
|
+
CognitoIdentityPoolRoleAttachment,
|
|
7
|
+
IAMRole,
|
|
8
|
+
} from '@stacksjs/ts-cloud-aws-types'
|
|
9
|
+
import type { EnvironmentType } from '@stacksjs/ts-cloud-types'
|
|
10
|
+
import { Fn } from '../intrinsic-functions'
|
|
11
|
+
import { generateLogicalId, generateResourceName } from '../resource-naming'
|
|
12
|
+
|
|
13
|
+
export interface UserPoolOptions {
|
|
14
|
+
slug: string
|
|
15
|
+
environment: EnvironmentType
|
|
16
|
+
userPoolName?: string
|
|
17
|
+
aliasAttributes?: ('email' | 'phone_number')[]
|
|
18
|
+
autoVerifiedAttributes?: ('email' | 'phone_number')[]
|
|
19
|
+
passwordPolicy?: PasswordPolicyOptions
|
|
20
|
+
mfaConfiguration?: 'OFF' | 'ON' | 'OPTIONAL'
|
|
21
|
+
emailConfiguration?: EmailConfigurationOptions
|
|
22
|
+
smsConfiguration?: SmsConfigurationOptions
|
|
23
|
+
lambdaTriggers?: LambdaTriggersOptions
|
|
24
|
+
userPoolAddOns?: {
|
|
25
|
+
advancedSecurityMode?: 'OFF' | 'AUDIT' | 'ENFORCED'
|
|
26
|
+
}
|
|
27
|
+
accountRecoverySetting?: {
|
|
28
|
+
recoveryMechanisms: Array<{
|
|
29
|
+
Name: 'verified_email' | 'verified_phone_number' | 'admin_only'
|
|
30
|
+
Priority: number
|
|
31
|
+
}>
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PasswordPolicyOptions {
|
|
36
|
+
minimumLength?: number
|
|
37
|
+
requireLowercase?: boolean
|
|
38
|
+
requireUppercase?: boolean
|
|
39
|
+
requireNumbers?: boolean
|
|
40
|
+
requireSymbols?: boolean
|
|
41
|
+
temporaryPasswordValidityDays?: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface EmailConfigurationOptions {
|
|
45
|
+
emailSendingAccount?: 'COGNITO_DEFAULT' | 'DEVELOPER'
|
|
46
|
+
from?: string
|
|
47
|
+
replyToEmailAddress?: string
|
|
48
|
+
sourceArn?: string
|
|
49
|
+
configurationSet?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SmsConfigurationOptions {
|
|
53
|
+
externalId: string
|
|
54
|
+
snsCallerArn: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface LambdaTriggersOptions {
|
|
58
|
+
preSignUp?: string
|
|
59
|
+
postConfirmation?: string
|
|
60
|
+
preAuthentication?: string
|
|
61
|
+
postAuthentication?: string
|
|
62
|
+
customMessage?: string
|
|
63
|
+
defineAuthChallenge?: string
|
|
64
|
+
createAuthChallenge?: string
|
|
65
|
+
verifyAuthChallengeResponse?: string
|
|
66
|
+
preTokenGeneration?: string
|
|
67
|
+
userMigration?: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface UserPoolClientOptions {
|
|
71
|
+
slug: string
|
|
72
|
+
environment: EnvironmentType
|
|
73
|
+
clientName?: string
|
|
74
|
+
generateSecret?: boolean
|
|
75
|
+
refreshTokenValidity?: number
|
|
76
|
+
accessTokenValidity?: number
|
|
77
|
+
idTokenValidity?: number
|
|
78
|
+
tokenValidityUnits?: {
|
|
79
|
+
RefreshToken?: 'seconds' | 'minutes' | 'hours' | 'days'
|
|
80
|
+
AccessToken?: 'seconds' | 'minutes' | 'hours' | 'days'
|
|
81
|
+
IdToken?: 'seconds' | 'minutes' | 'hours' | 'days'
|
|
82
|
+
}
|
|
83
|
+
readAttributes?: string[]
|
|
84
|
+
writeAttributes?: string[]
|
|
85
|
+
explicitAuthFlows?: string[]
|
|
86
|
+
preventUserExistenceErrors?: 'ENABLED' | 'LEGACY'
|
|
87
|
+
enableTokenRevocation?: boolean
|
|
88
|
+
callbackURLs?: string[]
|
|
89
|
+
logoutURLs?: string[]
|
|
90
|
+
allowedOAuthFlows?: ('code' | 'implicit' | 'client_credentials')[]
|
|
91
|
+
allowedOAuthScopes?: string[]
|
|
92
|
+
allowedOAuthFlowsUserPoolClient?: boolean
|
|
93
|
+
supportedIdentityProviders?: string[]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface UserPoolDomainOptions {
|
|
97
|
+
slug: string
|
|
98
|
+
environment: EnvironmentType
|
|
99
|
+
domain: string
|
|
100
|
+
customDomainConfig?: {
|
|
101
|
+
CertificateArn: string
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface IdentityPoolOptions {
|
|
106
|
+
slug: string
|
|
107
|
+
environment: EnvironmentType
|
|
108
|
+
identityPoolName?: string
|
|
109
|
+
allowUnauthenticatedIdentities?: boolean
|
|
110
|
+
cognitoIdentityProviders?: Array<{
|
|
111
|
+
ClientId: string
|
|
112
|
+
ProviderName: string
|
|
113
|
+
ServerSideTokenCheck?: boolean
|
|
114
|
+
}>
|
|
115
|
+
supportedLoginProviders?: Record<string, string>
|
|
116
|
+
samlProviderARNs?: string[]
|
|
117
|
+
openIdConnectProviderARNs?: string[]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface IdentityPoolRoleAttachmentOptions {
|
|
121
|
+
slug: string
|
|
122
|
+
environment: EnvironmentType
|
|
123
|
+
authenticatedRole: string
|
|
124
|
+
unauthenticatedRole?: string
|
|
125
|
+
roleMappings?: Record<string, {
|
|
126
|
+
Type: 'Token' | 'Rules'
|
|
127
|
+
AmbiguousRoleResolution?: 'AuthenticatedRole' | 'Deny'
|
|
128
|
+
RulesConfiguration?: {
|
|
129
|
+
Rules: Array<{
|
|
130
|
+
Claim: string
|
|
131
|
+
MatchType: 'Equals' | 'Contains' | 'StartsWith' | 'NotEqual'
|
|
132
|
+
Value: string
|
|
133
|
+
RoleARN: string
|
|
134
|
+
}>
|
|
135
|
+
}
|
|
136
|
+
}>
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Authentication Module - Cognito
|
|
141
|
+
* Provides clean API for user authentication and identity management
|
|
142
|
+
*/
|
|
143
|
+
export class Auth {
|
|
144
|
+
/**
|
|
145
|
+
* Create a Cognito User Pool
|
|
146
|
+
*/
|
|
147
|
+
static createUserPool(options: UserPoolOptions): {
|
|
148
|
+
userPool: CognitoUserPool
|
|
149
|
+
logicalId: string
|
|
150
|
+
} {
|
|
151
|
+
const {
|
|
152
|
+
slug,
|
|
153
|
+
environment,
|
|
154
|
+
userPoolName,
|
|
155
|
+
aliasAttributes,
|
|
156
|
+
autoVerifiedAttributes,
|
|
157
|
+
passwordPolicy,
|
|
158
|
+
mfaConfiguration,
|
|
159
|
+
emailConfiguration,
|
|
160
|
+
smsConfiguration,
|
|
161
|
+
lambdaTriggers,
|
|
162
|
+
userPoolAddOns,
|
|
163
|
+
accountRecoverySetting,
|
|
164
|
+
} = options
|
|
165
|
+
|
|
166
|
+
const resourceName = userPoolName || generateResourceName({
|
|
167
|
+
slug,
|
|
168
|
+
environment,
|
|
169
|
+
resourceType: 'user-pool',
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const logicalId = generateLogicalId(resourceName)
|
|
173
|
+
|
|
174
|
+
const userPool: CognitoUserPool = {
|
|
175
|
+
Type: 'AWS::Cognito::UserPool',
|
|
176
|
+
Properties: {
|
|
177
|
+
UserPoolName: resourceName,
|
|
178
|
+
Policies: passwordPolicy
|
|
179
|
+
? {
|
|
180
|
+
PasswordPolicy: {
|
|
181
|
+
MinimumLength: passwordPolicy.minimumLength,
|
|
182
|
+
RequireLowercase: passwordPolicy.requireLowercase,
|
|
183
|
+
RequireUppercase: passwordPolicy.requireUppercase,
|
|
184
|
+
RequireNumbers: passwordPolicy.requireNumbers,
|
|
185
|
+
RequireSymbols: passwordPolicy.requireSymbols,
|
|
186
|
+
TemporaryPasswordValidityDays: passwordPolicy.temporaryPasswordValidityDays,
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
: undefined,
|
|
190
|
+
MfaConfiguration: mfaConfiguration,
|
|
191
|
+
Schema: [
|
|
192
|
+
{
|
|
193
|
+
Name: 'email',
|
|
194
|
+
AttributeDataType: 'String',
|
|
195
|
+
Required: true,
|
|
196
|
+
Mutable: false,
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (aliasAttributes && aliasAttributes.length > 0) {
|
|
203
|
+
userPool.Properties!.UsernameAttributes = aliasAttributes
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (autoVerifiedAttributes && autoVerifiedAttributes.length > 0) {
|
|
207
|
+
userPool.Properties!.AutoVerifiedAttributes = autoVerifiedAttributes
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (emailConfiguration) {
|
|
211
|
+
userPool.Properties!.EmailConfiguration = {
|
|
212
|
+
EmailSendingAccount: emailConfiguration.emailSendingAccount,
|
|
213
|
+
From: emailConfiguration.from,
|
|
214
|
+
ReplyToEmailAddress: emailConfiguration.replyToEmailAddress,
|
|
215
|
+
SourceArn: emailConfiguration.sourceArn,
|
|
216
|
+
ConfigurationSet: emailConfiguration.configurationSet,
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (smsConfiguration) {
|
|
221
|
+
userPool.Properties!.SmsConfiguration = {
|
|
222
|
+
ExternalId: smsConfiguration.externalId,
|
|
223
|
+
SnsCallerArn: smsConfiguration.snsCallerArn,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (lambdaTriggers) {
|
|
228
|
+
userPool.Properties!.LambdaConfig = {
|
|
229
|
+
PreSignUp: lambdaTriggers.preSignUp,
|
|
230
|
+
PostConfirmation: lambdaTriggers.postConfirmation,
|
|
231
|
+
PreAuthentication: lambdaTriggers.preAuthentication,
|
|
232
|
+
PostAuthentication: lambdaTriggers.postAuthentication,
|
|
233
|
+
CustomMessage: lambdaTriggers.customMessage,
|
|
234
|
+
DefineAuthChallenge: lambdaTriggers.defineAuthChallenge,
|
|
235
|
+
CreateAuthChallenge: lambdaTriggers.createAuthChallenge,
|
|
236
|
+
VerifyAuthChallengeResponse: lambdaTriggers.verifyAuthChallengeResponse,
|
|
237
|
+
PreTokenGeneration: lambdaTriggers.preTokenGeneration,
|
|
238
|
+
UserMigration: lambdaTriggers.userMigration,
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (userPoolAddOns) {
|
|
243
|
+
userPool.Properties!.UserPoolAddOns = {
|
|
244
|
+
AdvancedSecurityMode: userPoolAddOns.advancedSecurityMode,
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (accountRecoverySetting) {
|
|
249
|
+
userPool.Properties!.AccountRecoverySetting = {
|
|
250
|
+
RecoveryMechanisms: accountRecoverySetting.recoveryMechanisms,
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return { userPool, logicalId }
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Create a Cognito User Pool Client
|
|
259
|
+
*/
|
|
260
|
+
static createUserPoolClient(
|
|
261
|
+
userPoolLogicalId: string,
|
|
262
|
+
options: UserPoolClientOptions,
|
|
263
|
+
): {
|
|
264
|
+
client: CognitoUserPoolClient
|
|
265
|
+
logicalId: string
|
|
266
|
+
} {
|
|
267
|
+
const {
|
|
268
|
+
slug,
|
|
269
|
+
environment,
|
|
270
|
+
clientName,
|
|
271
|
+
generateSecret = false,
|
|
272
|
+
refreshTokenValidity,
|
|
273
|
+
accessTokenValidity,
|
|
274
|
+
idTokenValidity,
|
|
275
|
+
tokenValidityUnits,
|
|
276
|
+
readAttributes,
|
|
277
|
+
writeAttributes,
|
|
278
|
+
explicitAuthFlows,
|
|
279
|
+
preventUserExistenceErrors,
|
|
280
|
+
enableTokenRevocation,
|
|
281
|
+
callbackURLs,
|
|
282
|
+
logoutURLs,
|
|
283
|
+
allowedOAuthFlows,
|
|
284
|
+
allowedOAuthScopes,
|
|
285
|
+
allowedOAuthFlowsUserPoolClient,
|
|
286
|
+
supportedIdentityProviders,
|
|
287
|
+
} = options
|
|
288
|
+
|
|
289
|
+
const resourceName = clientName || generateResourceName({
|
|
290
|
+
slug,
|
|
291
|
+
environment,
|
|
292
|
+
resourceType: 'user-pool-client',
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
const logicalId = generateLogicalId(resourceName)
|
|
296
|
+
|
|
297
|
+
const client: CognitoUserPoolClient = {
|
|
298
|
+
Type: 'AWS::Cognito::UserPoolClient',
|
|
299
|
+
Properties: {
|
|
300
|
+
ClientName: resourceName,
|
|
301
|
+
UserPoolId: Fn.Ref(userPoolLogicalId) as unknown as string,
|
|
302
|
+
GenerateSecret: generateSecret,
|
|
303
|
+
RefreshTokenValidity: refreshTokenValidity,
|
|
304
|
+
AccessTokenValidity: accessTokenValidity,
|
|
305
|
+
IdTokenValidity: idTokenValidity,
|
|
306
|
+
TokenValidityUnits: tokenValidityUnits,
|
|
307
|
+
ReadAttributes: readAttributes,
|
|
308
|
+
WriteAttributes: writeAttributes,
|
|
309
|
+
ExplicitAuthFlows: explicitAuthFlows,
|
|
310
|
+
PreventUserExistenceErrors: preventUserExistenceErrors,
|
|
311
|
+
EnableTokenRevocation: enableTokenRevocation,
|
|
312
|
+
CallbackURLs: callbackURLs,
|
|
313
|
+
LogoutURLs: logoutURLs,
|
|
314
|
+
AllowedOAuthFlows: allowedOAuthFlows,
|
|
315
|
+
AllowedOAuthScopes: allowedOAuthScopes,
|
|
316
|
+
AllowedOAuthFlowsUserPoolClient: allowedOAuthFlowsUserPoolClient,
|
|
317
|
+
SupportedIdentityProviders: supportedIdentityProviders,
|
|
318
|
+
},
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return { client, logicalId }
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Create a Cognito User Pool Domain
|
|
326
|
+
*/
|
|
327
|
+
static createUserPoolDomain(
|
|
328
|
+
userPoolLogicalId: string,
|
|
329
|
+
options: UserPoolDomainOptions,
|
|
330
|
+
): {
|
|
331
|
+
domain: CognitoUserPoolDomain
|
|
332
|
+
logicalId: string
|
|
333
|
+
} {
|
|
334
|
+
const {
|
|
335
|
+
slug,
|
|
336
|
+
environment,
|
|
337
|
+
domain,
|
|
338
|
+
customDomainConfig,
|
|
339
|
+
} = options
|
|
340
|
+
|
|
341
|
+
const resourceName = generateResourceName({
|
|
342
|
+
slug,
|
|
343
|
+
environment,
|
|
344
|
+
resourceType: 'user-pool-domain',
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
const logicalId = generateLogicalId(resourceName)
|
|
348
|
+
|
|
349
|
+
const userPoolDomain: CognitoUserPoolDomain = {
|
|
350
|
+
Type: 'AWS::Cognito::UserPoolDomain',
|
|
351
|
+
Properties: {
|
|
352
|
+
Domain: domain,
|
|
353
|
+
UserPoolId: Fn.Ref(userPoolLogicalId) as unknown as string,
|
|
354
|
+
CustomDomainConfig: customDomainConfig,
|
|
355
|
+
},
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return { domain: userPoolDomain, logicalId }
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Create a Cognito Identity Pool
|
|
363
|
+
*/
|
|
364
|
+
static createIdentityPool(options: IdentityPoolOptions): {
|
|
365
|
+
identityPool: CognitoIdentityPool
|
|
366
|
+
logicalId: string
|
|
367
|
+
} {
|
|
368
|
+
const {
|
|
369
|
+
slug,
|
|
370
|
+
environment,
|
|
371
|
+
identityPoolName,
|
|
372
|
+
allowUnauthenticatedIdentities = false,
|
|
373
|
+
cognitoIdentityProviders,
|
|
374
|
+
supportedLoginProviders,
|
|
375
|
+
samlProviderARNs,
|
|
376
|
+
openIdConnectProviderARNs,
|
|
377
|
+
} = options
|
|
378
|
+
|
|
379
|
+
const resourceName = identityPoolName || generateResourceName({
|
|
380
|
+
slug,
|
|
381
|
+
environment,
|
|
382
|
+
resourceType: 'identity-pool',
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
const logicalId = generateLogicalId(resourceName)
|
|
386
|
+
|
|
387
|
+
const identityPool: CognitoIdentityPool = {
|
|
388
|
+
Type: 'AWS::Cognito::IdentityPool',
|
|
389
|
+
Properties: {
|
|
390
|
+
IdentityPoolName: resourceName,
|
|
391
|
+
AllowUnauthenticatedIdentities: allowUnauthenticatedIdentities,
|
|
392
|
+
CognitoIdentityProviders: cognitoIdentityProviders,
|
|
393
|
+
SupportedLoginProviders: supportedLoginProviders,
|
|
394
|
+
SamlProviderARNs: samlProviderARNs,
|
|
395
|
+
OpenIdConnectProviderARNs: openIdConnectProviderARNs,
|
|
396
|
+
},
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return { identityPool, logicalId }
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Create an Identity Pool Role Attachment
|
|
404
|
+
*/
|
|
405
|
+
static createIdentityPoolRoleAttachment(
|
|
406
|
+
identityPoolLogicalId: string,
|
|
407
|
+
options: IdentityPoolRoleAttachmentOptions,
|
|
408
|
+
): {
|
|
409
|
+
attachment: CognitoIdentityPoolRoleAttachment
|
|
410
|
+
logicalId: string
|
|
411
|
+
} {
|
|
412
|
+
const {
|
|
413
|
+
slug,
|
|
414
|
+
environment,
|
|
415
|
+
authenticatedRole,
|
|
416
|
+
unauthenticatedRole,
|
|
417
|
+
roleMappings,
|
|
418
|
+
} = options
|
|
419
|
+
|
|
420
|
+
const resourceName = generateResourceName({
|
|
421
|
+
slug,
|
|
422
|
+
environment,
|
|
423
|
+
resourceType: 'identity-pool-role-attachment',
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
const logicalId = generateLogicalId(resourceName)
|
|
427
|
+
|
|
428
|
+
const roles: Record<string, string> = {
|
|
429
|
+
authenticated: authenticatedRole,
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (unauthenticatedRole) {
|
|
433
|
+
roles.unauthenticated = unauthenticatedRole
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const attachment: CognitoIdentityPoolRoleAttachment = {
|
|
437
|
+
Type: 'AWS::Cognito::IdentityPoolRoleAttachment',
|
|
438
|
+
Properties: {
|
|
439
|
+
IdentityPoolId: Fn.Ref(identityPoolLogicalId) as unknown as string,
|
|
440
|
+
Roles: roles,
|
|
441
|
+
RoleMappings: roleMappings,
|
|
442
|
+
},
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return { attachment, logicalId }
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Create IAM role for authenticated users
|
|
450
|
+
*/
|
|
451
|
+
static createAuthenticatedRole(options: {
|
|
452
|
+
slug: string
|
|
453
|
+
environment: EnvironmentType
|
|
454
|
+
identityPoolLogicalId: string
|
|
455
|
+
}): {
|
|
456
|
+
role: IAMRole
|
|
457
|
+
logicalId: string
|
|
458
|
+
} {
|
|
459
|
+
const { slug, environment, identityPoolLogicalId } = options
|
|
460
|
+
|
|
461
|
+
const resourceName = generateResourceName({
|
|
462
|
+
slug,
|
|
463
|
+
environment,
|
|
464
|
+
resourceType: 'cognito-authenticated-role',
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
const logicalId = generateLogicalId(resourceName)
|
|
468
|
+
|
|
469
|
+
const role: IAMRole = {
|
|
470
|
+
Type: 'AWS::IAM::Role',
|
|
471
|
+
Properties: {
|
|
472
|
+
RoleName: resourceName,
|
|
473
|
+
AssumeRolePolicyDocument: {
|
|
474
|
+
Version: '2012-10-17',
|
|
475
|
+
Statement: [
|
|
476
|
+
{
|
|
477
|
+
Effect: 'Allow',
|
|
478
|
+
Principal: {
|
|
479
|
+
Federated: 'cognito-identity.amazonaws.com',
|
|
480
|
+
},
|
|
481
|
+
Action: 'sts:AssumeRoleWithWebIdentity',
|
|
482
|
+
Condition: {
|
|
483
|
+
StringEquals: {
|
|
484
|
+
'cognito-identity.amazonaws.com:aud': Fn.Ref(identityPoolLogicalId) as unknown as string,
|
|
485
|
+
},
|
|
486
|
+
'ForAnyValue:StringLike': {
|
|
487
|
+
'cognito-identity.amazonaws.com:amr': 'authenticated',
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
},
|
|
493
|
+
Policies: [
|
|
494
|
+
{
|
|
495
|
+
PolicyName: 'CognitoAuthenticatedPolicy',
|
|
496
|
+
PolicyDocument: {
|
|
497
|
+
Version: '2012-10-17',
|
|
498
|
+
Statement: [
|
|
499
|
+
{
|
|
500
|
+
Effect: 'Allow',
|
|
501
|
+
Action: [
|
|
502
|
+
'cognito-sync:*',
|
|
503
|
+
'cognito-identity:*',
|
|
504
|
+
],
|
|
505
|
+
Resource: '*',
|
|
506
|
+
},
|
|
507
|
+
],
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
Tags: [
|
|
512
|
+
{ Key: 'Name', Value: resourceName },
|
|
513
|
+
{ Key: 'Environment', Value: environment },
|
|
514
|
+
],
|
|
515
|
+
},
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return { role, logicalId }
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Create IAM role for unauthenticated users
|
|
523
|
+
*/
|
|
524
|
+
static createUnauthenticatedRole(options: {
|
|
525
|
+
slug: string
|
|
526
|
+
environment: EnvironmentType
|
|
527
|
+
identityPoolLogicalId: string
|
|
528
|
+
}): {
|
|
529
|
+
role: IAMRole
|
|
530
|
+
logicalId: string
|
|
531
|
+
} {
|
|
532
|
+
const { slug, environment, identityPoolLogicalId } = options
|
|
533
|
+
|
|
534
|
+
const resourceName = generateResourceName({
|
|
535
|
+
slug,
|
|
536
|
+
environment,
|
|
537
|
+
resourceType: 'cognito-unauthenticated-role',
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
const logicalId = generateLogicalId(resourceName)
|
|
541
|
+
|
|
542
|
+
const role: IAMRole = {
|
|
543
|
+
Type: 'AWS::IAM::Role',
|
|
544
|
+
Properties: {
|
|
545
|
+
RoleName: resourceName,
|
|
546
|
+
AssumeRolePolicyDocument: {
|
|
547
|
+
Version: '2012-10-17',
|
|
548
|
+
Statement: [
|
|
549
|
+
{
|
|
550
|
+
Effect: 'Allow',
|
|
551
|
+
Principal: {
|
|
552
|
+
Federated: 'cognito-identity.amazonaws.com',
|
|
553
|
+
},
|
|
554
|
+
Action: 'sts:AssumeRoleWithWebIdentity',
|
|
555
|
+
Condition: {
|
|
556
|
+
StringEquals: {
|
|
557
|
+
'cognito-identity.amazonaws.com:aud': Fn.Ref(identityPoolLogicalId) as unknown as string,
|
|
558
|
+
},
|
|
559
|
+
'ForAnyValue:StringLike': {
|
|
560
|
+
'cognito-identity.amazonaws.com:amr': 'unauthenticated',
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
],
|
|
565
|
+
},
|
|
566
|
+
Policies: [
|
|
567
|
+
{
|
|
568
|
+
PolicyName: 'CognitoUnauthenticatedPolicy',
|
|
569
|
+
PolicyDocument: {
|
|
570
|
+
Version: '2012-10-17',
|
|
571
|
+
Statement: [
|
|
572
|
+
{
|
|
573
|
+
Effect: 'Allow',
|
|
574
|
+
Action: [
|
|
575
|
+
'cognito-sync:*',
|
|
576
|
+
],
|
|
577
|
+
Resource: '*',
|
|
578
|
+
},
|
|
579
|
+
],
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
],
|
|
583
|
+
Tags: [
|
|
584
|
+
{ Key: 'Name', Value: resourceName },
|
|
585
|
+
{ Key: 'Environment', Value: environment },
|
|
586
|
+
],
|
|
587
|
+
},
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return { role, logicalId }
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Common password policies
|
|
595
|
+
*/
|
|
596
|
+
static readonly PasswordPolicies = {
|
|
597
|
+
/**
|
|
598
|
+
* Relaxed password policy for development
|
|
599
|
+
*/
|
|
600
|
+
relaxed: (): PasswordPolicyOptions => ({
|
|
601
|
+
minimumLength: 8,
|
|
602
|
+
requireLowercase: false,
|
|
603
|
+
requireUppercase: false,
|
|
604
|
+
requireNumbers: false,
|
|
605
|
+
requireSymbols: false,
|
|
606
|
+
temporaryPasswordValidityDays: 7,
|
|
607
|
+
}),
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Standard password policy
|
|
611
|
+
*/
|
|
612
|
+
standard: (): PasswordPolicyOptions => ({
|
|
613
|
+
minimumLength: 8,
|
|
614
|
+
requireLowercase: true,
|
|
615
|
+
requireUppercase: true,
|
|
616
|
+
requireNumbers: true,
|
|
617
|
+
requireSymbols: false,
|
|
618
|
+
temporaryPasswordValidityDays: 3,
|
|
619
|
+
}),
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Strict password policy for production
|
|
623
|
+
*/
|
|
624
|
+
strict: (): PasswordPolicyOptions => ({
|
|
625
|
+
minimumLength: 12,
|
|
626
|
+
requireLowercase: true,
|
|
627
|
+
requireUppercase: true,
|
|
628
|
+
requireNumbers: true,
|
|
629
|
+
requireSymbols: true,
|
|
630
|
+
temporaryPasswordValidityDays: 1,
|
|
631
|
+
}),
|
|
632
|
+
} as const
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Common authentication flows
|
|
636
|
+
*/
|
|
637
|
+
static readonly AuthFlows = {
|
|
638
|
+
/**
|
|
639
|
+
* Standard auth flows (SRP, refresh token)
|
|
640
|
+
*/
|
|
641
|
+
standard: [
|
|
642
|
+
'ALLOW_USER_SRP_AUTH',
|
|
643
|
+
'ALLOW_REFRESH_TOKEN_AUTH',
|
|
644
|
+
],
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Admin auth flows (for server-side authentication)
|
|
648
|
+
*/
|
|
649
|
+
admin: [
|
|
650
|
+
'ALLOW_ADMIN_USER_PASSWORD_AUTH',
|
|
651
|
+
'ALLOW_REFRESH_TOKEN_AUTH',
|
|
652
|
+
],
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Custom auth flows
|
|
656
|
+
*/
|
|
657
|
+
custom: [
|
|
658
|
+
'ALLOW_CUSTOM_AUTH',
|
|
659
|
+
'ALLOW_REFRESH_TOKEN_AUTH',
|
|
660
|
+
],
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* All auth flows (not recommended for production)
|
|
664
|
+
*/
|
|
665
|
+
all: [
|
|
666
|
+
'ALLOW_USER_SRP_AUTH',
|
|
667
|
+
'ALLOW_USER_PASSWORD_AUTH',
|
|
668
|
+
'ALLOW_ADMIN_USER_PASSWORD_AUTH',
|
|
669
|
+
'ALLOW_CUSTOM_AUTH',
|
|
670
|
+
'ALLOW_REFRESH_TOKEN_AUTH',
|
|
671
|
+
],
|
|
672
|
+
} as const
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Common OAuth scopes
|
|
676
|
+
*/
|
|
677
|
+
static readonly OAuthScopes = {
|
|
678
|
+
/**
|
|
679
|
+
* Basic OAuth scopes
|
|
680
|
+
*/
|
|
681
|
+
basic: [
|
|
682
|
+
'openid',
|
|
683
|
+
'email',
|
|
684
|
+
'profile',
|
|
685
|
+
],
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* All standard scopes
|
|
689
|
+
*/
|
|
690
|
+
all: [
|
|
691
|
+
'openid',
|
|
692
|
+
'email',
|
|
693
|
+
'profile',
|
|
694
|
+
'phone',
|
|
695
|
+
'aws.cognito.signin.user.admin',
|
|
696
|
+
],
|
|
697
|
+
} as const
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Common use cases
|
|
701
|
+
*/
|
|
702
|
+
static readonly UseCases = {
|
|
703
|
+
/**
|
|
704
|
+
* Create a basic user pool for web application
|
|
705
|
+
*/
|
|
706
|
+
webApp: (slug: string, environment: EnvironmentType, callbackUrl: string): {
|
|
707
|
+
userPool: CognitoUserPool
|
|
708
|
+
poolId: string
|
|
709
|
+
client: CognitoUserPoolClient
|
|
710
|
+
clientId: string
|
|
711
|
+
} => {
|
|
712
|
+
const { userPool, logicalId: poolId } = Auth.createUserPool({
|
|
713
|
+
slug,
|
|
714
|
+
environment,
|
|
715
|
+
aliasAttributes: ['email'],
|
|
716
|
+
autoVerifiedAttributes: ['email'],
|
|
717
|
+
passwordPolicy: Auth.PasswordPolicies.standard(),
|
|
718
|
+
mfaConfiguration: 'OPTIONAL',
|
|
719
|
+
})
|
|
720
|
+
|
|
721
|
+
const { client, logicalId: clientId } = Auth.createUserPoolClient(poolId, {
|
|
722
|
+
slug,
|
|
723
|
+
environment,
|
|
724
|
+
explicitAuthFlows: [...Auth.AuthFlows.standard],
|
|
725
|
+
callbackURLs: [callbackUrl],
|
|
726
|
+
allowedOAuthFlows: ['code'],
|
|
727
|
+
allowedOAuthScopes: [...Auth.OAuthScopes.basic],
|
|
728
|
+
allowedOAuthFlowsUserPoolClient: true,
|
|
729
|
+
})
|
|
730
|
+
|
|
731
|
+
return { userPool, poolId, client, clientId }
|
|
732
|
+
},
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Create a user pool with identity pool for mobile app
|
|
736
|
+
*/
|
|
737
|
+
mobileApp: (slug: string, environment: EnvironmentType): {
|
|
738
|
+
userPool: CognitoUserPool
|
|
739
|
+
poolId: string
|
|
740
|
+
client: CognitoUserPoolClient
|
|
741
|
+
clientId: string
|
|
742
|
+
identityPool: CognitoIdentityPool
|
|
743
|
+
identityPoolId: string
|
|
744
|
+
authRole: IAMRole
|
|
745
|
+
authRoleId: string
|
|
746
|
+
attachment: CognitoIdentityPoolRoleAttachment
|
|
747
|
+
attachmentId: string
|
|
748
|
+
} => {
|
|
749
|
+
const { userPool, logicalId: poolId } = Auth.createUserPool({
|
|
750
|
+
slug,
|
|
751
|
+
environment,
|
|
752
|
+
aliasAttributes: ['email'],
|
|
753
|
+
autoVerifiedAttributes: ['email'],
|
|
754
|
+
passwordPolicy: Auth.PasswordPolicies.standard(),
|
|
755
|
+
mfaConfiguration: 'OPTIONAL',
|
|
756
|
+
})
|
|
757
|
+
|
|
758
|
+
const { client, logicalId: clientId } = Auth.createUserPoolClient(poolId, {
|
|
759
|
+
slug,
|
|
760
|
+
environment,
|
|
761
|
+
explicitAuthFlows: [...Auth.AuthFlows.standard],
|
|
762
|
+
})
|
|
763
|
+
|
|
764
|
+
const { identityPool, logicalId: identityPoolId } = Auth.createIdentityPool({
|
|
765
|
+
slug,
|
|
766
|
+
environment,
|
|
767
|
+
allowUnauthenticatedIdentities: false,
|
|
768
|
+
cognitoIdentityProviders: [
|
|
769
|
+
{
|
|
770
|
+
ClientId: Fn.Ref(clientId) as unknown as string,
|
|
771
|
+
ProviderName: Fn.GetAtt(poolId, 'ProviderName') as unknown as string,
|
|
772
|
+
},
|
|
773
|
+
],
|
|
774
|
+
})
|
|
775
|
+
|
|
776
|
+
const { role: authRole, logicalId: authRoleId } = Auth.createAuthenticatedRole({
|
|
777
|
+
slug,
|
|
778
|
+
environment,
|
|
779
|
+
identityPoolLogicalId: identityPoolId,
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
const { attachment, logicalId: attachmentId } = Auth.createIdentityPoolRoleAttachment(
|
|
783
|
+
identityPoolId,
|
|
784
|
+
{
|
|
785
|
+
slug,
|
|
786
|
+
environment,
|
|
787
|
+
authenticatedRole: Fn.GetAtt(authRoleId, 'Arn') as unknown as string,
|
|
788
|
+
},
|
|
789
|
+
)
|
|
790
|
+
|
|
791
|
+
return {
|
|
792
|
+
userPool,
|
|
793
|
+
poolId,
|
|
794
|
+
client,
|
|
795
|
+
clientId,
|
|
796
|
+
identityPool,
|
|
797
|
+
identityPoolId,
|
|
798
|
+
authRole,
|
|
799
|
+
authRoleId,
|
|
800
|
+
attachment,
|
|
801
|
+
attachmentId,
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
} as const
|
|
805
|
+
}
|