Skip to content

Commit 8968cf4

Browse files
authored
fix: Only first class supported idp providers should be present in the client config (#1683)
1 parent 67da33d commit 8968cf4

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

.changeset/healthy-monkeys-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/client-config': patch
3+
---
4+
5+
fix: Only first class supported idp providers should be present in the client config

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void describe('auth client config contributor v1', () => {
129129
oauthRedirectSignIn: 'http://callback.com,http://callback2.com',
130130
oauthRedirectSignOut: 'http://logout.com,http://logout2.com',
131131
oauthResponseType: 'code',
132-
socialProviders: `["GOOGLE","FACEBOOK"]`,
132+
socialProviders: `["GOOGLE","FACEBOOK","SIGN_IN_WITH_APPLE","LOGIN_WITH_AMAZON","GITHUB","DISCORD"]`,
133133
},
134134
},
135135
}),
@@ -152,7 +152,12 @@ void describe('auth client config contributor v1', () => {
152152
username_attributes: ['email'],
153153
user_verification_types: ['email', 'phone_number'],
154154
oauth: {
155-
identity_providers: ['GOOGLE', 'FACEBOOK'],
155+
identity_providers: [
156+
'GOOGLE',
157+
'FACEBOOK',
158+
'SIGN_IN_WITH_APPLE',
159+
'LOGIN_WITH_AMAZON',
160+
], //Only first class supported idp providers
156161
domain: 'testDomain',
157162
scopes: ['email', 'profile'],
158163
redirect_sign_in_uri: [

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ export class AuthClientConfigContributor implements ClientConfigContributor {
146146
authOutput.payload.oauthRedirectSignIn &&
147147
authOutput.payload.oauthRedirectSignOut
148148
) {
149+
let socialProviders = authOutput.payload.socialProviders
150+
? JSON.parse(authOutput.payload.socialProviders)
151+
: [];
152+
if (Array.isArray(socialProviders)) {
153+
socialProviders = socialProviders.filter(this.isValidIdentityProvider);
154+
}
149155
authClientConfig.auth.oauth = {
150-
identity_providers: authOutput.payload.socialProviders
151-
? JSON.parse(authOutput.payload.socialProviders)
152-
: [],
156+
identity_providers: socialProviders,
153157
redirect_sign_in_uri: authOutput.payload.oauthRedirectSignIn.split(','),
154158
redirect_sign_out_uri:
155159
authOutput.payload.oauthRedirectSignOut.split(','),
@@ -168,6 +172,16 @@ export class AuthClientConfigContributor implements ClientConfigContributor {
168172

169173
return authClientConfig;
170174
};
175+
176+
// Define a type guard function to check if a value is a valid IdentityProvider
177+
isValidIdentityProvider = (identityProvider: string): boolean => {
178+
return [
179+
'GOOGLE',
180+
'FACEBOOK',
181+
'LOGIN_WITH_AMAZON',
182+
'SIGN_IN_WITH_APPLE',
183+
].includes(identityProvider);
184+
};
171185
}
172186

173187
/**

0 commit comments

Comments
 (0)