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

fix(amplify-category-auth): add auth user selections to aws-exports/amplifyconfiguration files #7807

Merged
merged 27 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bcb889f
Add .circleci/config.yml
lazpavel Jul 8, 2021
9c1796a
Merge branch 'aws-amplify:master' into master
lazpavel Jul 8, 2021
f4ad225
Merge branch 'aws-amplify:master' into master
lazpavel Jul 12, 2021
8be15e5
Merge branch 'aws-amplify:master' into master
lazpavel Jul 14, 2021
071ccc8
Merge branch 'aws-amplify:master' into master
lazpavel Jul 18, 2021
6c00377
Merge branch 'aws-amplify:master' into master
lazpavel Jul 21, 2021
3fa3a32
Merge branch 'aws-amplify:master' into master
lazpavel Jul 23, 2021
0690346
Merge branch 'aws-amplify:master' into master
lazpavel Jul 23, 2021
3e9f2e3
Merge branch 'aws-amplify:master' into master
lazpavel Jul 25, 2021
f319345
fix(amplify-category-auth): add auth user selections to aws-exports/a…
lazpavel Jul 26, 2021
560a951
fix(amplify-category-auth): add auth user selections to aws-exports/a…
lazpavel Jul 26, 2021
2680ac8
fix(amplify-category-auth): added e2e test for add auth user selectio…
lazpavel Jul 27, 2021
be988f3
fix(amplify-category-auth): added e2e test for add auth user selectio…
lazpavel Jul 27, 2021
1e00136
fix(amplify-category-auth): added e2e test for add auth user selectio…
lazpavel Jul 27, 2021
3c9f548
fix(amplify-category-auth): add auth user selections to config files
lazpavel Jul 27, 2021
b6fc631
Merge branch 'aws-amplify:master' into main
lazpavel Jul 27, 2021
01b302c
fix(amplify-category-auth): add auth user selections to config files
lazpavel Jul 27, 2021
d004867
chore(amplify-category-auth): cr feedback for add auth user selection…
lazpavel Jul 27, 2021
ef07445
chore(amplify-category-auth): cr feedback for add auth user selection…
lazpavel Jul 27, 2021
98aacfd
chore(amplify-category-auth): typo fix
lazpavel Jul 28, 2021
e7ef846
chore(amplify-category-auth): fixed e2e test for front end config val…
lazpavel Jul 28, 2021
0aab652
Merge branch 'aws-amplify:master' into master
lazpavel Jul 28, 2021
4cb6b7c
Merge branch 'master' into zero-config-auth
lazpavel Jul 29, 2021
aa13f1d
Update packages/amplify-category-auth/src/provider-utils/awscloudform…
lazpavel Jul 29, 2021
470c09b
Merge branch 'zero-config-auth' of github.com:lazpavel/amplify-cli in…
lazpavel Jul 29, 2021
496fd46
chore(amplify-category-auth): addressed pr feedback
lazpavel Jul 29, 2021
d2e1bea
chore(amplify-category-auth): changed dependsOn type from any to
lazpavel Jul 29, 2021
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
46 changes: 38 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1251,14 +1251,22 @@ jobs:
environment:
TEST_SUITE: src/__tests__/configure-project.test.ts
CLI_REGION: eu-central-1
auth_6-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/auth_6.test.ts
CLI_REGION: ap-northeast-1
api_4-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
schema-iterative-update-4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
Expand Down Expand Up @@ -1999,6 +2007,16 @@ jobs:
TEST_SUITE: src/__tests__/configure-project.test.ts
CLI_REGION: eu-central-1
steps: *ref_6
auth_6-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/auth_6.test.ts
CLI_REGION: ap-northeast-1
steps: *ref_6
api_4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
Expand All @@ -2007,7 +2025,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
steps: *ref_6
workflows:
version: 2
Expand Down Expand Up @@ -2130,11 +2148,11 @@ workflows:
- interactions-amplify_e2e_tests
- datastore-modelgen-amplify_e2e_tests
- layer-2-amplify_e2e_tests
- api_4-amplify_e2e_tests
- schema-iterative-update-2-amplify_e2e_tests
- auth_6-amplify_e2e_tests
- schema-data-access-patterns-amplify_e2e_tests
- init-special-case-amplify_e2e_tests
- iam-permissions-boundary-amplify_e2e_tests
- api_4-amplify_e2e_tests
- feature-flags-amplify_e2e_tests
- schema-versioned-amplify_e2e_tests
- plugin-amplify_e2e_tests
Expand All @@ -2160,11 +2178,11 @@ workflows:
- interactions-amplify_e2e_tests_pkg_linux
- datastore-modelgen-amplify_e2e_tests_pkg_linux
- layer-2-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- schema-iterative-update-2-amplify_e2e_tests_pkg_linux
- auth_6-amplify_e2e_tests_pkg_linux
- schema-data-access-patterns-amplify_e2e_tests_pkg_linux
- init-special-case-amplify_e2e_tests_pkg_linux
- iam-permissions-boundary-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- feature-flags-amplify_e2e_tests_pkg_linux
- schema-versioned-amplify_e2e_tests_pkg_linux
- plugin-amplify_e2e_tests_pkg_linux
Expand Down Expand Up @@ -2648,7 +2666,7 @@ workflows:
filters: *ref_10
requires:
- function_3-amplify_e2e_tests
- api_4-amplify_e2e_tests:
- auth_6-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2714,6 +2732,12 @@ workflows:
filters: *ref_10
requires:
- auth_5-amplify_e2e_tests
- api_4-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- schema-iterative-update-2-amplify_e2e_tests
- schema-iterative-update-3-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
Expand Down Expand Up @@ -3128,7 +3152,7 @@ workflows:
filters: *ref_13
requires:
- function_3-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
- auth_6-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
Expand Down Expand Up @@ -3198,6 +3222,12 @@ workflows:
filters: *ref_13
requires:
- auth_5-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- schema-iterative-update-2-amplify_e2e_tests_pkg_linux
- schema-iterative-update-3-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export type MetaOutput = {
CreatedSNSRole?: string;
};

export type AuthParameters = {
dependsOn?: any[];
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
triggers?: string;
identityPoolName?: string;
aliasAttributes?: string[];
authProviders?: string[];
requiredAttributes?: string[];
passwordPolicyMinLength?: string;
passwordPolicyCharacters?: string[];
mfaConfiguration?: string;
mfaTypes?: string[];
};

// Persisted into team-provider-info
export type EnvSpecificResourceParameters = {
userPoolId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as path from 'path';
import { JSONUtilities, $TSAny, pathManager } from 'amplify-cli-core';
import { JSONUtilities, pathManager } from 'amplify-cli-core';
import { transformUserPoolGroupSchema } from './transform-user-pool-group';
import { authProviders as authProviderList } from '../assets/string-maps';
import { AuthParameters } from '../import/types';

/**
* Factory function that returns a function that updates Amplify meta files after adding auth resource assets
*
Expand All @@ -16,7 +19,7 @@ export const getPostAddAuthMetaUpdater = (context: any, resultMetadata: { servic
providerPlugin: resultMetadata.providerName,
};
const parametersJSONPath = path.join(context.amplify.pathManager.getBackendDirPath(), 'auth', resourceName, 'parameters.json');
const authParameters = JSONUtilities.readJson<{ dependsOn: any[]; triggers: string; identityPoolName: string }>(parametersJSONPath)!;
const authParameters = JSONUtilities.readJson<AuthParameters>(parametersJSONPath)!;

if (authParameters.dependsOn) {
options.dependsOn = authParameters.dependsOn;
Expand All @@ -36,6 +39,7 @@ export const getPostAddAuthMetaUpdater = (context: any, resultMetadata: { servic
}

options.customAuth = customAuthConfigured;
options.frontendAuthConfig = getFrontEndConfig(authParameters);

context.amplify.updateamplifyMetaAfterResourceAdd('auth', resourceName, options);

Expand All @@ -62,7 +66,7 @@ export const getPostAddAuthMetaUpdater = (context: any, resultMetadata: { servic
*/
export const getPostUpdateAuthMetaUpdater = (context: any) => async (resourceName: string) => {
const resourceDirPath = path.join(pathManager.getBackendDirPath(), 'auth', resourceName, 'parameters.json');
const authParameters = JSONUtilities.readJson<$TSAny>(resourceDirPath);
const authParameters = JSONUtilities.readJson<AuthParameters>(resourceDirPath)!;
if (authParameters.dependsOn) {
context.amplify.updateamplifyMetaAfterResourceUpdate('auth', resourceName, 'dependsOn', authParameters.dependsOn);
}
Expand All @@ -79,6 +83,7 @@ export const getPostUpdateAuthMetaUpdater = (context: any) => async (resourceNam
triggers.VerifyAuthChallengeResponse.length > 0;
}
context.amplify.updateamplifyMetaAfterResourceUpdate('auth', resourceName, 'customAuth', customAuthConfigured);
context.amplify.updateamplifyMetaAfterResourceUpdate('auth', resourceName, 'frontendAuthConfig', getFrontEndConfig(authParameters));

// Update Identity Pool dependency attributes on userpool groups
const allResources = context.amplify.getProjectMeta();
Expand All @@ -100,3 +105,48 @@ export const getPostUpdateAuthMetaUpdater = (context: any) => async (resourceNam
}
return resourceName;
};

function getFrontEndConfig(authParameters: AuthParameters) {
const loginMechanism: string[] = [];
loginMechanism.push(...(authParameters?.aliasAttributes || []).map((att: string) => att.toUpperCase()));

if (authParameters.authProviders) {
authParameters.authProviders.forEach((provider: string) => {
let name = authProviderList.find(it => it.value === provider)?.name;

if (name) {
loginMechanism.push(name.toUpperCase());
}
});
}

const signupAttributes: string[] = authParameters?.requiredAttributes
? authParameters.requiredAttributes.map((att: string) => att.toUpperCase())
: [];
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

const passwordProtectionSettings = {
passwordPolicyMinLength: authParameters?.passwordPolicyMinLength,
passwordPolicyCharacters: authParameters?.passwordPolicyCharacters
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
? authParameters.passwordPolicyCharacters.map((i: string) => i.replace(/ /g, '_').toUpperCase())
: [],
};

const mfaTypes: string[] = [];
if (authParameters.mfaTypes) {
if (authParameters.mfaTypes.includes('SMS Text Message')) {
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
mfaTypes.push('SMS');
}

if (authParameters.mfaTypes.includes('TOTP')) {
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
mfaTypes.push('TOTP');
}
}

return {
loginMechanism: loginMechanism,
signupAttributes: signupAttributes,
passwordProtectionSettings: passwordProtectionSettings,
mfaConfiguration: authParameters?.mfaConfiguration,
mfaTypes: mfaTypes,
};
}
4 changes: 2 additions & 2 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ export function addAuthUserPoolOnlyWithOAuth(cwd: string, settings: AddAuthUserP
.wait('Do you want to add another redirect signout URI')
.sendConfirmNo()
.wait('Select the OAuth flows enabled for this project')
.sendCarriageReturn() // Authorication Grant
.sendCarriageReturn() // Authorization Grant
.wait('Select the OAuth scopes enabled for this project')
.sendCarriageReturn() // All
.wait('Select the social providers you want to configure for your user pool')
Expand Down Expand Up @@ -1414,7 +1414,7 @@ export function addAuthIdentityPoolAndUserPoolWithOAuth(
.wait('Do you want to add another redirect signout URI')
.sendConfirmNo()
.wait('Select the OAuth flows enabled for this project')
.sendCarriageReturn() // Authorication Grant
.sendCarriageReturn() // Authorization Grant
.wait('Select the OAuth scopes enabled for this project')
.sendCarriageReturn() // All
.wait('Select the social providers you want to configure for your user pool')
Expand Down
64 changes: 64 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/auth_6.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { $TSAny } from 'amplify-cli-core';
import {
addAuthWithMaxOptions,
amplifyPushAuth,
createNewProjectDir,
deleteProject,
deleteProjectDir,
getProjectMeta,
initJSProjectWithProfile,
} from 'amplify-e2e-core';

const PROJECT_NAME = 'authTest';
const defaultSettings = {
name: PROJECT_NAME,
};
describe('zero config auth ', () => {
let projRoot: string;
beforeEach(async () => {
projRoot = await createNewProjectDir('zero-config-auth');
});

afterEach(async () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});

it('...should init a javascript project and add auth with all options and update front end config', async () => {
await initJSProjectWithProfile(projRoot, defaultSettings);
await addAuthWithMaxOptions(projRoot, {});
await amplifyPushAuth(projRoot);

const meta = getProjectMeta(projRoot);
const authMeta: $TSAny = Object.values(meta.auth)[1];
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

expect(authMeta.frontendAuthConfig).toMatchInlineSnapshot(`
Object {
"loginMechanism": Array [
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be plural loginMechanisms?

Copy link
Contributor

Choose a reason for hiding this comment

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

@drochetti @manueliglesias Do you recall why this was singular vs. plural in the API Review?

This feature hasn't shipped, so I'm wondering if this is a tweak we need to land before releasing.

Copy link
Contributor

Choose a reason for hiding this comment

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

"EMAIL",
"FACEBOOK",
"GOOGLE",
"AMAZON",
"APPLE",
],
"mfaConfiguration": "ON",
"mfaTypes": Array [
"SMS",
"TOTP",
],
"passwordProtectionSettings": Object {
"passwordPolicyCharacters": Array [
"REQUIRES_LOWERCASE",
"REQUIRES_UPPERCASE",
"REQUIRES_NUMBERS",
"REQUIRES_SYMBOLS",
],
"passwordPolicyMinLength": 8,
},
"signupAttributes": Array [
"EMAIL",
],
}
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
};
}

Object.assign(cognitoConfig.Auth.Default, cognitoResource.frontendAuthConfig);

return cognitoConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
};
}

Object.assign(cognitoConfig.Auth.Default, cognitoResource.frontendAuthConfig);

return cognitoConfig;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-frontend-ios/lib/frontend-config-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ function getCognitoConfig(cognitoResources, projectRegion) {
};
}

Object.assign(cognitoConfig.Auth.Default, cognitoResource.frontendAuthConfig);

return cognitoConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,25 @@ function getCognitoConfig(cognitoResources, projectRegion) {
federationTarget = 'COGNITO_IDENTITY_POOLS';
}

let frontendAuthConfig;
if (cognitoResource && cognitoResource.frontEndConfig) {
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
frontendAuthConfig = {
aws_cognito_login_mechanism: cognitoResource.frontEndConfig.loginMechanism,
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
aws_cognito_signup_attributes: cognitoResource.frontEndConfig.signupAttributes,
aws_cognito_mfa_configuration: cognitoResource.frontEndConfig.mfaConfiguration,
aws_cognito_mfa_types: cognitoResource.frontEndConfig.mfaTypes,
aws_cognito_password_protection_settings: cognitoResource.frontEndConfig.passwordProtectionSettings,
};
}

return {
aws_cognito_identity_pool_id: cognitoResource.output.IdentityPoolId,
aws_cognito_region: projectRegion,
aws_user_pools_id: cognitoResource.output.UserPoolId,
aws_user_pools_web_client_id: cognitoResource.output.AppClientIDWeb,
oauth,
federationTarget,
...frontendAuthConfig,
};
}

Expand Down