Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release(required): Parsing custom oAuth in amplify_outputs #13474

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
"name": "[Analytics] identifyUser (Pinpoint)",
"path": "./dist/esm/analytics/index.mjs",
"import": "{ identifyUser }",
"limit": "15.57 kB"
"limit": "15.58 kB"
},
{
"name": "[Analytics] enable",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/__mocks__/configMocks/amplify_outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"user_pool_client_id": "mock-cup-client-id",
"identity_pool_id": "mock-idp-id",
"oauth": {
"identity_providers": ["FACEBOOK", "SIGN_IN_WITH_APPLE", "GOOGLE"],
"identity_providers": ["FACEBOOK", "SIGN_IN_WITH_APPLE", "GOOGLE", "Auth0"],
"domain": "mock-oauth-domain",
"scopes": ["phone"],
"redirect_sign_in_uri": ["mock-sign-in-uri"],
Expand Down
18 changes: 6 additions & 12 deletions packages/core/__mocks__/configMocks/amplifyconfiguration.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just lint changes on this file

Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,25 @@
"aws_user_files_s3_bucket_region": "us-west-2",
"aws_user_pools_id": "mock-cup-id",
"aws_user_pools_web_client_id": "mock-cup-client-id",
"geo": {
"geo": {
"amazon_location_service": {
"search_indices": {
"items": [
"mock-geo-search-item",
"mock-geo-search-item-alt"
],
"items": ["mock-geo-search-item", "mock-geo-search-item-alt"],
"default": "mock-geo-search-item"
},
"geofenceCollections": {
"items": [
"mock-geo-fence-item",
"mock-geo-fence-item-alt"
],
"items": ["mock-geo-fence-item", "mock-geo-fence-item-alt"],
"default": "mock-geo-fence-item"
},
"region": "us-west-2"
}
}
},
"aws_appsync_graphqlEndpoint": "mock-data-url",
"aws_appsync_apiKey": "mock-data-api-key",
"aws_appsync_region": "us-west-2",
"aws_appsync_authenticationType": "API_KEY",
"Notifications": {
"InAppMessaging": {
"InAppMessaging": {
"AWSPinpoint": {
"appId": "mock-pinpoint-app-id",
"region": "us-west-2"
Expand All @@ -66,4 +60,4 @@
}
}
}
}
}
18 changes: 15 additions & 3 deletions packages/core/__tests__/parseAWSExports.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseAWSExports } from '../src/parseAWSExports';
import { OAuthScope } from '../src/singleton/Auth/types';
import { OAuthProvider, OAuthScope } from '../src/singleton/Auth/types';
import { ResourcesConfig } from '../src/singleton/types';

// TODO: Add API category tests
Expand Down Expand Up @@ -91,7 +91,13 @@ describe('parseAWSExports', () => {
email: false,
oauth: {
domain: oAuthDomain,
providers: ['Google', 'Apple', 'Facebook', 'Amazon'],
providers: [
'Google',
'Apple',
'Facebook',
'Amazon',
'Auth0',
] as OAuthProvider[],
redirectSignIn: [oAuthSigninUrl],
redirectSignOut: [oAuthSignoutUrl],
responseType: oAuthResponseType,
Expand Down Expand Up @@ -172,7 +178,13 @@ describe('parseAWSExports', () => {
responseType: oAuthResponseType,
},
aws_cognito_verification_mechanisms: ['EMAIL'],
aws_cognito_social_providers: ['GOOGLE', 'APPLE', 'FACEBOOK', 'AMAZON'],
aws_cognito_social_providers: [
'GOOGLE',
'APPLE',
'FACEBOOK',
'AMAZON',
'Auth0',
],
aws_mandatory_sign_in: 'enable',
aws_mobile_analytics_app_id: appId,
aws_mobile_analytics_app_region: region,
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/parseAmplifyOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,13 @@ const providerNames: Record<string, OAuthProvider> = {
};

function getOAuthProviders(providers: string[] = []): OAuthProvider[] {
return providers.map(provider => providerNames[provider]);
return providers.reduce<OAuthProvider[]>((oAuthProviders, provider) => {
ashika112 marked this conversation as resolved.
Show resolved Hide resolved
if (providerNames[provider] !== undefined) {
oAuthProviders.push(providerNames[provider]);
}

return oAuthProviders;
}, []);
Comment on lines +319 to +325
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially this?

Suggested change
return providers.reduce<OAuthProvider[]>((oAuthProviders, provider) => {
if (providerNames[provider] !== undefined) {
oAuthProviders.push(providerNames[provider]);
}
return oAuthProviders;
}, []);
return providers.map(provider => providerNames[provider]).filter(p => p);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes ! reduce reduces the two iteration :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

Comment on lines +319 to +325
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify this with filter:

Suggested change
return providers.reduce<OAuthProvider[]>((oAuthProviders, provider) => {
if (providerNames[provider] !== undefined) {
oAuthProviders.push(providerNames[provider]);
}
return oAuthProviders;
}, []);
return providers.filter(provider => !!providerNames[provider]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slight note we would need map and filter in this case :P

}

function getMfaStatus(
Expand Down
Loading