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 16 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
@@ -1,6 +1,8 @@
import * as path from 'path';
import { JSONUtilities, $TSAny, pathManager } from 'amplify-cli-core';
import { transformUserPoolGroupSchema } from './transform-user-pool-group';
import { authProviders as authProviderList } from '../assets/string-maps';

/**
* Factory function that returns a function that updates Amplify meta files after adding auth resource assets
*
Expand All @@ -16,7 +18,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<$TSAny>(parametersJSONPath)!;
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

Expand Down Expand Up @@ -79,6 +82,7 @@ export const getPostUpdateAuthMetaUpdater = (context: any) => async (resourceNam
triggers.VerifyAuthChallengeResponse.length > 0;
}
context.amplify.updateamplifyMetaAfterResourceUpdate('auth', resourceName, 'customAuth', customAuthConfigured);
context.amplify.updateamplifyMetaAfterResourceUpdate('auth', resourceName, 'frontEndConfig', getFrontEndConfig(authParameters));

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

function getFrontEndConfig(authParameters: any) {
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
const frontEndConfig: any = {};
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

let loginMechanism: string[] = [];
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

if (authParameters.aliasAttributes) {
let aliasAttributes = authParameters.aliasAttributes.map((att: string) => att.toUpperCase());
loginMechanism = [...aliasAttributes];
}
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

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

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

if (loginMechanism.length) {
frontEndConfig.loginMechanism = loginMechanism;
}

if (authParameters.requiredAttributes) {
let requiredAttributes = authParameters.requiredAttributes.map((att: string) => att.toUpperCase());
frontEndConfig.signupAttributes = [...requiredAttributes];
}
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

if (authParameters.mfaConfiguration) {
frontEndConfig.mfaConfiguration = authParameters.mfaConfiguration;
}

if (authParameters.mfaTypes) {
frontEndConfig.mfaTypes = [];

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

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

if (authParameters.passwordPolicyMinLength || authParameters.passwordPolicyCharacters) {
let passwordProtectionSettings: any = {};

if (authParameters.passwordPolicyMinLength) {
passwordProtectionSettings.passwordPolicyMinLength = authParameters.passwordPolicyMinLength;
}

if (authParameters.passwordPolicyCharacters) {
let passwordPolicyCharacters = authParameters.passwordPolicyCharacters.map((i: string) => i.replace(/ /g, '_').toUpperCase());
passwordProtectionSettings.passwordPolicyCharacters = passwordPolicyCharacters;
}

frontEndConfig.passwordProtectionSettings = passwordProtectionSettings;
}

return frontEndConfig;
}
43 changes: 43 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,43 @@
import {
initJSProjectWithProfile,
getProjectMeta,
deleteProject,
amplifyPushAuth,
createNewProjectDir,
deleteProjectDir,
addAuthWithMaxOptions,
} from 'amplify-e2e-core';
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
import _ from 'lodash';
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

const PROJECT_NAME = 'authTest';
const defaultsSettings = {
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
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 a all uptions and update front end config', async () => {
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
await initJSProjectWithProfile(projRoot, defaultsSettings);
await addAuthWithMaxOptions(projRoot, { useInclusiveTerminology: false });
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
await amplifyPushAuth(projRoot);
let meta = getProjectMeta(projRoot);
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

let id = Object.keys(meta.auth)[0];
let authMeta = meta.auth[id];
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
lazpavel marked this conversation as resolved.
Show resolved Hide resolved

expect(authMeta.frontEndConfig).toBeDefined();
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
expect(authMeta.frontEndConfig.loginMechanism).toBeDefined();
expect(authMeta.frontEndConfig.signupAttributes).toBeDefined();
expect(authMeta.frontEndConfig.mfaConfiguration).toBeDefined();
expect(authMeta.frontEndConfig.mfaTypes).toBeDefined();
expect(authMeta.frontEndConfig.passwordProtectionSettings).toBeDefined();
});
});
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.frontEndConfig);

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.frontEndConfig);

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.frontEndConfig);

return cognitoConfig;
}

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

let authData = {};

if (cognitoResource.frontEndConfig) {
if (cognitoResource.frontEndConfig.loginMechanism) {
authData.aws_cognito_login_mechanism = cognitoResource.frontEndConfig.loginMechanism;
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
}

if (cognitoResource.frontEndConfig.signupAttributes) {
authData.aws_cognito_signup_attributes = cognitoResource.frontEndConfig.signupAttributes;
}

if (cognitoResource.frontEndConfig.mfaConfiguration) {
authData.aws_cognito_mfa_configuration = cognitoResource.frontEndConfig.mfaConfiguration;
}

if (cognitoResource.frontEndConfig.mfaTypes) {
authData.aws_cognito_mfa_types = cognitoResource.frontEndConfig.mfaTypes;
}

if (cognitoResource.frontEndConfig.passwordProtectionSettings) {
authData.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,
...authData,
lazpavel marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down