@stacksjs/ts-cloud-core 0.1.3 → 0.1.6
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/README.md +98 -13
- package/package.json +12 -3
- package/src/advanced-features.test.ts +0 -465
- package/src/aws/cloudformation.ts +0 -421
- package/src/aws/cloudfront.ts +0 -158
- package/src/aws/credentials.test.ts +0 -132
- package/src/aws/credentials.ts +0 -545
- package/src/aws/index.ts +0 -87
- package/src/aws/s3.test.ts +0 -188
- package/src/aws/s3.ts +0 -1088
- package/src/aws/signature.test.ts +0 -670
- package/src/aws/signature.ts +0 -1155
- package/src/backup/disaster-recovery.test.ts +0 -726
- package/src/backup/disaster-recovery.ts +0 -500
- package/src/backup/index.ts +0 -34
- package/src/backup/manager.test.ts +0 -498
- package/src/backup/manager.ts +0 -432
- package/src/cicd/circleci.ts +0 -430
- package/src/cicd/github-actions.ts +0 -424
- package/src/cicd/gitlab-ci.ts +0 -255
- package/src/cicd/index.ts +0 -8
- package/src/cli/history.ts +0 -396
- package/src/cli/index.ts +0 -10
- package/src/cli/progress.ts +0 -458
- package/src/cli/repl.ts +0 -454
- package/src/cli/suggestions.ts +0 -327
- package/src/cli/table.test.ts +0 -319
- package/src/cli/table.ts +0 -332
- package/src/cloudformation/builder.test.ts +0 -327
- package/src/cloudformation/builder.ts +0 -378
- package/src/cloudformation/builders/api-gateway.ts +0 -449
- package/src/cloudformation/builders/cache.ts +0 -334
- package/src/cloudformation/builders/cdn.ts +0 -278
- package/src/cloudformation/builders/compute.ts +0 -485
- package/src/cloudformation/builders/database.ts +0 -392
- package/src/cloudformation/builders/functions.ts +0 -343
- package/src/cloudformation/builders/messaging.ts +0 -140
- package/src/cloudformation/builders/monitoring.ts +0 -300
- package/src/cloudformation/builders/network.ts +0 -264
- package/src/cloudformation/builders/queue.ts +0 -147
- package/src/cloudformation/builders/security.ts +0 -399
- package/src/cloudformation/builders/storage.ts +0 -285
- package/src/cloudformation/index.ts +0 -30
- package/src/cloudformation/types.ts +0 -173
- package/src/compliance/aws-config.ts +0 -543
- package/src/compliance/cloudtrail.ts +0 -376
- package/src/compliance/compliance.test.ts +0 -423
- package/src/compliance/guardduty.ts +0 -446
- package/src/compliance/index.ts +0 -66
- package/src/compliance/security-hub.ts +0 -456
- package/src/containers/build-optimization.ts +0 -416
- package/src/containers/containers.test.ts +0 -508
- package/src/containers/image-scanning.ts +0 -360
- package/src/containers/index.ts +0 -9
- package/src/containers/registry.ts +0 -293
- package/src/containers/service-mesh.ts +0 -520
- package/src/database/database.test.ts +0 -762
- package/src/database/index.ts +0 -9
- package/src/database/migrations.ts +0 -444
- package/src/database/performance.ts +0 -528
- package/src/database/replicas.ts +0 -534
- package/src/database/users.ts +0 -494
- package/src/dependency-graph.ts +0 -143
- package/src/deployment/ab-testing.ts +0 -582
- package/src/deployment/blue-green.ts +0 -452
- package/src/deployment/canary.ts +0 -500
- package/src/deployment/deployment.test.ts +0 -526
- package/src/deployment/index.ts +0 -61
- package/src/deployment/progressive.ts +0 -62
- package/src/dns/dns.test.ts +0 -641
- package/src/dns/dnssec.ts +0 -315
- package/src/dns/index.ts +0 -8
- package/src/dns/resolver.ts +0 -496
- package/src/dns/routing.ts +0 -593
- package/src/email/advanced/analytics.ts +0 -445
- package/src/email/advanced/index.ts +0 -11
- package/src/email/advanced/rules.ts +0 -465
- package/src/email/advanced/scheduling.ts +0 -352
- package/src/email/advanced/search.ts +0 -412
- package/src/email/advanced/shared-mailboxes.ts +0 -404
- package/src/email/advanced/templates.ts +0 -455
- package/src/email/advanced/threading.ts +0 -281
- package/src/email/analytics.ts +0 -467
- package/src/email/bounce-handling.ts +0 -425
- package/src/email/email.test.ts +0 -431
- package/src/email/handlers/__tests__/inbound.test.ts +0 -38
- package/src/email/handlers/__tests__/outbound.test.ts +0 -37
- package/src/email/handlers/converter.ts +0 -227
- package/src/email/handlers/feedback.ts +0 -228
- package/src/email/handlers/inbound.ts +0 -169
- package/src/email/handlers/outbound.ts +0 -178
- package/src/email/index.ts +0 -15
- package/src/email/reputation.ts +0 -303
- package/src/email/templates.ts +0 -352
- package/src/errors/index.test.ts +0 -434
- package/src/errors/index.ts +0 -416
- package/src/health-checks/index.ts +0 -40
- package/src/index.ts +0 -360
- package/src/intrinsic-functions.ts +0 -118
- package/src/lambda/concurrency.ts +0 -330
- package/src/lambda/destinations.ts +0 -345
- package/src/lambda/dlq.ts +0 -425
- package/src/lambda/index.ts +0 -11
- package/src/lambda/lambda.test.ts +0 -840
- package/src/lambda/layers.ts +0 -263
- package/src/lambda/versions.ts +0 -376
- package/src/lambda/vpc.ts +0 -399
- package/src/local/config.ts +0 -114
- package/src/local/index.ts +0 -6
- package/src/local/mock-aws.ts +0 -351
- package/src/modules/ai.ts +0 -340
- package/src/modules/api.ts +0 -478
- package/src/modules/auth.ts +0 -805
- package/src/modules/cache.ts +0 -417
- package/src/modules/cdn.ts +0 -1062
- package/src/modules/communication.ts +0 -1094
- package/src/modules/compute.ts +0 -3348
- package/src/modules/database.ts +0 -554
- package/src/modules/deployment.ts +0 -1079
- package/src/modules/dns.ts +0 -337
- package/src/modules/email.ts +0 -1538
- package/src/modules/filesystem.ts +0 -515
- package/src/modules/index.ts +0 -32
- package/src/modules/messaging.ts +0 -486
- package/src/modules/monitoring.ts +0 -2086
- package/src/modules/network.ts +0 -664
- package/src/modules/parameter-store.ts +0 -325
- package/src/modules/permissions.ts +0 -1081
- package/src/modules/phone.ts +0 -494
- package/src/modules/queue.ts +0 -1260
- package/src/modules/redirects.ts +0 -464
- package/src/modules/registry.ts +0 -699
- package/src/modules/search.ts +0 -401
- package/src/modules/secrets.ts +0 -416
- package/src/modules/security.ts +0 -731
- package/src/modules/sms.ts +0 -389
- package/src/modules/storage.ts +0 -1120
- package/src/modules/workflow.ts +0 -680
- package/src/multi-account/config.ts +0 -521
- package/src/multi-account/index.ts +0 -7
- package/src/multi-account/manager.ts +0 -427
- package/src/multi-region/cross-region.ts +0 -410
- package/src/multi-region/index.ts +0 -8
- package/src/multi-region/manager.ts +0 -483
- package/src/multi-region/regions.ts +0 -435
- package/src/network-security/index.ts +0 -48
- package/src/observability/index.ts +0 -9
- package/src/observability/logs.ts +0 -522
- package/src/observability/metrics.ts +0 -460
- package/src/observability/observability.test.ts +0 -782
- package/src/observability/synthetics.ts +0 -568
- package/src/observability/xray.ts +0 -358
- package/src/phone/advanced/analytics.ts +0 -349
- package/src/phone/advanced/callbacks.ts +0 -428
- package/src/phone/advanced/index.ts +0 -8
- package/src/phone/advanced/ivr-builder.ts +0 -504
- package/src/phone/advanced/recording.ts +0 -310
- package/src/phone/handlers/__tests__/incoming-call.test.ts +0 -40
- package/src/phone/handlers/incoming-call.ts +0 -117
- package/src/phone/handlers/missed-call.ts +0 -116
- package/src/phone/handlers/voicemail.ts +0 -179
- package/src/phone/index.ts +0 -9
- package/src/presets/api-backend.ts +0 -134
- package/src/presets/data-pipeline.ts +0 -204
- package/src/presets/extend.test.ts +0 -295
- package/src/presets/extend.ts +0 -297
- package/src/presets/fullstack-app.ts +0 -144
- package/src/presets/index.ts +0 -27
- package/src/presets/jamstack.ts +0 -135
- package/src/presets/microservices.ts +0 -167
- package/src/presets/ml-api.ts +0 -208
- package/src/presets/nodejs-server.ts +0 -104
- package/src/presets/nodejs-serverless.ts +0 -114
- package/src/presets/realtime-app.ts +0 -184
- package/src/presets/static-site.ts +0 -64
- package/src/presets/traditional-web-app.ts +0 -339
- package/src/presets/wordpress.ts +0 -138
- package/src/preview/github.test.ts +0 -249
- package/src/preview/github.ts +0 -297
- package/src/preview/index.ts +0 -37
- package/src/preview/manager.test.ts +0 -440
- package/src/preview/manager.ts +0 -326
- package/src/preview/notifications.test.ts +0 -582
- package/src/preview/notifications.ts +0 -341
- package/src/queue/batch-processing.ts +0 -402
- package/src/queue/dlq-monitoring.ts +0 -402
- package/src/queue/fifo.ts +0 -342
- package/src/queue/index.ts +0 -9
- package/src/queue/management.ts +0 -428
- package/src/queue/queue.test.ts +0 -429
- package/src/resource-mgmt/index.ts +0 -39
- package/src/resource-naming.ts +0 -62
- package/src/s3/index.ts +0 -523
- package/src/schema/cloud-config.schema.json +0 -554
- package/src/schema/index.ts +0 -68
- package/src/security/certificate-manager.ts +0 -492
- package/src/security/index.ts +0 -9
- package/src/security/scanning.ts +0 -545
- package/src/security/secrets-manager.ts +0 -476
- package/src/security/secrets-rotation.ts +0 -456
- package/src/security/security.test.ts +0 -738
- package/src/sms/advanced/ab-testing.ts +0 -389
- package/src/sms/advanced/analytics.ts +0 -336
- package/src/sms/advanced/campaigns.ts +0 -523
- package/src/sms/advanced/chatbot.ts +0 -224
- package/src/sms/advanced/index.ts +0 -10
- package/src/sms/advanced/link-tracking.ts +0 -248
- package/src/sms/advanced/mms.ts +0 -308
- package/src/sms/handlers/__tests__/send.test.ts +0 -40
- package/src/sms/handlers/delivery-status.ts +0 -133
- package/src/sms/handlers/receive.ts +0 -162
- package/src/sms/handlers/send.ts +0 -174
- package/src/sms/index.ts +0 -9
- package/src/stack-diff.ts +0 -389
- package/src/static-site/index.ts +0 -85
- package/src/template-builder.ts +0 -110
- package/src/template-validator.ts +0 -574
- package/src/utils/cache.ts +0 -291
- package/src/utils/diff.ts +0 -269
- package/src/utils/hash.ts +0 -227
- package/src/utils/index.ts +0 -8
- package/src/utils/parallel.ts +0 -294
- package/src/validators/credentials.test.ts +0 -274
- package/src/validators/credentials.ts +0 -233
- package/src/validators/quotas.test.ts +0 -434
- package/src/validators/quotas.ts +0 -217
- package/test/ai.test.ts +0 -327
- package/test/api.test.ts +0 -511
- package/test/auth.test.ts +0 -632
- package/test/cache.test.ts +0 -406
- package/test/cdn.test.ts +0 -247
- package/test/compute.test.ts +0 -861
- package/test/database.test.ts +0 -523
- package/test/deployment.test.ts +0 -499
- package/test/dns.test.ts +0 -270
- package/test/email.test.ts +0 -439
- package/test/filesystem.test.ts +0 -382
- package/test/integration.test.ts +0 -350
- package/test/messaging.test.ts +0 -514
- package/test/monitoring.test.ts +0 -634
- package/test/network.test.ts +0 -425
- package/test/permissions.test.ts +0 -488
- package/test/queue.test.ts +0 -484
- package/test/registry.test.ts +0 -306
- package/test/security.test.ts +0 -462
- package/test/storage.test.ts +0 -463
- package/test/template-validator.test.ts +0 -559
- package/test/workflow.test.ts +0 -592
- package/tsconfig.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
package/src/modules/auth.ts
DELETED
|
@@ -1,805 +0,0 @@
|
|
|
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
|
-
}
|