AWS Node JS MFA Cognito



我正在为节点js开发aws sdk,并尝试从特定用户池对用户进行身份验证。注意:我的用户池已启用多重身份验证,并通过短信接收 OTP。

这是我的代码段: ' var userData = { 用户名 : "用户名", 池 : 用户池 };

cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
var authenticationData = {
Username : 'username',
Password : 'password',
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('authentication successful!')
},
onFailure: function(err) {
alert(err);
},
mfaRequired: function(codeDeliveryDetails) {
var verificationCode = prompt('Please input verification code' ,'');
cognitoUser.sendMFACode(verificationCode, this);
}
});` 

但是:问题是:它给出了一个错误:

错误 => {"代码":"未知错误", "message":"未知错误,来自 fetch 的响应正文未定义"}

**在堆栈跟踪中,我得到:**Stack Trace : Error at Object.onFailure (E:Karmanode_awsmedium_tryindex.js:78:79) at E:Karmanode_awsmedium_trynode_modulesamazon-cognito-identity-jslibCognitoUser.js:376:31 at E:Karmanode_awsmedium_trynode_modulesamazon-cognito-identity-jslibCognitoUser.js:361:22 at E:Karmanode_awsmedium_trynode_modulesamazon-cognito-identity-jslibClient.js:114:14 at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:228:7)

**但又一次 :::: **OTP 来到我的手机...

请谁能帮我????

提前感谢

添加丢失的回调函数,以便您可以正确处理状态:

export interface IAuthenticationCallback {
onSuccess: (session: CognitoUserSession, userConfirmationNecessary?: boolean) => void,
onFailure: (err: any) => void,
newPasswordRequired?: (userAttributes: any, requiredAttributes: any) => void,
mfaRequired?: (challengeName: any, challengeParameters: any) => void,
totpRequired?: (challengeName: any, challengeParameters: any) => void,
customChallenge?: (challengeParameters: any) => void,
mfaSetup?: (challengeName: any, challengeParameters: any) => void,
selectMFAType?: (challengeName: any, challengeParameters: any) => void
}
global['fetch'] = require('node-fetch');

使用文件顶部的上述代码。

最新更新