gpt4 book ai didi

javascript - 如何使用 AWS Cognito TOTP MFA?

转载 作者:行者123 更新时间:2023-12-04 17:34:55 27 4
gpt4 key购买 nike

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

它说 用例 27. 选择 MFA 方法并使用 TOTP 进行身份验证。

我已经成功完成了用户名和密码登录并完成了 SMS 代码,但我无法获得 associateSecretCode 中给出的 secret token 使用 google authenticator 扫描的函数qr 扫描仪。一直给我一个无效的代码错误

这是我的代码:

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
});
}
});

生成了二维码,但是在扫描它时,谷歌身份验证器给了我这个错误:
enter image description here

我在这里做错了什么?

最佳答案

您需要格式化谷歌验证器的二维码。看这里:https://github.com/google/google-authenticator/wiki/Key-Uri-Format

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

关于javascript - 如何使用 AWS Cognito TOTP MFA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57080249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com