Javascript 如何使用AWS cognito TOTP MFA?
我很难弄清楚如何使用这个库: 其中显示用例27。选择MFA方法并使用TOTP进行身份验证。 我已经成功完成用户名和密码登录以及短信编码,但是我无法使用Javascript 如何使用AWS cognito TOTP MFA?,javascript,reactjs,amazon-web-services,amazon-cognito,totp,Javascript,Reactjs,Amazon Web Services,Amazon Cognito,Totp,我很难弄清楚如何使用这个库: 其中显示用例27。选择MFA方法并使用TOTP进行身份验证。 我已经成功完成用户名和密码登录以及短信编码,但是我无法使用googleauthenticatorqr扫描仪获取associateSecretCode功能中给出的秘密令牌。一直给我一个无效的代码错误 这是我的密码: cognitoUser.authenticateUser(authenticationDetails, { onSuccess: function(result) { const
googleauthenticator
qr扫描仪获取associateSecretCode
功能中给出的秘密令牌。一直给我一个无效的代码错误
这是我的密码:
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
});
}
});
二维码会生成,但扫描时,google authenticator会告诉我以下错误:
我做错了什么?您需要为google authenticator格式化二维码。请看这里: 尝试使用此npm库生成正确的格式: