首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用AWS认知TOTP MFA?

如何使用AWS认知TOTP MFA?
EN

Stack Overflow用户
提问于 2019-07-17 16:13:05
回答 1查看 5.4K关注 0票数 4

我很难弄清楚如何使用这个库:https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js

上面写着用例27。选择MFA方法并使用TOTP.进行身份验证

我已经成功地获得用户名和密码登录和短信代码完成,但我无法获得在associateSecretCode函数中给出的秘密令牌被扫描使用google authenticator qr扫描仪。一直给我一个无效的代码错误

这是我的密码:

代码语言:javascript
复制
cognitoUser.authenticateUser(authenticationDetails, {
  onSuccess: function(result) {
    const accessToken = result.getAccessToken().getJwtToken();
    cognitoUser.associateSoftwareToken(this);
  },

  onFailure: function(err) {
    alert(err.message || JSON.stringify(err));
  },

  mfaSetup: function(challengeName, challengeParameters) {
    console.log("MFA SETUP");
    cognitoUser.associateSoftwareToken(this);
  },

  associateSecretCode: async secretCode => {
    console.log("SECRET CODE: ", secretCode);
    await this.setState({ QRCode: secretCode, showQRCode: true });
    setTimeout(() => {
      const challengeAnswer = prompt("Please input the TOTP code.", "");
      cognitoUser.verifySoftwareToken(challengeAnswer, "My TOTP device", {
        onSuccess: session => console.log("SUCCESS TOTP: ", session),
        onFailure: err => console.error("ERROR TOTP: ", err)
      });
    }, 2000);
  },

  selectMFAType: function(challengeName, challengeParameters) {
    var mfaType = prompt("Please select the MFA method.", ""); // valid values for mfaType is "SMS_MFA", "SOFTWARE_TOKEN_MFA"
    cognitoUser.sendMFASelectionAnswer(mfaType, this);
  },

  totpRequired: function(secretCode) {
    var challengeAnswer = prompt("Please input the TOTP code.", "");
    cognitoUser.sendMFACode(challengeAnswer, this, "SOFTWARE_TOKEN_MFA");
  },

  mfaRequired: function(codeDeliveryDetails) {
    var verificationCode = prompt("Please input verification code", "");
    cognitoUser.sendMFACode(verificationCode, this);
  },
  newPasswordRequired: userAttributes => {
    this.setState({
      user: userAttributes,
      showNewPassword: true
    });
  }
});

生成QR代码,但在扫描它时,google身份验证器会给出以下错误:

我在这里做错什么了?

EN

回答 1

Stack Overflow用户

发布于 2019-11-01 04:43:42

您需要为google身份验证程序格式化qr代码。见此处:https://github.com/google/google-authenticator/wiki/Key-Uri-Format

尝试使用这个npm库生成适当的格式:https://www.npmjs.com/package/otpauth

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57080249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档