Skip to content

Commit 618a2ea

Browse files
authored
Add allowUnauthenticatedIdentities to front-end config (#924)
* fix: add allowUnauthenticatedIdentities to front end config * chore: cleanup * fix: use === instead of == * fix: make property optional in output * chore: update api * fix: front end config tests * chore: update api
1 parent f8112b6 commit 618a2ea

File tree

11 files changed

+69
-2
lines changed

11 files changed

+69
-2
lines changed

.changeset/purple-cherries-cry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@aws-amplify/backend-output-schemas': patch
3+
'@aws-amplify/auth-construct-alpha': patch
4+
'@aws-amplify/client-config': patch
5+
---
6+
7+
Add allowUnauthenticatedIdentities to config output.

packages/auth-construct/src/construct.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ void describe('Auth construct', () => {
501501
signupAttributes: '["EMAIL"]',
502502
verificationMechanisms: '["EMAIL"]',
503503
usernameAttributes: '["EMAIL"]',
504+
allowUnauthenticatedIdentities: 'true',
504505
},
505506
},
506507
]);
@@ -561,6 +562,7 @@ void describe('Auth construct', () => {
561562
oauthRedirectSignOut: 'http://logout.com',
562563
oauthResponseType: 'code',
563564
socialProviders: '["GOOGLE"]',
565+
allowUnauthenticatedIdentities: 'true',
564566
},
565567
},
566568
]);
@@ -634,6 +636,7 @@ void describe('Auth construct', () => {
634636
'webClientId',
635637
'identityPoolId',
636638
'authRegion',
639+
'allowUnauthenticatedIdentities',
637640
'signupAttributes',
638641
'usernameAttributes',
639642
'verificationMechanisms',

packages/auth-construct/src/construct.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,12 @@ export class AmplifyAuth
707707
webClientId: this.resources.userPoolClient.userPoolClientId,
708708
identityPoolId: this.resources.cfnResources.cfnIdentityPool.ref,
709709
authRegion: Stack.of(this).region,
710+
allowUnauthenticatedIdentities:
711+
this.resources.cfnResources.cfnIdentityPool
712+
.allowUnauthenticatedIdentities === true
713+
? 'true'
714+
: 'false',
710715
};
711-
712716
if (this.computedUserPoolProps.standardAttributes) {
713717
const signupAttributes = Object.entries(
714718
this.computedUserPoolProps.standardAttributes

packages/backend-output-schemas/API.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
104104
appleClientId: z.ZodOptional<z.ZodString>;
105105
facebookClientId: z.ZodOptional<z.ZodString>;
106106
googleClientId: z.ZodOptional<z.ZodString>;
107+
allowUnauthenticatedIdentities: z.ZodOptional<z.ZodString>;
107108
usernameAttributes: z.ZodOptional<z.ZodString>;
108109
signupAttributes: z.ZodOptional<z.ZodString>;
109110
passwordPolicyMinLength: z.ZodOptional<z.ZodString>;
@@ -113,7 +114,9 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
113114
verificationMechanisms: z.ZodOptional<z.ZodString>;
114115
socialProviders: z.ZodOptional<z.ZodString>;
115116
oauthDomain: z.ZodOptional<z.ZodString>;
116-
oauthScope: z.ZodOptional<z.ZodString>;
117+
oauthScope: z.ZodOptional<z.ZodString>; /**
118+
* re-export the storage output schema
119+
*/
117120
oauthRedirectSignIn: z.ZodOptional<z.ZodString>;
118121
oauthRedirectSignOut: z.ZodOptional<z.ZodString>;
119122
oauthClientId: z.ZodOptional<z.ZodString>;
@@ -127,6 +130,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
127130
appleClientId?: string | undefined;
128131
facebookClientId?: string | undefined;
129132
googleClientId?: string | undefined;
133+
allowUnauthenticatedIdentities?: string | undefined;
130134
usernameAttributes?: string | undefined;
131135
signupAttributes?: string | undefined;
132136
passwordPolicyMinLength?: string | undefined;
@@ -150,6 +154,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
150154
appleClientId?: string | undefined;
151155
facebookClientId?: string | undefined;
152156
googleClientId?: string | undefined;
157+
allowUnauthenticatedIdentities?: string | undefined;
153158
usernameAttributes?: string | undefined;
154159
signupAttributes?: string | undefined;
155160
passwordPolicyMinLength?: string | undefined;
@@ -176,6 +181,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
176181
appleClientId?: string | undefined;
177182
facebookClientId?: string | undefined;
178183
googleClientId?: string | undefined;
184+
allowUnauthenticatedIdentities?: string | undefined;
179185
usernameAttributes?: string | undefined;
180186
signupAttributes?: string | undefined;
181187
passwordPolicyMinLength?: string | undefined;
@@ -202,6 +208,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
202208
appleClientId?: string | undefined;
203209
facebookClientId?: string | undefined;
204210
googleClientId?: string | undefined;
211+
allowUnauthenticatedIdentities?: string | undefined;
205212
usernameAttributes?: string | undefined;
206213
signupAttributes?: string | undefined;
207214
passwordPolicyMinLength?: string | undefined;
@@ -317,6 +324,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
317324
appleClientId?: string | undefined;
318325
facebookClientId?: string | undefined;
319326
googleClientId?: string | undefined;
327+
allowUnauthenticatedIdentities?: string | undefined;
320328
usernameAttributes?: string | undefined;
321329
signupAttributes?: string | undefined;
322330
passwordPolicyMinLength?: string | undefined;
@@ -372,6 +380,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
372380
appleClientId?: string | undefined;
373381
facebookClientId?: string | undefined;
374382
googleClientId?: string | undefined;
383+
allowUnauthenticatedIdentities?: string | undefined;
375384
usernameAttributes?: string | undefined;
376385
signupAttributes?: string | undefined;
377386
passwordPolicyMinLength?: string | undefined;
@@ -422,6 +431,7 @@ export const versionedAuthOutputSchema: z.ZodDiscriminatedUnion<"version", [z.Zo
422431
appleClientId: z.ZodOptional<z.ZodString>;
423432
facebookClientId: z.ZodOptional<z.ZodString>;
424433
googleClientId: z.ZodOptional<z.ZodString>;
434+
allowUnauthenticatedIdentities: z.ZodOptional<z.ZodString>;
425435
usernameAttributes: z.ZodOptional<z.ZodString>;
426436
signupAttributes: z.ZodOptional<z.ZodString>;
427437
passwordPolicyMinLength: z.ZodOptional<z.ZodString>;
@@ -445,6 +455,7 @@ export const versionedAuthOutputSchema: z.ZodDiscriminatedUnion<"version", [z.Zo
445455
appleClientId?: string | undefined;
446456
facebookClientId?: string | undefined;
447457
googleClientId?: string | undefined;
458+
allowUnauthenticatedIdentities?: string | undefined;
448459
usernameAttributes?: string | undefined;
449460
signupAttributes?: string | undefined;
450461
passwordPolicyMinLength?: string | undefined;
@@ -468,6 +479,7 @@ export const versionedAuthOutputSchema: z.ZodDiscriminatedUnion<"version", [z.Zo
468479
appleClientId?: string | undefined;
469480
facebookClientId?: string | undefined;
470481
googleClientId?: string | undefined;
482+
allowUnauthenticatedIdentities?: string | undefined;
471483
usernameAttributes?: string | undefined;
472484
signupAttributes?: string | undefined;
473485
passwordPolicyMinLength?: string | undefined;
@@ -494,6 +506,7 @@ export const versionedAuthOutputSchema: z.ZodDiscriminatedUnion<"version", [z.Zo
494506
appleClientId?: string | undefined;
495507
facebookClientId?: string | undefined;
496508
googleClientId?: string | undefined;
509+
allowUnauthenticatedIdentities?: string | undefined;
497510
usernameAttributes?: string | undefined;
498511
signupAttributes?: string | undefined;
499512
passwordPolicyMinLength?: string | undefined;
@@ -520,6 +533,7 @@ export const versionedAuthOutputSchema: z.ZodDiscriminatedUnion<"version", [z.Zo
520533
appleClientId?: string | undefined;
521534
facebookClientId?: string | undefined;
522535
googleClientId?: string | undefined;
536+
allowUnauthenticatedIdentities?: string | undefined;
523537
usernameAttributes?: string | undefined;
524538
signupAttributes?: string | undefined;
525539
passwordPolicyMinLength?: string | undefined;

packages/backend-output-schemas/src/auth/v1.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const authOutputSchema = z.object({
1313
facebookClientId: z.optional(z.string()),
1414
googleClientId: z.optional(z.string()),
1515

16+
allowUnauthenticatedIdentities: z.optional(z.string()), // boolean as string 'true' | 'false'
17+
1618
usernameAttributes: z.string().optional(), // JSON array as string
1719
signupAttributes: z.string().optional(), // JSON array as string
1820
passwordPolicyMinLength: z.string().optional(),

packages/client-config/API.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type AuthClientConfig = {
2424
};
2525
aws_cognito_verification_mechanisms?: string[];
2626
aws_cognito_social_providers?: string[];
27+
allowUnauthenticatedIdentities?: string;
2728
oauth?: {
2829
domain?: string;
2930
scope?: string[];

packages/client-config/src/client-config-contributor/auth_client_config_contributor.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ void describe('AuthClientConfigContributor', () => {
2929
});
3030

3131
void it('returns translated config when output has auth', () => {
32+
const contributor = new AuthClientConfigContributor();
33+
assert.deepStrictEqual(
34+
contributor.contribute({
35+
[authOutputKey]: {
36+
version: '1',
37+
payload: {
38+
identityPoolId: 'testIdentityPoolId',
39+
userPoolId: 'testUserPoolId',
40+
webClientId: 'testWebClientId',
41+
authRegion: 'testRegion',
42+
allowUnauthenticatedIdentities: 'true',
43+
},
44+
},
45+
}),
46+
{
47+
aws_user_pools_id: 'testUserPoolId',
48+
aws_user_pools_web_client_id: 'testWebClientId',
49+
aws_cognito_region: 'testRegion',
50+
aws_cognito_identity_pool_id: 'testIdentityPoolId',
51+
allowUnauthenticatedIdentities: 'true',
52+
}
53+
);
54+
});
55+
56+
void it('returns translated config without requiring allowUnauthenticatedIdentities', () => {
3257
const contributor = new AuthClientConfigContributor();
3358
assert.deepStrictEqual(
3459
contributor.contribute({
@@ -70,6 +95,7 @@ void describe('AuthClientConfigContributor', () => {
7095
verificationMechanisms: '["EMAIL","PHONE"]',
7196
usernameAttributes: '["EMAIL"]',
7297
signupAttributes: '["EMAIL"]',
98+
allowUnauthenticatedIdentities: 'true',
7399
},
74100
},
75101
}),
@@ -91,6 +117,7 @@ void describe('AuthClientConfigContributor', () => {
91117
aws_cognito_signup_attributes: ['EMAIL'],
92118
aws_cognito_username_attributes: ['EMAIL'],
93119
aws_cognito_verification_mechanisms: ['EMAIL', 'PHONE'],
120+
allowUnauthenticatedIdentities: 'true',
94121
}
95122
);
96123
});

packages/client-config/src/client-config-contributor/auth_client_config_contributor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export class AuthClientConfigContributor implements ClientConfigContributor {
3535
aws_user_pools_web_client_id: authOutput.payload.webClientId,
3636
aws_cognito_identity_pool_id: authOutput.payload.identityPoolId,
3737
};
38+
if (authOutput.payload.allowUnauthenticatedIdentities !== undefined) {
39+
authClientConfig.allowUnauthenticatedIdentities =
40+
authOutput.payload.allowUnauthenticatedIdentities;
41+
}
3842

3943
parseAndAssignObject(
4044
authClientConfig,

packages/client-config/src/client-config-contributor/graphql_client_config_contributor.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void describe('GraphqlClientConfigContributor', () => {
2828
userPoolId: 'stuff',
2929
authRegion: 'testRegion ',
3030
webClientId: 'clientId',
31+
allowUnauthenticatedIdentities: 'true',
3132
},
3233
},
3334
});

packages/client-config/src/client-config-types/auth_client_config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export type AuthClientConfig = {
2121

2222
aws_cognito_social_providers?: string[];
2323

24+
allowUnauthenticatedIdentities?: string;
25+
2426
oauth?: {
2527
domain?: string;
2628
scope?: string[];

0 commit comments

Comments
 (0)