@ttoss/cloud-auth 0.6.4 → 0.7.0

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.
@@ -28,10 +28,10 @@ BRH:4
28
28
  end_of_record
29
29
  TN:
30
30
  SF:src/template.ts
31
- FN:16,createAuthTemplate
31
+ FN:22,createAuthTemplate
32
32
  FNF:1
33
33
  FNH:1
34
- FNDA:12,createAuthTemplate
34
+ FNDA:11,createAuthTemplate
35
35
  DA:1,1
36
36
  DA:2,1
37
37
  DA:3,1
@@ -48,140 +48,140 @@ DA:13,1
48
48
  DA:14,1
49
49
  DA:15,1
50
50
  DA:16,1
51
- DA:17,12
52
- DA:18,12
53
- DA:19,12
54
- DA:20,12
55
- DA:21,12
56
- DA:22,12
57
- DA:23,12
58
- DA:24,12
59
- DA:25,12
60
- DA:26,12
61
- DA:27,12
62
- DA:28,12
63
- DA:29,12
64
- DA:30,12
65
- DA:31,12
66
- DA:32,12
67
- DA:33,12
68
- DA:34,12
69
- DA:35,12
70
- DA:36,12
71
- DA:37,12
72
- DA:38,12
73
- DA:39,12
74
- DA:40,12
75
- DA:41,12
76
- DA:42,12
77
- DA:43,12
78
- DA:44,12
79
- DA:45,12
80
- DA:46,12
81
- DA:47,12
82
- DA:48,12
83
- DA:49,12
84
- DA:50,12
85
- DA:51,9
86
- DA:52,12
87
- DA:53,12
88
- DA:54,12
89
- DA:55,12
90
- DA:56,12
91
- DA:57,12
92
- DA:58,12
93
- DA:59,12
94
- DA:60,12
95
- DA:61,12
96
- DA:62,12
97
- DA:63,12
98
- DA:64,12
99
- DA:65,12
100
- DA:66,12
101
- DA:67,12
102
- DA:68,12
103
- DA:69,12
104
- DA:70,12
105
- DA:71,12
106
- DA:72,12
107
- DA:73,12
108
- DA:74,12
109
- DA:75,12
110
- DA:76,12
111
- DA:77,12
112
- DA:78,12
113
- DA:79,12
114
- DA:80,12
115
- DA:81,12
116
- DA:82,12
117
- DA:83,12
118
- DA:84,12
119
- DA:85,12
120
- DA:86,12
121
- DA:87,12
122
- DA:88,12
123
- DA:89,12
124
- DA:90,12
125
- DA:91,12
126
- DA:92,12
127
- DA:93,12
128
- DA:94,12
129
- DA:95,12
130
- DA:96,12
131
- DA:97,12
132
- DA:98,12
133
- DA:99,12
134
- DA:100,12
135
- DA:101,12
136
- DA:102,12
137
- DA:103,12
138
- DA:104,12
139
- DA:105,12
140
- DA:106,12
141
- DA:107,12
142
- DA:108,12
143
- DA:109,12
144
- DA:110,12
145
- DA:111,12
146
- DA:112,12
147
- DA:113,12
148
- DA:114,12
149
- DA:115,12
150
- DA:116,12
151
- DA:117,12
152
- DA:118,12
153
- DA:119,12
154
- DA:120,12
155
- DA:121,12
156
- DA:122,12
157
- DA:123,12
158
- DA:124,12
159
- DA:125,12
160
- DA:126,12
161
- DA:127,12
162
- DA:128,12
163
- DA:129,12
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
+ DA:23,11
58
+ DA:24,11
59
+ DA:25,11
60
+ DA:26,11
61
+ DA:27,11
62
+ DA:28,11
63
+ DA:29,11
64
+ DA:30,11
65
+ DA:31,11
66
+ DA:32,11
67
+ DA:33,11
68
+ DA:34,11
69
+ DA:35,11
70
+ DA:36,11
71
+ DA:37,11
72
+ DA:38,11
73
+ DA:39,11
74
+ DA:40,11
75
+ DA:41,11
76
+ DA:42,11
77
+ DA:43,11
78
+ DA:44,11
79
+ DA:45,11
80
+ DA:46,11
81
+ DA:47,11
82
+ DA:48,11
83
+ DA:49,11
84
+ DA:50,11
85
+ DA:51,11
86
+ DA:52,11
87
+ DA:53,11
88
+ DA:54,11
89
+ DA:55,11
90
+ DA:56,8
91
+ DA:57,11
92
+ DA:58,11
93
+ DA:59,11
94
+ DA:60,11
95
+ DA:61,11
96
+ DA:62,11
97
+ DA:63,11
98
+ DA:64,11
99
+ DA:65,11
100
+ DA:66,11
101
+ DA:67,11
102
+ DA:68,11
103
+ DA:69,11
104
+ DA:70,11
105
+ DA:71,11
106
+ DA:72,11
107
+ DA:73,11
108
+ DA:74,11
109
+ DA:75,11
110
+ DA:76,11
111
+ DA:77,11
112
+ DA:78,11
113
+ DA:79,11
114
+ DA:80,11
115
+ DA:81,11
116
+ DA:82,11
117
+ DA:83,11
118
+ DA:84,11
119
+ DA:85,11
120
+ DA:86,11
121
+ DA:87,11
122
+ DA:88,11
123
+ DA:89,11
124
+ DA:90,11
125
+ DA:91,11
126
+ DA:92,11
127
+ DA:93,11
128
+ DA:94,11
129
+ DA:95,11
130
+ DA:96,11
131
+ DA:97,11
132
+ DA:98,11
133
+ DA:99,11
134
+ DA:100,11
135
+ DA:101,11
136
+ DA:102,11
137
+ DA:103,11
138
+ DA:104,11
139
+ DA:105,11
140
+ DA:106,11
141
+ DA:107,11
142
+ DA:108,11
143
+ DA:109,11
144
+ DA:110,11
145
+ DA:111,11
146
+ DA:112,11
147
+ DA:113,11
148
+ DA:114,11
149
+ DA:115,11
150
+ DA:116,11
151
+ DA:117,11
152
+ DA:118,11
153
+ DA:119,11
154
+ DA:120,11
155
+ DA:121,11
156
+ DA:122,11
157
+ DA:123,11
158
+ DA:124,11
159
+ DA:125,11
160
+ DA:126,11
161
+ DA:127,11
162
+ DA:128,11
163
+ DA:129,11
164
164
  DA:130,11
165
165
  DA:131,11
166
166
  DA:132,11
167
167
  DA:133,11
168
- DA:134,11
169
- DA:135,11
170
- DA:136,11
171
- DA:137,11
172
- DA:138,11
173
- DA:139,11
174
- DA:140,11
175
- DA:141,11
176
- DA:142,11
177
- DA:143,11
178
- DA:144,11
179
- DA:145,11
180
- DA:146,11
181
- DA:147,11
182
- DA:148,11
183
- DA:149,11
184
- DA:150,11
168
+ DA:134,1
169
+ DA:135,1
170
+ DA:136,1
171
+ DA:137,1
172
+ DA:138,0
173
+ DA:139,0
174
+ DA:140,0
175
+ DA:141,0
176
+ DA:142,0
177
+ DA:143,1
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,163 @@ DA:160,1
195
195
  DA:161,1
196
196
  DA:162,1
197
197
  DA:163,1
198
- DA:164,11
199
- DA:165,11
200
- DA:166,0
201
- DA:167,0
202
- DA:168,11
203
- DA:169,11
204
- DA:170,11
205
- DA:171,11
206
- DA:172,11
207
- DA:173,11
208
- DA:174,11
209
- DA:175,11
210
- DA:176,11
211
- DA:177,11
212
- DA:178,11
213
- DA:179,11
214
- DA:180,11
215
- DA:181,11
216
- DA:182,11
217
- DA:183,11
218
- DA:184,12
219
- DA:185,12
220
- DA:186,12
221
- DA:187,1
222
- DA:188,1
223
- DA:189,1
224
- DA:190,1
225
- DA:191,1
226
- LF:191
227
- LH:189
228
- BRDA:16,0,0,12
229
- BRDA:50,1,0,10
230
- BRDA:51,2,0,9
231
- BRDA:52,3,0,3
232
- BRDA:129,4,0,11
233
- BRDA:150,5,0,1
234
- BRDA:165,6,0,0
235
- BRF:7
236
- BRH:6
198
+ DA:164,1
199
+ DA:165,1
200
+ DA:166,11
201
+ DA:167,11
202
+ DA:168,2
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,0
318
+ DA:284,0
319
+ DA:285,2
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,11
336
+ DA:302,11
337
+ DA:303,11
338
+ DA:304,1
339
+ DA:305,1
340
+ DA:306,1
341
+ DA:307,1
342
+ DA:308,1
343
+ LF:308
344
+ LH:301
345
+ BRDA:22,0,0,11
346
+ BRDA:55,1,0,9
347
+ BRDA:56,2,0,8
348
+ BRDA:57,3,0,3
349
+ BRDA:133,4,0,1
350
+ BRDA:167,5,0,4
351
+ BRDA:167,6,0,2
352
+ BRDA:282,7,0,0
353
+ BRDA:134,8,0,1
354
+ BRDA:137,9,0,0
355
+ BRF:10
356
+ BRH:8
237
357
  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 = true,
13
- roles,
19
+ identityPool,
14
20
  schema,
15
21
  usernameAttributes = ["email"]
16
22
  } = {}) => {
@@ -32,7 +38,6 @@ var createAuthTemplate = ({
32
38
  TemporaryPasswordValidityDays: 30
33
39
  }
34
40
  },
35
- Schema: schema,
36
41
  UsernameAttributes: usernameAttributes,
37
42
  UsernameConfiguration: {
38
43
  CaseSensitive: false
@@ -88,7 +93,35 @@ var createAuthTemplate = ({
88
93
  }
89
94
  }
90
95
  };
91
- if (identityPool) {
96
+ if (schema) {
97
+ const Schema = schema.map((attribute) => {
98
+ let NumberAttributeConstraints = void 0;
99
+ if (attribute.numberAttributeConstraints) {
100
+ NumberAttributeConstraints = {
101
+ MaxValue: attribute.numberAttributeConstraints?.maxValue,
102
+ MinValue: attribute.numberAttributeConstraints?.minValue
103
+ };
104
+ }
105
+ let StringAttributeConstraints = void 0;
106
+ if (attribute.stringAttributeConstraints) {
107
+ StringAttributeConstraints = {
108
+ MaxLength: attribute.stringAttributeConstraints?.maxLength,
109
+ MinLength: attribute.stringAttributeConstraints?.minLength
110
+ };
111
+ }
112
+ return {
113
+ AttributeDataType: attribute.attributeDataType,
114
+ DeveloperOnlyAttribute: attribute.developerOnlyAttribute,
115
+ Mutable: attribute.mutable,
116
+ Name: attribute.name,
117
+ NumberAttributeConstraints,
118
+ Required: attribute.required,
119
+ StringAttributeConstraints
120
+ };
121
+ });
122
+ template.Resources[CognitoUserPoolLogicalId].Properties.Schema = Schema;
123
+ }
124
+ if (identityPool?.enabled) {
92
125
  template.Resources[CognitoIdentityPoolLogicalId] = {
93
126
  Type: "AWS::Cognito::IdentityPool",
94
127
  Properties: {
@@ -105,17 +138,94 @@ var createAuthTemplate = ({
105
138
  ]
106
139
  }
107
140
  };
108
- if (roles) {
109
- template.Resources.CognitoIdentityPoolRoleAttachment = {
110
- Type: "AWS::Cognito::IdentityPoolRoleAttachment",
111
- Properties: {
112
- IdentityPoolId: {
113
- Ref: CognitoIdentityPoolLogicalId
141
+ template.Resources[IdentityPoolAuthenticatedIAMRoleLogicalId] = {
142
+ Type: "AWS::IAM::Role",
143
+ Properties: {
144
+ AssumeRolePolicyDocument: {
145
+ Version: "2012-10-17",
146
+ Statement: [
147
+ {
148
+ Effect: "Allow",
149
+ Principal: {
150
+ Federated: "cognito-identity.amazonaws.com"
151
+ },
152
+ Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
153
+ Condition: {
154
+ StringEquals: {
155
+ "cognito-identity.amazonaws.com:aud": {
156
+ Ref: CognitoIdentityPoolLogicalId
157
+ }
158
+ },
159
+ "ForAnyValue:StringLike": {
160
+ "cognito-identity.amazonaws.com:amr": "authenticated"
161
+ }
162
+ }
163
+ }
164
+ ]
165
+ },
166
+ Policies: identityPool.authenticatedPolicies || [
167
+ {
168
+ PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
169
+ PolicyDocument: {
170
+ Version: "2012-10-17",
171
+ Statement: [DenyStatement]
172
+ }
173
+ }
174
+ ]
175
+ }
176
+ };
177
+ template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
178
+ Type: "AWS::IAM::Role",
179
+ Properties: {
180
+ AssumeRolePolicyDocument: {
181
+ Version: "2012-10-17",
182
+ Statement: [
183
+ {
184
+ Effect: "Allow",
185
+ Principal: {
186
+ Federated: "cognito-identity.amazonaws.com"
187
+ },
188
+ Action: "sts:AssumeRoleWithWebIdentity",
189
+ Condition: {
190
+ StringEquals: {
191
+ "cognito-identity.amazonaws.com:aud": {
192
+ Ref: CognitoIdentityPoolLogicalId
193
+ }
194
+ },
195
+ "ForAnyValue:StringLike": {
196
+ "cognito-identity.amazonaws.com:amr": "unauthenticated"
197
+ }
198
+ }
199
+ }
200
+ ]
201
+ },
202
+ Policies: identityPool.authenticatedPolicies || [
203
+ {
204
+ PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
205
+ PolicyDocument: {
206
+ Version: "2012-10-17",
207
+ Statement: [DenyStatement]
208
+ }
209
+ }
210
+ ]
211
+ }
212
+ };
213
+ template.Resources.CognitoIdentityPoolRoleAttachment = {
214
+ Type: "AWS::Cognito::IdentityPoolRoleAttachment",
215
+ Properties: {
216
+ IdentityPoolId: {
217
+ Ref: CognitoIdentityPoolLogicalId
218
+ },
219
+ Roles: {
220
+ authenticated: {
221
+ "Fn::GetAtt": [IdentityPoolAuthenticatedIAMRoleLogicalId, "Arn"]
114
222
  },
115
- Roles: roles
223
+ unauthenticated: {
224
+ "Fn::GetAtt": [IdentityPoolUnauthenticatedIAMRoleLogicalId, "Arn"]
225
+ }
116
226
  }
117
- };
118
- }
227
+ }
228
+ };
119
229
  if (!template.Outputs) {
120
230
  template.Outputs = {};
121
231
  }
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, roles, schema, usernameAttributes, }?: {
6
+ ({ autoVerifiedAttributes, identityPool, schema, usernameAttributes, }?: {
10
7
  autoVerifiedAttributes?: false | ("email" | "phone_number")[] | null | undefined;
11
- identityPool?: boolean | undefined;
12
- roles?: {
13
- authenticated?: Role | undefined;
14
- unauthenticated?: Role | undefined;
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
- AttributeDataType?: "Boolean" | "DateTime" | "Number" | "String" | undefined;
21
- DeveloperOnlyAttribute?: boolean | undefined;
22
- Mutable?: boolean | undefined;
23
- Name?: string | undefined;
24
- NumberAttributeConstraints?: {
25
- MaxValue?: string | undefined;
26
- MinValue?: string | undefined;
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
- Required?: boolean | undefined;
29
- StringAttributeConstraints?: {
30
- MaxLength: string;
31
- MinLength: string;
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;