Skip to content

Conversation

@devnotfound
Copy link
Contributor

@devnotfound devnotfound commented Jul 6, 2023

Description of changes:

  • This PR adds TypeScript examples for the multi-factor authentication category
  • This PR also modernises the JavaScript examples for the multi-factor authentication category

Related GitHub issue #, if available:

N/A

Instructions

If this PR should not be merged upon approval for any reason, please submit as a DRAFT

Which product(s) are affected by this PR (if applicable)?

  • amplify-cli
  • amplify-ui
  • amplify-studio
  • amplify-hosting
  • amplify-libraries

Which platform(s) are affected by this PR (if applicable)?

  • JS
  • iOS
  • Android
  • Flutter
  • React Native

Please add the product(s)/platform(s) affected to the PR title

Checks

  • Does this PR conform to the styleguide?

  • Does this PR include filetypes other than markdown or images? Please add or update unit tests accordingly.

  • Are any files being deleted with this PR? If so, have the needed redirects been created?

  • Are all links in MDX files using the MDX link syntax rather than HTML link syntax?

    ref: MDX: [link](https://link.com)
    HTML: <a href="https://link.com">link</a>

When this PR is ready to merge, please check the box below

  • Ready to merge

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@devnotfound devnotfound requested a review from a team as a code owner July 6, 2023 00:15
@timngyn timngyn added the amplify/js Issues tied to JS label Jul 6, 2023
@katieklein katieklein requested a review from a team July 6, 2023 21:35
@katieklein katieklein added external-contributor product-owner-review-needed Current step in the approval process requires a PM review technical-review-needed labels Jul 6, 2023
Copy link
Member

@israx israx left a comment

Choose a reason for hiding this comment

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

Hey @devnotfound . Thanks so much for putting this together.

PR looks good, just a few minor changes about not having imports and references from scoped packages, user passed on authenticated APIs should come from Auth.currentAuthenticatedUser, and finally about keeping the current format for user attributes.

type SetupTOTPAuthParameters = {
user: string;
challengeAnswer: string;
mfaType?: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA' | null;
Copy link
Member

Choose a reason for hiding this comment

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

mfaType param is already nullable, we can avoid the null type here

export async function setupTOTPAuth({ user, challengeAnswer, mfaType }: SetupTOTPAuthParameters) {
// To setup TOTP, first you need to get a `authorization code` from Amazon Cognito
// `user` is the current Authenticated user
const tOTPCode = await Auth.setupTOTP(user);
Copy link
Member

Choose a reason for hiding this comment

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

Technically, Auth.setupTOTP(user) doesn't return the OTP code yet. It returns a secretCode that is used on authenticator Apps to generate the OTP code.


// Finally, when sign-in with MFA is enabled, use the confirmSignIn method
// to pass the TOTP code and MFA type.
await Auth.confirmSignIn(user, tOTPCode, mfaType); // Optional, MFA Type e.g. SMS_MFA || SOFTWARE_TOKEN_MFA
Copy link
Member

Choose a reason for hiding this comment

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

the OTP code used here should come from an authenticator app, we can make that reference above

// and then trigger the following function with a button click
// For example, the email and phone_number are required attributes
const { username, email, phone_number } = getInfoFromUserInput();
const { inputUsername, inputEmail, inputPhoneNumber } = await getInfoFromUserInput();
Copy link
Member

Choose a reason for hiding this comment

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

user attributes format should be based on the standard claims of OpenId Connect

Comment on lines 343 to 344
inputEmail,
inputPhoneNumber,
Copy link
Member

Choose a reason for hiding this comment

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

should be on the standard format as mentioned above

Comment on lines 408 to 409
import { CognitoUser } from '@aws-amplify/auth';
import { ClientMetaData } from '@aws-amplify/auth/lib-esm/types';
Copy link
Member

Choose a reason for hiding this comment

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

trying to avoid this import pattern and all the reference as suggested above

Batch commit of all initial review changes

Co-authored-by: israx <70438514+israx@users.noreply.github.com>
line replacement test
add try/catch for TS and JS blocks
update location of Auth.currentAuthenticatedUser() call
@cwomack cwomack requested review from cwomack and israx July 21, 2023 20:14
Copy link
Contributor

@cwomack cwomack left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@israx israx left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@abdallahshaban557 abdallahshaban557 left a comment

Choose a reason for hiding this comment

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

LGTM

@abdallahshaban557 abdallahshaban557 added ready-to-merge all approvals are in and this PR is ready for a docs engineer to merge and removed product-owner-review-needed Current step in the approval process requires a PM review labels Jul 21, 2023
@katieklein katieklein merged commit 1200248 into aws-amplify:main Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amplify/js Issues tied to JS external-contributor ready-to-merge all approvals are in and this PR is ready for a docs engineer to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants