@ttoss/cloud-auth 0.6.4 → 0.7.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/.turbo/turbo-build.log +6 -6
- package/.turbo/turbo-test.log +18 -16
- package/CHANGELOG.md +12 -0
- package/coverage/clover.xml +185 -67
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/config.ts.html +1 -1
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/index.ts.html +1 -1
- package/coverage/lcov-report/template.ts.html +440 -86
- package/coverage/lcov.info +190 -69
- package/dist/esm/index.js +124 -13
- package/dist/index.d.ts +17 -20
- package/dist/index.js +124 -13
- package/package.json +5 -5
- package/src/template.ts +155 -37
- package/tests/unit/template.test.ts +85 -65
package/coverage/lcov.info
CHANGED
|
@@ -28,7 +28,7 @@ BRH:4
|
|
|
28
28
|
end_of_record
|
|
29
29
|
TN:
|
|
30
30
|
SF:src/template.ts
|
|
31
|
-
FN:
|
|
31
|
+
FN:22,createAuthTemplate
|
|
32
32
|
FNF:1
|
|
33
33
|
FNH:1
|
|
34
34
|
FNDA:12,createAuthTemplate
|
|
@@ -48,12 +48,12 @@ DA:13,1
|
|
|
48
48
|
DA:14,1
|
|
49
49
|
DA:15,1
|
|
50
50
|
DA:16,1
|
|
51
|
-
DA:17,
|
|
52
|
-
DA:18,
|
|
53
|
-
DA:19,
|
|
54
|
-
DA:20,
|
|
55
|
-
DA:21,
|
|
56
|
-
DA:22,
|
|
51
|
+
DA:17,1
|
|
52
|
+
DA:18,1
|
|
53
|
+
DA:19,1
|
|
54
|
+
DA:20,1
|
|
55
|
+
DA:21,1
|
|
56
|
+
DA:22,1
|
|
57
57
|
DA:23,12
|
|
58
58
|
DA:24,12
|
|
59
59
|
DA:25,12
|
|
@@ -82,12 +82,12 @@ DA:47,12
|
|
|
82
82
|
DA:48,12
|
|
83
83
|
DA:49,12
|
|
84
84
|
DA:50,12
|
|
85
|
-
DA:51,
|
|
85
|
+
DA:51,12
|
|
86
86
|
DA:52,12
|
|
87
87
|
DA:53,12
|
|
88
88
|
DA:54,12
|
|
89
89
|
DA:55,12
|
|
90
|
-
DA:56,
|
|
90
|
+
DA:56,9
|
|
91
91
|
DA:57,12
|
|
92
92
|
DA:58,12
|
|
93
93
|
DA:59,12
|
|
@@ -161,27 +161,27 @@ DA:126,12
|
|
|
161
161
|
DA:127,12
|
|
162
162
|
DA:128,12
|
|
163
163
|
DA:129,12
|
|
164
|
-
DA:130,
|
|
165
|
-
DA:131,
|
|
166
|
-
DA:132,
|
|
167
|
-
DA:133,
|
|
168
|
-
DA:134,
|
|
169
|
-
DA:135,
|
|
170
|
-
DA:136,
|
|
171
|
-
DA:137,
|
|
172
|
-
DA:138,
|
|
173
|
-
DA:139,
|
|
174
|
-
DA:140,
|
|
175
|
-
DA:141,
|
|
176
|
-
DA:142,
|
|
177
|
-
DA:143,
|
|
178
|
-
DA:144,
|
|
179
|
-
DA:145,
|
|
180
|
-
DA:146,
|
|
181
|
-
DA:147,
|
|
182
|
-
DA:148,
|
|
183
|
-
DA:149,
|
|
184
|
-
DA:150,
|
|
164
|
+
DA:130,12
|
|
165
|
+
DA:131,12
|
|
166
|
+
DA:132,12
|
|
167
|
+
DA:133,12
|
|
168
|
+
DA:134,12
|
|
169
|
+
DA:135,1
|
|
170
|
+
DA:136,1
|
|
171
|
+
DA:137,1
|
|
172
|
+
DA:138,1
|
|
173
|
+
DA:139,0
|
|
174
|
+
DA:140,0
|
|
175
|
+
DA:141,0
|
|
176
|
+
DA:142,0
|
|
177
|
+
DA:143,0
|
|
178
|
+
DA:144,1
|
|
179
|
+
DA:145,1
|
|
180
|
+
DA:146,1
|
|
181
|
+
DA:147,1
|
|
182
|
+
DA:148,1
|
|
183
|
+
DA:149,1
|
|
184
|
+
DA:150,1
|
|
185
185
|
DA:151,1
|
|
186
186
|
DA:152,1
|
|
187
187
|
DA:153,1
|
|
@@ -195,43 +195,164 @@ DA:160,1
|
|
|
195
195
|
DA:161,1
|
|
196
196
|
DA:162,1
|
|
197
197
|
DA:163,1
|
|
198
|
-
DA:164,
|
|
199
|
-
DA:165,
|
|
200
|
-
DA:166,
|
|
201
|
-
DA:167,
|
|
202
|
-
DA:168,
|
|
203
|
-
DA:169,
|
|
204
|
-
DA:170,
|
|
205
|
-
DA:171,
|
|
206
|
-
DA:172,
|
|
207
|
-
DA:173,
|
|
208
|
-
DA:174,
|
|
209
|
-
DA:175,
|
|
210
|
-
DA:176,
|
|
211
|
-
DA:177,
|
|
212
|
-
DA:178,
|
|
213
|
-
DA:179,
|
|
214
|
-
DA:180,
|
|
215
|
-
DA:181,
|
|
216
|
-
DA:182,
|
|
217
|
-
DA:183,
|
|
218
|
-
DA:184,
|
|
219
|
-
DA:185,
|
|
220
|
-
DA:186,
|
|
221
|
-
DA:187,
|
|
222
|
-
DA:188,
|
|
223
|
-
DA:189,
|
|
224
|
-
DA:190,
|
|
225
|
-
DA:191,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
198
|
+
DA:164,1
|
|
199
|
+
DA:165,1
|
|
200
|
+
DA:166,1
|
|
201
|
+
DA:167,12
|
|
202
|
+
DA:168,12
|
|
203
|
+
DA:169,2
|
|
204
|
+
DA:170,2
|
|
205
|
+
DA:171,2
|
|
206
|
+
DA:172,2
|
|
207
|
+
DA:173,2
|
|
208
|
+
DA:174,2
|
|
209
|
+
DA:175,2
|
|
210
|
+
DA:176,2
|
|
211
|
+
DA:177,2
|
|
212
|
+
DA:178,2
|
|
213
|
+
DA:179,2
|
|
214
|
+
DA:180,2
|
|
215
|
+
DA:181,2
|
|
216
|
+
DA:182,2
|
|
217
|
+
DA:183,2
|
|
218
|
+
DA:184,2
|
|
219
|
+
DA:185,2
|
|
220
|
+
DA:186,2
|
|
221
|
+
DA:187,2
|
|
222
|
+
DA:188,2
|
|
223
|
+
DA:189,2
|
|
224
|
+
DA:190,2
|
|
225
|
+
DA:191,2
|
|
226
|
+
DA:192,2
|
|
227
|
+
DA:193,2
|
|
228
|
+
DA:194,2
|
|
229
|
+
DA:195,2
|
|
230
|
+
DA:196,2
|
|
231
|
+
DA:197,2
|
|
232
|
+
DA:198,2
|
|
233
|
+
DA:199,2
|
|
234
|
+
DA:200,2
|
|
235
|
+
DA:201,2
|
|
236
|
+
DA:202,2
|
|
237
|
+
DA:203,2
|
|
238
|
+
DA:204,2
|
|
239
|
+
DA:205,2
|
|
240
|
+
DA:206,2
|
|
241
|
+
DA:207,2
|
|
242
|
+
DA:208,2
|
|
243
|
+
DA:209,2
|
|
244
|
+
DA:210,2
|
|
245
|
+
DA:211,2
|
|
246
|
+
DA:212,2
|
|
247
|
+
DA:213,2
|
|
248
|
+
DA:214,2
|
|
249
|
+
DA:215,2
|
|
250
|
+
DA:216,2
|
|
251
|
+
DA:217,2
|
|
252
|
+
DA:218,2
|
|
253
|
+
DA:219,2
|
|
254
|
+
DA:220,2
|
|
255
|
+
DA:221,2
|
|
256
|
+
DA:222,2
|
|
257
|
+
DA:223,2
|
|
258
|
+
DA:224,2
|
|
259
|
+
DA:225,2
|
|
260
|
+
DA:226,2
|
|
261
|
+
DA:227,2
|
|
262
|
+
DA:228,2
|
|
263
|
+
DA:229,2
|
|
264
|
+
DA:230,2
|
|
265
|
+
DA:231,2
|
|
266
|
+
DA:232,2
|
|
267
|
+
DA:233,2
|
|
268
|
+
DA:234,2
|
|
269
|
+
DA:235,2
|
|
270
|
+
DA:236,2
|
|
271
|
+
DA:237,2
|
|
272
|
+
DA:238,2
|
|
273
|
+
DA:239,2
|
|
274
|
+
DA:240,2
|
|
275
|
+
DA:241,2
|
|
276
|
+
DA:242,2
|
|
277
|
+
DA:243,2
|
|
278
|
+
DA:244,2
|
|
279
|
+
DA:245,2
|
|
280
|
+
DA:246,2
|
|
281
|
+
DA:247,2
|
|
282
|
+
DA:248,2
|
|
283
|
+
DA:249,2
|
|
284
|
+
DA:250,2
|
|
285
|
+
DA:251,2
|
|
286
|
+
DA:252,2
|
|
287
|
+
DA:253,2
|
|
288
|
+
DA:254,2
|
|
289
|
+
DA:255,2
|
|
290
|
+
DA:256,2
|
|
291
|
+
DA:257,2
|
|
292
|
+
DA:258,2
|
|
293
|
+
DA:259,2
|
|
294
|
+
DA:260,2
|
|
295
|
+
DA:261,2
|
|
296
|
+
DA:262,2
|
|
297
|
+
DA:263,2
|
|
298
|
+
DA:264,2
|
|
299
|
+
DA:265,2
|
|
300
|
+
DA:266,2
|
|
301
|
+
DA:267,2
|
|
302
|
+
DA:268,2
|
|
303
|
+
DA:269,2
|
|
304
|
+
DA:270,2
|
|
305
|
+
DA:271,2
|
|
306
|
+
DA:272,2
|
|
307
|
+
DA:273,2
|
|
308
|
+
DA:274,2
|
|
309
|
+
DA:275,2
|
|
310
|
+
DA:276,2
|
|
311
|
+
DA:277,2
|
|
312
|
+
DA:278,2
|
|
313
|
+
DA:279,2
|
|
314
|
+
DA:280,2
|
|
315
|
+
DA:281,2
|
|
316
|
+
DA:282,2
|
|
317
|
+
DA:283,2
|
|
318
|
+
DA:284,0
|
|
319
|
+
DA:285,0
|
|
320
|
+
DA:286,2
|
|
321
|
+
DA:287,2
|
|
322
|
+
DA:288,2
|
|
323
|
+
DA:289,2
|
|
324
|
+
DA:290,2
|
|
325
|
+
DA:291,2
|
|
326
|
+
DA:292,2
|
|
327
|
+
DA:293,2
|
|
328
|
+
DA:294,2
|
|
329
|
+
DA:295,2
|
|
330
|
+
DA:296,2
|
|
331
|
+
DA:297,2
|
|
332
|
+
DA:298,2
|
|
333
|
+
DA:299,2
|
|
334
|
+
DA:300,2
|
|
335
|
+
DA:301,2
|
|
336
|
+
DA:302,12
|
|
337
|
+
DA:303,12
|
|
338
|
+
DA:304,12
|
|
339
|
+
DA:305,1
|
|
340
|
+
DA:306,1
|
|
341
|
+
DA:307,1
|
|
342
|
+
DA:308,1
|
|
343
|
+
DA:309,1
|
|
344
|
+
LF:309
|
|
345
|
+
LH:302
|
|
346
|
+
BRDA:22,0,0,12
|
|
347
|
+
BRDA:55,1,0,10
|
|
348
|
+
BRDA:56,2,0,9
|
|
349
|
+
BRDA:57,3,0,3
|
|
350
|
+
BRDA:134,4,0,1
|
|
351
|
+
BRDA:168,5,0,4
|
|
352
|
+
BRDA:168,6,0,2
|
|
353
|
+
BRDA:283,7,0,0
|
|
354
|
+
BRDA:135,8,0,1
|
|
355
|
+
BRDA:138,9,0,0
|
|
356
|
+
BRF:10
|
|
357
|
+
BRH:8
|
|
237
358
|
end_of_record
|
package/dist/esm/index.js
CHANGED
|
@@ -7,10 +7,16 @@ var PASSWORD_MINIMUM_LENGTH = 8;
|
|
|
7
7
|
var CognitoUserPoolLogicalId = "CognitoUserPool";
|
|
8
8
|
var CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
|
|
9
9
|
var CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
|
|
10
|
+
var IdentityPoolAuthenticatedIAMRoleLogicalId = "IdentityPoolAuthenticatedIAMRole";
|
|
11
|
+
var IdentityPoolUnauthenticatedIAMRoleLogicalId = "IdentityPoolUnauthenticatedIAMRole";
|
|
12
|
+
var DenyStatement = {
|
|
13
|
+
Effect: "Deny",
|
|
14
|
+
Action: ["*"],
|
|
15
|
+
Resource: ["*"]
|
|
16
|
+
};
|
|
10
17
|
var createAuthTemplate = ({
|
|
11
18
|
autoVerifiedAttributes = ["email"],
|
|
12
|
-
identityPool
|
|
13
|
-
roles,
|
|
19
|
+
identityPool,
|
|
14
20
|
schema,
|
|
15
21
|
usernameAttributes = ["email"]
|
|
16
22
|
} = {}) => {
|
|
@@ -20,6 +26,7 @@ var createAuthTemplate = ({
|
|
|
20
26
|
Resources: {
|
|
21
27
|
[CognitoUserPoolLogicalId]: {
|
|
22
28
|
Type: "AWS::Cognito::UserPool",
|
|
29
|
+
DeletionPolicy: "Retain",
|
|
23
30
|
Properties: {
|
|
24
31
|
AutoVerifiedAttributes,
|
|
25
32
|
Policies: {
|
|
@@ -32,7 +39,6 @@ var createAuthTemplate = ({
|
|
|
32
39
|
TemporaryPasswordValidityDays: 30
|
|
33
40
|
}
|
|
34
41
|
},
|
|
35
|
-
Schema: schema,
|
|
36
42
|
UsernameAttributes: usernameAttributes,
|
|
37
43
|
UsernameConfiguration: {
|
|
38
44
|
CaseSensitive: false
|
|
@@ -88,7 +94,35 @@ var createAuthTemplate = ({
|
|
|
88
94
|
}
|
|
89
95
|
}
|
|
90
96
|
};
|
|
91
|
-
if (
|
|
97
|
+
if (schema) {
|
|
98
|
+
const Schema = schema.map((attribute) => {
|
|
99
|
+
let NumberAttributeConstraints = void 0;
|
|
100
|
+
if (attribute.numberAttributeConstraints) {
|
|
101
|
+
NumberAttributeConstraints = {
|
|
102
|
+
MaxValue: attribute.numberAttributeConstraints?.maxValue,
|
|
103
|
+
MinValue: attribute.numberAttributeConstraints?.minValue
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
let StringAttributeConstraints = void 0;
|
|
107
|
+
if (attribute.stringAttributeConstraints) {
|
|
108
|
+
StringAttributeConstraints = {
|
|
109
|
+
MaxLength: attribute.stringAttributeConstraints?.maxLength,
|
|
110
|
+
MinLength: attribute.stringAttributeConstraints?.minLength
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
AttributeDataType: attribute.attributeDataType,
|
|
115
|
+
DeveloperOnlyAttribute: attribute.developerOnlyAttribute,
|
|
116
|
+
Mutable: attribute.mutable,
|
|
117
|
+
Name: attribute.name,
|
|
118
|
+
NumberAttributeConstraints,
|
|
119
|
+
Required: attribute.required,
|
|
120
|
+
StringAttributeConstraints
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
template.Resources[CognitoUserPoolLogicalId].Properties.Schema = Schema;
|
|
124
|
+
}
|
|
125
|
+
if (identityPool?.enabled) {
|
|
92
126
|
template.Resources[CognitoIdentityPoolLogicalId] = {
|
|
93
127
|
Type: "AWS::Cognito::IdentityPool",
|
|
94
128
|
Properties: {
|
|
@@ -105,17 +139,94 @@ var createAuthTemplate = ({
|
|
|
105
139
|
]
|
|
106
140
|
}
|
|
107
141
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
142
|
+
template.Resources[IdentityPoolAuthenticatedIAMRoleLogicalId] = {
|
|
143
|
+
Type: "AWS::IAM::Role",
|
|
144
|
+
Properties: {
|
|
145
|
+
AssumeRolePolicyDocument: {
|
|
146
|
+
Version: "2012-10-17",
|
|
147
|
+
Statement: [
|
|
148
|
+
{
|
|
149
|
+
Effect: "Allow",
|
|
150
|
+
Principal: {
|
|
151
|
+
Federated: "cognito-identity.amazonaws.com"
|
|
152
|
+
},
|
|
153
|
+
Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
|
|
154
|
+
Condition: {
|
|
155
|
+
StringEquals: {
|
|
156
|
+
"cognito-identity.amazonaws.com:aud": {
|
|
157
|
+
Ref: CognitoIdentityPoolLogicalId
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
"ForAnyValue:StringLike": {
|
|
161
|
+
"cognito-identity.amazonaws.com:amr": "authenticated"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
Policies: identityPool.authenticatedPolicies || [
|
|
168
|
+
{
|
|
169
|
+
PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
|
|
170
|
+
PolicyDocument: {
|
|
171
|
+
Version: "2012-10-17",
|
|
172
|
+
Statement: [DenyStatement]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
|
|
179
|
+
Type: "AWS::IAM::Role",
|
|
180
|
+
Properties: {
|
|
181
|
+
AssumeRolePolicyDocument: {
|
|
182
|
+
Version: "2012-10-17",
|
|
183
|
+
Statement: [
|
|
184
|
+
{
|
|
185
|
+
Effect: "Allow",
|
|
186
|
+
Principal: {
|
|
187
|
+
Federated: "cognito-identity.amazonaws.com"
|
|
188
|
+
},
|
|
189
|
+
Action: "sts:AssumeRoleWithWebIdentity",
|
|
190
|
+
Condition: {
|
|
191
|
+
StringEquals: {
|
|
192
|
+
"cognito-identity.amazonaws.com:aud": {
|
|
193
|
+
Ref: CognitoIdentityPoolLogicalId
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"ForAnyValue:StringLike": {
|
|
197
|
+
"cognito-identity.amazonaws.com:amr": "unauthenticated"
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
Policies: identityPool.authenticatedPolicies || [
|
|
204
|
+
{
|
|
205
|
+
PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
|
|
206
|
+
PolicyDocument: {
|
|
207
|
+
Version: "2012-10-17",
|
|
208
|
+
Statement: [DenyStatement]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
template.Resources.CognitoIdentityPoolRoleAttachment = {
|
|
215
|
+
Type: "AWS::Cognito::IdentityPoolRoleAttachment",
|
|
216
|
+
Properties: {
|
|
217
|
+
IdentityPoolId: {
|
|
218
|
+
Ref: CognitoIdentityPoolLogicalId
|
|
219
|
+
},
|
|
220
|
+
Roles: {
|
|
221
|
+
authenticated: {
|
|
222
|
+
"Fn::GetAtt": [IdentityPoolAuthenticatedIAMRoleLogicalId, "Arn"]
|
|
114
223
|
},
|
|
115
|
-
|
|
224
|
+
unauthenticated: {
|
|
225
|
+
"Fn::GetAtt": [IdentityPoolUnauthenticatedIAMRoleLogicalId, "Arn"]
|
|
226
|
+
}
|
|
116
227
|
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
119
230
|
if (!template.Outputs) {
|
|
120
231
|
template.Outputs = {};
|
|
121
232
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
import { CloudFormationTemplate } from '@ttoss/cloudformation';
|
|
1
|
+
import { Policy, CloudFormationTemplate } from '@ttoss/cloudformation';
|
|
2
2
|
|
|
3
3
|
declare const PASSWORD_MINIMUM_LENGTH = 8;
|
|
4
4
|
|
|
5
|
-
type Role = string | {
|
|
6
|
-
'Fn::ImportValue': string;
|
|
7
|
-
};
|
|
8
5
|
declare const createAuthTemplate: {
|
|
9
|
-
({ autoVerifiedAttributes, identityPool,
|
|
6
|
+
({ autoVerifiedAttributes, identityPool, schema, usernameAttributes, }?: {
|
|
10
7
|
autoVerifiedAttributes?: false | ("email" | "phone_number")[] | null | undefined;
|
|
11
|
-
identityPool?:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
identityPool?: {
|
|
9
|
+
enabled?: boolean | undefined;
|
|
10
|
+
authenticatedPolicies?: Policy[] | undefined;
|
|
11
|
+
unauthenticatedPolicies?: Policy[] | undefined;
|
|
15
12
|
} | undefined;
|
|
16
13
|
/**
|
|
17
14
|
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-schemaattribute.html
|
|
18
15
|
*/
|
|
19
16
|
schema?: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
attributeDataType?: "Boolean" | "DateTime" | "Number" | "String" | undefined;
|
|
18
|
+
developerOnlyAttribute?: boolean | undefined;
|
|
19
|
+
mutable?: boolean | undefined;
|
|
20
|
+
name?: string | undefined;
|
|
21
|
+
numberAttributeConstraints?: {
|
|
22
|
+
maxValue?: string | undefined;
|
|
23
|
+
minValue?: string | undefined;
|
|
27
24
|
} | undefined;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
required?: boolean | undefined;
|
|
26
|
+
stringAttributeConstraints?: {
|
|
27
|
+
maxLength: string;
|
|
28
|
+
minLength: string;
|
|
32
29
|
} | undefined;
|
|
33
30
|
}[] | undefined;
|
|
34
31
|
usernameAttributes?: ("email" | "phone_number")[] | null | undefined;
|
package/dist/index.js
CHANGED
|
@@ -33,10 +33,16 @@ var PASSWORD_MINIMUM_LENGTH = 8;
|
|
|
33
33
|
var CognitoUserPoolLogicalId = "CognitoUserPool";
|
|
34
34
|
var CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
|
|
35
35
|
var CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
|
|
36
|
+
var IdentityPoolAuthenticatedIAMRoleLogicalId = "IdentityPoolAuthenticatedIAMRole";
|
|
37
|
+
var IdentityPoolUnauthenticatedIAMRoleLogicalId = "IdentityPoolUnauthenticatedIAMRole";
|
|
38
|
+
var DenyStatement = {
|
|
39
|
+
Effect: "Deny",
|
|
40
|
+
Action: ["*"],
|
|
41
|
+
Resource: ["*"]
|
|
42
|
+
};
|
|
36
43
|
var createAuthTemplate = ({
|
|
37
44
|
autoVerifiedAttributes = ["email"],
|
|
38
|
-
identityPool
|
|
39
|
-
roles,
|
|
45
|
+
identityPool,
|
|
40
46
|
schema,
|
|
41
47
|
usernameAttributes = ["email"]
|
|
42
48
|
} = {}) => {
|
|
@@ -46,6 +52,7 @@ var createAuthTemplate = ({
|
|
|
46
52
|
Resources: {
|
|
47
53
|
[CognitoUserPoolLogicalId]: {
|
|
48
54
|
Type: "AWS::Cognito::UserPool",
|
|
55
|
+
DeletionPolicy: "Retain",
|
|
49
56
|
Properties: {
|
|
50
57
|
AutoVerifiedAttributes,
|
|
51
58
|
Policies: {
|
|
@@ -58,7 +65,6 @@ var createAuthTemplate = ({
|
|
|
58
65
|
TemporaryPasswordValidityDays: 30
|
|
59
66
|
}
|
|
60
67
|
},
|
|
61
|
-
Schema: schema,
|
|
62
68
|
UsernameAttributes: usernameAttributes,
|
|
63
69
|
UsernameConfiguration: {
|
|
64
70
|
CaseSensitive: false
|
|
@@ -114,7 +120,35 @@ var createAuthTemplate = ({
|
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
};
|
|
117
|
-
if (
|
|
123
|
+
if (schema) {
|
|
124
|
+
const Schema = schema.map((attribute) => {
|
|
125
|
+
let NumberAttributeConstraints = void 0;
|
|
126
|
+
if (attribute.numberAttributeConstraints) {
|
|
127
|
+
NumberAttributeConstraints = {
|
|
128
|
+
MaxValue: attribute.numberAttributeConstraints?.maxValue,
|
|
129
|
+
MinValue: attribute.numberAttributeConstraints?.minValue
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
let StringAttributeConstraints = void 0;
|
|
133
|
+
if (attribute.stringAttributeConstraints) {
|
|
134
|
+
StringAttributeConstraints = {
|
|
135
|
+
MaxLength: attribute.stringAttributeConstraints?.maxLength,
|
|
136
|
+
MinLength: attribute.stringAttributeConstraints?.minLength
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
AttributeDataType: attribute.attributeDataType,
|
|
141
|
+
DeveloperOnlyAttribute: attribute.developerOnlyAttribute,
|
|
142
|
+
Mutable: attribute.mutable,
|
|
143
|
+
Name: attribute.name,
|
|
144
|
+
NumberAttributeConstraints,
|
|
145
|
+
Required: attribute.required,
|
|
146
|
+
StringAttributeConstraints
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
template.Resources[CognitoUserPoolLogicalId].Properties.Schema = Schema;
|
|
150
|
+
}
|
|
151
|
+
if (identityPool?.enabled) {
|
|
118
152
|
template.Resources[CognitoIdentityPoolLogicalId] = {
|
|
119
153
|
Type: "AWS::Cognito::IdentityPool",
|
|
120
154
|
Properties: {
|
|
@@ -131,17 +165,94 @@ var createAuthTemplate = ({
|
|
|
131
165
|
]
|
|
132
166
|
}
|
|
133
167
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
168
|
+
template.Resources[IdentityPoolAuthenticatedIAMRoleLogicalId] = {
|
|
169
|
+
Type: "AWS::IAM::Role",
|
|
170
|
+
Properties: {
|
|
171
|
+
AssumeRolePolicyDocument: {
|
|
172
|
+
Version: "2012-10-17",
|
|
173
|
+
Statement: [
|
|
174
|
+
{
|
|
175
|
+
Effect: "Allow",
|
|
176
|
+
Principal: {
|
|
177
|
+
Federated: "cognito-identity.amazonaws.com"
|
|
178
|
+
},
|
|
179
|
+
Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
|
|
180
|
+
Condition: {
|
|
181
|
+
StringEquals: {
|
|
182
|
+
"cognito-identity.amazonaws.com:aud": {
|
|
183
|
+
Ref: CognitoIdentityPoolLogicalId
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"ForAnyValue:StringLike": {
|
|
187
|
+
"cognito-identity.amazonaws.com:amr": "authenticated"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
Policies: identityPool.authenticatedPolicies || [
|
|
194
|
+
{
|
|
195
|
+
PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
|
|
196
|
+
PolicyDocument: {
|
|
197
|
+
Version: "2012-10-17",
|
|
198
|
+
Statement: [DenyStatement]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
|
|
205
|
+
Type: "AWS::IAM::Role",
|
|
206
|
+
Properties: {
|
|
207
|
+
AssumeRolePolicyDocument: {
|
|
208
|
+
Version: "2012-10-17",
|
|
209
|
+
Statement: [
|
|
210
|
+
{
|
|
211
|
+
Effect: "Allow",
|
|
212
|
+
Principal: {
|
|
213
|
+
Federated: "cognito-identity.amazonaws.com"
|
|
214
|
+
},
|
|
215
|
+
Action: "sts:AssumeRoleWithWebIdentity",
|
|
216
|
+
Condition: {
|
|
217
|
+
StringEquals: {
|
|
218
|
+
"cognito-identity.amazonaws.com:aud": {
|
|
219
|
+
Ref: CognitoIdentityPoolLogicalId
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
"ForAnyValue:StringLike": {
|
|
223
|
+
"cognito-identity.amazonaws.com:amr": "unauthenticated"
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
Policies: identityPool.authenticatedPolicies || [
|
|
230
|
+
{
|
|
231
|
+
PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
|
|
232
|
+
PolicyDocument: {
|
|
233
|
+
Version: "2012-10-17",
|
|
234
|
+
Statement: [DenyStatement]
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
template.Resources.CognitoIdentityPoolRoleAttachment = {
|
|
241
|
+
Type: "AWS::Cognito::IdentityPoolRoleAttachment",
|
|
242
|
+
Properties: {
|
|
243
|
+
IdentityPoolId: {
|
|
244
|
+
Ref: CognitoIdentityPoolLogicalId
|
|
245
|
+
},
|
|
246
|
+
Roles: {
|
|
247
|
+
authenticated: {
|
|
248
|
+
"Fn::GetAtt": [IdentityPoolAuthenticatedIAMRoleLogicalId, "Arn"]
|
|
140
249
|
},
|
|
141
|
-
|
|
250
|
+
unauthenticated: {
|
|
251
|
+
"Fn::GetAtt": [IdentityPoolUnauthenticatedIAMRoleLogicalId, "Arn"]
|
|
252
|
+
}
|
|
142
253
|
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
145
256
|
if (!template.Outputs) {
|
|
146
257
|
template.Outputs = {};
|
|
147
258
|
}
|