Skip to content

Commit

Permalink
chore: add new backend for username only login
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed Oct 22, 2024
1 parent d85e665 commit 453a175
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 39 deletions.
5 changes: 5 additions & 0 deletions infra-gen2/backends/auth/username-login-mfa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amplify
node_modules
.amplify
amplify_outputs*
amplifyconfiguration*
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineAuth } from "@aws-amplify/backend";

export const auth = defineAuth({
name: "mfa-required-email",
loginWith: {
phone: true,
},
// TODO(khatruong2009): Uncomment the following line when the feature is ready.
// multifactor: {
// mode: "REQUIRED",
// email: true,
// sms: true,
// totp: true,
// },
accountRecovery: "PHONE_WITHOUT_MFA_AND_EMAIL",
});
40 changes: 40 additions & 0 deletions infra-gen2/backends/auth/username-login-mfa/amplify/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineBackend } from "@aws-amplify/backend";
import { addAuthUserExtensions } from "infra-common";
import { auth } from "./auth/resource";

const backend = defineBackend({
auth,
});

const resources = backend.auth.resources;
const { userPool, cfnResources } = resources;
const { stack } = userPool;
const { cfnUserPool } = cfnResources;

// Adds infra for creating/deleting users via App Sync and fetching confirmation
// and MFA codes from App Sync.
const customOutputs = addAuthUserExtensions({
name: "username-login-mfa",
stack,
userPool,
cfnUserPool,
});
backend.addOutput(customOutputs);

cfnUserPool.schema = undefined;
cfnUserPool.usernameAttributes = [];
cfnUserPool.emailConfiguration = {
emailSendingAccount: "DEVELOPER",
from: "ktruon@amazon.com",
sourceArn: `arn:aws:ses:${stack.region}:${stack.account}:identity/ktruon@amazon.com`,
};
cfnUserPool.adminCreateUserConfig = {
allowAdminCreateUserOnly: true,
};
cfnUserPool.autoVerifiedAttributes = [];
cfnUserPool.userAttributeUpdateSettings = {
attributesRequireVerificationBeforeUpdate: [],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
17 changes: 17 additions & 0 deletions infra-gen2/backends/auth/username-login-mfa/amplify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"$amplify/*": [
"../.amplify/generated/*"
]
}
}
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/auth/username-login-mfa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "username-login-mfa",
"version": "1.0.0",
"main": "index.js"
}
71 changes: 32 additions & 39 deletions infra-gen2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions infra-gen2/tool/deploy_gen2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ const List<AmplifyBackendGroup> infraConfig = [
identifier: 'mfa-opt-ema-tot',
pathToSource: 'infra-gen2/backends/auth/mfa-optional-email-totp',
),
AmplifyBackend(
name: 'username-login-mfa',
identifier: 'user-login-mfa',
pathToSource: 'infra-gen2/backends/auth/username-login-mfa',
),
],
),
AmplifyBackendGroup(
Expand Down

0 comments on commit 453a175

Please sign in to comment.