首页 > 解决方案 > 放大和反应:代码不匹配和失败启用软件令牌 MFA

问题描述

我有一个 Cognito 用户池,它的 MFA 设置为 Optional,仅 TOTP。

我正在尝试设置一个页面,在此AWS 文档之后首次为用户启用 MultiFactorAuthentication 。

当我的组件安装时,我生成一个二维码并使用 qrcode.react 在屏幕上显示它

  useEffect(() => {
Auth.currentAuthenticatedUser({ bypassCache: true }).then(user => {
  setUser(user);
  Auth.setupTOTP(user).then(code => {
    const authCode = "otpauth://totp/AWSCognito:" + user.username + "?secret=" + code + "&issuer=Invent";
    setQrCode(authCode);
  });
});
}, []);

然后,当用户输入输入时,我对其进行验证并调用 setPrefferredMFA。现在在这里,我检查了“输入”是否正确传递并且那里没有问题。

const setupMFA = input => {
Auth.setupTOTP(user).then(() => {
  Auth.verifyTotpToken(user, input)
    .then(() => {
      Auth.setPreferredMFA(user, "TOTP").then(() => {
        props.setShowModal(false);
      });
    })
    .catch(e => {
      // Token is not verified
    });
});
};

我仍然收到代码不匹配和无法启用软件令牌 MFA错误并且无法为用户设置 MFA。

标签: reactjsamazon-web-servicesamazon-cognitomulti-factor-authenticationamplify

解决方案


我解决了。

Auth.verifyTotpToken() 不应该在 setupTOTP 的 .then() 块中。

噗。删除 setupMFA 函数中的 Auth.setupTOTP 使其工作。


推荐阅读