@@ -103,6 +103,8 @@ export class AmplifyAuth
103103
104104 private readonly oAuthSettings : cognito . OAuthSettings | undefined ;
105105
106+ private readonly name : string ;
107+
106108 /**
107109 * Create a new Auth construct with AuthProps.
108110 * If no props are provided, email login and defaults will be used.
@@ -114,11 +116,13 @@ export class AmplifyAuth
114116 ) {
115117 super ( scope , id ) ;
116118
119+ this . name = props . name ?? '' ;
120+
117121 // UserPool
118122 this . computedUserPoolProps = this . getUserPoolProps ( props ) ;
119123 this . userPool = new cognito . UserPool (
120124 this ,
121- ' UserPool' ,
125+ ` ${ this . name } UserPool` ,
122126 this . computedUserPoolProps
123127 ) ;
124128
@@ -133,7 +137,7 @@ export class AmplifyAuth
133137 this . domainPrefix &&
134138 this . providerSetupResult . providersList . length > 0
135139 ) {
136- this . userPool . addDomain ( ' UserPoolDomain' , {
140+ this . userPool . addDomain ( ` ${ this . name } UserPoolDomain` , {
137141 cognitoDomain : { domainPrefix : this . domainPrefix } ,
138142 } ) ;
139143 } else if (
@@ -174,7 +178,7 @@ export class AmplifyAuth
174178 // UserPool Client
175179 const userPoolClient = new cognito . UserPoolClient (
176180 this ,
177- ' UserPoolAppClient' ,
181+ ` ${ this . name } UserPoolAppClient` ,
178182 {
179183 userPool : this . userPool ,
180184 authFlows : DEFAULTS . AUTH_FLOWS ,
@@ -244,7 +248,7 @@ export class AmplifyAuth
244248 */
245249 private setupAuthAndUnAuthRoles = ( identityPoolId : string ) : DefaultRoles => {
246250 const result : DefaultRoles = {
247- auth : new Role ( this , ' authenticatedUserRole' , {
251+ auth : new Role ( this , ` ${ this . name } authenticatedUserRole` , {
248252 assumedBy : new FederatedPrincipal (
249253 'cognito-identity.amazonaws.com' ,
250254 {
@@ -258,7 +262,7 @@ export class AmplifyAuth
258262 'sts:AssumeRoleWithWebIdentity'
259263 ) ,
260264 } ) ,
261- unAuth : new Role ( this , ' unauthenticatedUserRole' , {
265+ unAuth : new Role ( this , ` ${ this . name } unauthenticatedUserRole` , {
262266 assumedBy : new FederatedPrincipal (
263267 'cognito-identity.amazonaws.com' ,
264268 {
@@ -286,14 +290,19 @@ export class AmplifyAuth
286290 ) => {
287291 // setup identity pool
288292 const region = Stack . of ( this ) . region ;
289- const identityPool = new cognito . CfnIdentityPool ( this , 'IdentityPool' , {
290- allowUnauthenticatedIdentities : DEFAULTS . ALLOW_UNAUTHENTICATED_IDENTITIES ,
291- } ) ;
293+ const identityPool = new cognito . CfnIdentityPool (
294+ this ,
295+ `${ this . name } IdentityPool` ,
296+ {
297+ allowUnauthenticatedIdentities :
298+ DEFAULTS . ALLOW_UNAUTHENTICATED_IDENTITIES ,
299+ }
300+ ) ;
292301 const roles = this . setupAuthAndUnAuthRoles ( identityPool . ref ) ;
293302 const identityPoolRoleAttachment =
294303 new cognito . CfnIdentityPoolRoleAttachment (
295304 this ,
296- ' IdentityPoolRoleAttachment' ,
305+ ` ${ this . name } IdentityPoolRoleAttachment` ,
297306 {
298307 identityPoolId : identityPool . ref ,
299308 roles : {
@@ -602,7 +611,7 @@ export class AmplifyAuth
602611 const googleProps = external . google ;
603612 result . google = new cognito . UserPoolIdentityProviderGoogle (
604613 this ,
605- ' GoogleIdP' ,
614+ ` ${ this . name } GoogleIdP` ,
606615 {
607616 userPool,
608617 clientId : googleProps . clientId ,
@@ -624,7 +633,7 @@ export class AmplifyAuth
624633 if ( external . facebook ) {
625634 result . facebook = new cognito . UserPoolIdentityProviderFacebook (
626635 this ,
627- ' FacebookIDP' ,
636+ ` ${ this . name } FacebookIDP` ,
628637 {
629638 userPool,
630639 ...external . facebook ,
@@ -645,7 +654,7 @@ export class AmplifyAuth
645654 if ( external . loginWithAmazon ) {
646655 result . amazon = new cognito . UserPoolIdentityProviderAmazon (
647656 this ,
648- ' AmazonIDP' ,
657+ ` ${ this . name } AmazonIDP` ,
649658 {
650659 userPool,
651660 ...external . loginWithAmazon ,
@@ -667,7 +676,7 @@ export class AmplifyAuth
667676 if ( external . signInWithApple ) {
668677 result . apple = new cognito . UserPoolIdentityProviderApple (
669678 this ,
670- ' AppleIDP' ,
679+ ` ${ this . name } AppleIDP` ,
671680 {
672681 userPool,
673682 ...external . signInWithApple ,
@@ -687,36 +696,44 @@ export class AmplifyAuth
687696 result . providersList . push ( 'APPLE' ) ;
688697 }
689698 if ( external . oidc ) {
690- result . oidc = new cognito . UserPoolIdentityProviderOidc ( this , 'OidcIDP' , {
691- userPool,
692- ...external . oidc ,
693- attributeMapping :
694- external . oidc . attributeMapping ?? shouldMapEmailAttributes
695- ? {
696- email : {
697- attributeName : 'email' ,
698- } ,
699- }
700- : undefined ,
701- } ) ;
699+ result . oidc = new cognito . UserPoolIdentityProviderOidc (
700+ this ,
701+ `${ this . name } OidcIDP` ,
702+ {
703+ userPool,
704+ ...external . oidc ,
705+ attributeMapping :
706+ external . oidc . attributeMapping ?? shouldMapEmailAttributes
707+ ? {
708+ email : {
709+ attributeName : 'email' ,
710+ } ,
711+ }
712+ : undefined ,
713+ }
714+ ) ;
702715 result . providersList . push ( 'OIDC' ) ;
703716 }
704717 if ( external . saml ) {
705718 const saml = external . saml ;
706- result . saml = new cognito . UserPoolIdentityProviderSaml ( this , 'SamlIDP' , {
707- userPool,
708- attributeMapping : saml . attributeMapping ,
709- identifiers : saml . identifiers ,
710- idpSignout : saml . idpSignout ,
711- metadata : {
712- metadataContent : saml . metadata . metadataContent ,
713- metadataType :
714- saml . metadata . metadataType === 'FILE'
715- ? UserPoolIdentityProviderSamlMetadataType . FILE
716- : UserPoolIdentityProviderSamlMetadataType . URL ,
717- } ,
718- name : saml . name ,
719- } ) ;
719+ result . saml = new cognito . UserPoolIdentityProviderSaml (
720+ this ,
721+ `${ this . name } SamlIDP` ,
722+ {
723+ userPool,
724+ attributeMapping : saml . attributeMapping ,
725+ identifiers : saml . identifiers ,
726+ idpSignout : saml . idpSignout ,
727+ metadata : {
728+ metadataContent : saml . metadata . metadataContent ,
729+ metadataType :
730+ saml . metadata . metadataType === 'FILE'
731+ ? UserPoolIdentityProviderSamlMetadataType . FILE
732+ : UserPoolIdentityProviderSamlMetadataType . URL ,
733+ } ,
734+ name : saml . name ,
735+ }
736+ ) ;
720737 result . providersList . push ( 'SAML' ) ;
721738 }
722739 return result ;
0 commit comments