@@ -1655,6 +1655,163 @@ void describe('Auth construct', () => {
16551655 } ,
16561656 } ) ;
16571657 } ) ;
1658+
1659+ void it ( 'automatically maps email attributes for external providers excluding SAML' , ( ) => {
1660+ const app = new App ( ) ;
1661+ const stack = new Stack ( app ) ;
1662+ new AmplifyAuth ( stack , 'test' , {
1663+ loginWith : {
1664+ email : true ,
1665+ externalProviders : {
1666+ google : {
1667+ clientId : googleClientId ,
1668+ clientSecret : SecretValue . unsafePlainText ( googleClientSecret ) ,
1669+ } ,
1670+ facebook : {
1671+ clientId : facebookClientId ,
1672+ clientSecret : facebookClientSecret ,
1673+ } ,
1674+ signInWithApple : {
1675+ clientId : appleClientId ,
1676+ keyId : appleKeyId ,
1677+ privateKey : applePrivateKey ,
1678+ teamId : appleTeamId ,
1679+ } ,
1680+ loginWithAmazon : {
1681+ clientId : amazonClientId ,
1682+ clientSecret : amazonClientSecret ,
1683+ } ,
1684+ oidc : {
1685+ clientId : oidcClientId ,
1686+ clientSecret : oidcClientSecret ,
1687+ issuerUrl : oidcIssuerUrl ,
1688+ name : oidcProviderName ,
1689+ } ,
1690+ callbackUrls : [ 'https://redirect.com' ] ,
1691+ logoutUrls : [ 'https://logout.com' ] ,
1692+ } ,
1693+ } ,
1694+ } ) ;
1695+ const template = Template . fromStack ( stack ) ;
1696+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
1697+ UsernameAttributes : [ 'email' ] ,
1698+ AutoVerifiedAttributes : [ 'email' ] ,
1699+ } ) ;
1700+ const expectedAutoMappedAttributes = {
1701+ AttributeMapping : {
1702+ // 'email' is a standardized claim for oauth and oidc IDPS
1703+ // so we can map it to cognito's 'email' claim
1704+ email : 'email' ,
1705+ } ,
1706+ } ;
1707+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1708+ ...ExpectedAmazonIDPProperties ,
1709+ ...expectedAutoMappedAttributes ,
1710+ } ) ;
1711+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1712+ ...ExpectedAppleIDPProperties ,
1713+ ...expectedAutoMappedAttributes ,
1714+ } ) ;
1715+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1716+ ...ExpectedFacebookIDPProperties ,
1717+ ...expectedAutoMappedAttributes ,
1718+ } ) ;
1719+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1720+ ...ExpectedGoogleIDPProperties ,
1721+ ...expectedAutoMappedAttributes ,
1722+ } ) ;
1723+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1724+ ...ExpectedOidcIDPProperties ,
1725+ ...expectedAutoMappedAttributes ,
1726+ } ) ;
1727+ template . hasResourceProperties ( 'AWS::Cognito::IdentityPool' , {
1728+ SupportedLoginProviders : {
1729+ 'www.amazon.com' : amazonClientId ,
1730+ 'accounts.google.com' : googleClientId ,
1731+ 'appleid.apple.com' : appleClientId ,
1732+ 'graph.facebook.com' : facebookClientId ,
1733+ } ,
1734+ } ) ;
1735+ } ) ;
1736+ } ) ;
1737+
1738+ void it ( 'does not automatically map email attributes if phone is also enabled' , ( ) => {
1739+ const app = new App ( ) ;
1740+ const stack = new Stack ( app ) ;
1741+ new AmplifyAuth ( stack , 'test' , {
1742+ loginWith : {
1743+ email : true ,
1744+ phone : true , // this makes phone_number a required attribute
1745+ externalProviders : {
1746+ google : {
1747+ clientId : googleClientId ,
1748+ clientSecret : SecretValue . unsafePlainText ( googleClientSecret ) ,
1749+ } ,
1750+ facebook : {
1751+ clientId : facebookClientId ,
1752+ clientSecret : facebookClientSecret ,
1753+ } ,
1754+ signInWithApple : {
1755+ clientId : appleClientId ,
1756+ keyId : appleKeyId ,
1757+ privateKey : applePrivateKey ,
1758+ teamId : appleTeamId ,
1759+ } ,
1760+ loginWithAmazon : {
1761+ clientId : amazonClientId ,
1762+ clientSecret : amazonClientSecret ,
1763+ } ,
1764+ oidc : {
1765+ clientId : oidcClientId ,
1766+ clientSecret : oidcClientSecret ,
1767+ issuerUrl : oidcIssuerUrl ,
1768+ name : oidcProviderName ,
1769+ } ,
1770+ callbackUrls : [ 'https://redirect.com' ] ,
1771+ logoutUrls : [ 'https://logout.com' ] ,
1772+ } ,
1773+ } ,
1774+ } ) ;
1775+ const template = Template . fromStack ( stack ) ;
1776+ template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
1777+ UsernameAttributes : [ 'email' , 'phone_number' ] ,
1778+ AutoVerifiedAttributes : [ 'email' , 'phone_number' ] ,
1779+ } ) ;
1780+ const mappingThatShouldNotExist = {
1781+ AttributeMapping : {
1782+ email : 'email' ,
1783+ } ,
1784+ } ;
1785+ assert . throws ( ( ) => {
1786+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1787+ ...ExpectedAmazonIDPProperties ,
1788+ ...mappingThatShouldNotExist ,
1789+ } ) ;
1790+ } ) ;
1791+ assert . throws ( ( ) => {
1792+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1793+ ...ExpectedAppleIDPProperties ,
1794+ ...mappingThatShouldNotExist ,
1795+ } ) ;
1796+ } ) ;
1797+ assert . throws ( ( ) => {
1798+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1799+ ...ExpectedFacebookIDPProperties ,
1800+ ...mappingThatShouldNotExist ,
1801+ } ) ;
1802+ } ) ;
1803+ assert . throws ( ( ) => {
1804+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1805+ ...ExpectedGoogleIDPProperties ,
1806+ ...mappingThatShouldNotExist ,
1807+ } ) ;
1808+ } ) ;
1809+ assert . throws ( ( ) => {
1810+ template . hasResourceProperties ( 'AWS::Cognito::UserPoolIdentityProvider' , {
1811+ ...ExpectedOidcIDPProperties ,
1812+ ...mappingThatShouldNotExist ,
1813+ } ) ;
1814+ } ) ;
16581815 } ) ;
16591816
16601817 void describe ( 'addTrigger' , ( ) => {
0 commit comments