Skip to content

Commit

Permalink
feat: Support for Apple Sign In (#7265)
Browse files Browse the repository at this point in the history
  • Loading branch information
letsbelopez authored May 12, 2021
1 parent 78854eb commit 9f5e659
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,27 @@ Resources:
- ' let providerCredsIndex = hostedUIProviderCreds.findIndex((provider) => provider.ProviderName === providerName);'
- ' let providerCreds = hostedUIProviderCreds[providerCredsIndex];'
- ' let requestParams = {'
- ' ProviderDetails: {'
- ' ''client_id'': providerCreds.client_id,'
- ' ''client_secret'': providerCreds.client_secret,'
- ' ''authorize_scopes'': providerMeta.authorize_scopes'
- ' },'
- ' ProviderName: providerMeta.ProviderName,'
- ' UserPoolId: userPoolId,'
- ' AttributeMapping: providerMeta.AttributeMapping'
- ' AttributeMapping: providerMeta.AttributeMapping,'
- ' };'
- ' return requestParams;'
- ' let providerDetails;'
- ' if (providerMeta.ProviderName === ''SignInWithApple'') {'
- ' providerDetails = {'
- ' ''client_id'': providerCreds.client_id,'
- ' ''team_id'': providerCreds.team_id,'
- ' ''key_id'': providerCreds.key_id,'
- ' ''private_key'': providerCreds.private_key,'
- ' ''authorize_scopes'': providerMeta.authorize_scopes,'
- ' };'
- ' } else {'
- ' providerDetails = {'
- ' ''client_id'': providerCreds.client_id,'
- ' ''client_secret'': providerCreds.client_secret,'
- ' ''authorize_scopes'': providerMeta.authorize_scopes,'
- ' };'
- ' }'
- ' return { ProviderDetails: providerDetails, ...requestParams };'
- ' };'
- ' let createIdentityProvider = (providerName) => {'
- ' let requestParams = getRequestParams(providerName);'
Expand Down Expand Up @@ -1112,6 +1123,9 @@ Resources:
<%if (props.authProviders.indexOf('www.amazon.com') !== -1) { %>
www.amazon.com: !Ref amazonAppId
<% } %>
<%if (props.authProviders.indexOf('appleid.apple.com') !== -1) { %>
appleid.apple.com: !Ref appleAppId
<% } %>
<% } %>
AllowUnauthenticatedIdentities: !Ref allowUnauthenticatedIdentities
<%if (props.audiences && props.audiences.length > 0) { %>
Expand Down Expand Up @@ -1194,4 +1208,8 @@ Outputs :
AmazonWebClient:
Value: !Ref amazonAppId
<% } %>
<%if (props.appleAppId) { %>
AppleWebClient:
Value: !Ref appleAppId
<% } %>
<% } %>
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const attributeProviderMap = {
facebook: {},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
birthdate: {
facebook: {
Expand All @@ -147,6 +148,7 @@ const attributeProviderMap = {
scope: 'profile',
},
loginwithamazon: {},
signinwithapple: {},
},
email: {
facebook: {
Expand All @@ -161,6 +163,10 @@ const attributeProviderMap = {
attr: 'email',
scope: 'profile',
},
signinwithapple: {
attr: 'email',
scope: 'email',
},
},
family_name: {
facebook: {
Expand All @@ -172,6 +178,10 @@ const attributeProviderMap = {
scope: 'profile',
},
loginwithamazon: {},
signinwithapple: {
attr: 'lastName',
scope: 'name',
},
},
gender: {
facebook: {
Expand All @@ -183,6 +193,7 @@ const attributeProviderMap = {
scope: 'profile',
},
loginwithamazon: {},
signinwithapple: {},
},
given_name: {
facebook: {
Expand All @@ -194,6 +205,10 @@ const attributeProviderMap = {
scope: 'profile',
},
loginwithamazon: {},
signinwithapple: {
attr: 'firstName',
scope: 'name',
},
},
locale: {
facebook: {},
Expand All @@ -202,6 +217,7 @@ const attributeProviderMap = {
attr: 'postal_code',
scope: 'postal_code',
},
signinwithapple: {},
},
middle_name: {
facebook: {
Expand All @@ -210,6 +226,7 @@ const attributeProviderMap = {
},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
name: {
facebook: {
Expand All @@ -224,11 +241,13 @@ const attributeProviderMap = {
attr: 'name',
scope: 'profile',
},
signinwithapple: {},
},
nickname: {
facebook: {},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
phone_number: {
facebook: {},
Expand All @@ -237,6 +256,7 @@ const attributeProviderMap = {
scope: 'profile',
},
loginwithamazon: {},
signinwithapple: {},
},
picture: {
facebook: {
Expand All @@ -248,26 +268,31 @@ const attributeProviderMap = {
scope: 'profile',
},
loginwithamazon: {},
signinwithapple: {},
},
preferred_username: {
facebook: {},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
profile: {
facebook: {},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
zoneinfo: {
facebook: {},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
website: {
facebook: {},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
username: {
facebook: {
Expand All @@ -282,6 +307,7 @@ const attributeProviderMap = {
attr: 'user_id',
scope: 'profile:user_id',
},
signinwithapple: {},
},
updated_at: {
facebook: {
Expand All @@ -290,6 +316,7 @@ const attributeProviderMap = {
},
google: {},
loginwithamazon: {},
signinwithapple: {},
},
};

Expand Down Expand Up @@ -392,6 +419,11 @@ const authProviders = [
value: 'www.amazon.com',
answerHashKey: 'amazonAppId',
},
{
name: 'Apple',
value: 'appleid.apple.com',
answerHashKey: 'appleAppId',
},
];

const hostedUIProviders = [
Expand All @@ -407,6 +439,10 @@ const hostedUIProviders = [
name: 'Login With Amazon',
value: 'LoginWithAmazon',
},
{
name: 'Sign in with Apple',
value: 'SignInWithApple',
},
];

const authorizeScopes = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const ENV_SPECIFIC_PARAMS = [
'amazonAppId',
'loginwithamazonAppIdUserPool',
'loginwithamazonAppSecretUserPool',
'signinwithappleClientIdUserPool',
'signinwithappleTeamIdUserPool',
'signinwithappleKeyIdUserPool',
'signinwithapplePrivateKeyUserPool',
'hostedUIProviderCreds',
];

Expand Down Expand Up @@ -55,6 +59,10 @@ export const privateKeys = [
'loginwithamazonAppIdUserPool',
'loginwithamazonAuthorizeScopes',
'loginwithamazonAppSecretUserPool',
'signinwithappleClientIdUserPool',
'signinwithappleTeamIdUserPool',
'signinwithappleKeyIdUserPool',
'signinwithapplePrivateKeyUserPool',
'CallbackURLs',
'LogoutURLs',
'AllowedOAuthFlows',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { importMessages } from './messages';
import uuid from 'uuid';

// Currently the CLI only supports the output generation of these providers
const supportedIdentityProviders = ['COGNITO', 'Facebook', 'Google', 'LoginWithAmazon'];
const supportedIdentityProviders = ['COGNITO', 'Facebook', 'Google', 'LoginWithAmazon', 'SignInWithApple'];

export const importResource = async (
context: $TSContext,
Expand Down Expand Up @@ -752,6 +752,9 @@ const createMetaOutput = (answers: ImportAnswers, hasOAuthConfig: boolean): Meta
case 'accounts.google.com':
output.GoogleWebClient = answers.identityPool!.SupportedLoginProviders![key];
break;
case 'appleid.apple.com':
output.AppleWebClient = answers.identityPool!.SupportedLoginProviders![key];
break;
default:
// We don't do anything with the providers that the CLI currently does not support.
break;
Expand Down Expand Up @@ -815,6 +818,9 @@ const createEnvSpecificResourceParameters = (
case 'graph.facebook.com':
envSpecificResourceParameters.facebookAppId = answers.identityPool!.SupportedLoginProviders![key];
break;
case 'appleid.apple.com':
envSpecificResourceParameters.appleAppId = answers.identityPool!.SupportedLoginProviders![key];
break;
case 'accounts.google.com': {
switch (projectType) {
case 'javascript':
Expand All @@ -840,11 +846,23 @@ const createEnvSpecificResourceParameters = (
};

const createOAuthCredentials = (identityProviders: IdentityProviderType[]): string => {
const credentials = identityProviders.map(idp => ({
ProviderName: idp.ProviderName!,
client_id: idp.ProviderDetails!.client_id,
client_secret: idp.ProviderDetails!.client_secret,
}));
const credentials = identityProviders.map(idp => {
if (idp.ProviderName === 'SignInWithApple') {
return {
ProviderName: idp.ProviderName!,
client_id: idp.ProviderDetails!.client_id,
team_id: idp.ProviderDetails!.team_id,
key_id: idp.ProviderDetails!.key_id,
private_key: idp.ProviderDetails!.private_key,
};
} else {
return {
ProviderName: idp.ProviderName!,
client_id: idp.ProviderDetails!.client_id,
client_secret: idp.ProviderDetails!.client_secret,
};
}
});

return JSON.stringify(credentials);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type MetaOutput = {
AmazonWebClient?: string;
FacebookWebClient?: string;
GoogleWebClient?: string;
AppleWebClient?: string;
HostedUIDomain?: string;
OAuthMetadata?: string;
CreatedSNSRole?: string;
Expand All @@ -59,6 +60,7 @@ export type EnvSpecificResourceParameters = {
identityPoolName?: string;
facebookAppId?: string;
amazonAppId?: string;
appleAppId?: string;
googleIos?: string;
googleAndroid?: string;
googleClientId?: string;
Expand Down
Loading

0 comments on commit 9f5e659

Please sign in to comment.