AWS Node JS MFA Cognito

Я работал над aws sdk для node js и пытался аутентифицировать пользователя из определенного пула пользователей. ПРИМЕЧАНИЕ. в моем пуле пользователей включена многофакторная аутентификация, и он получает OTP через SMS.

Это мой фрагмент кода: `var userData = {Имя пользователя: 'имя пользователя', Пул: userPool};

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

        });` 

НО: проблема в том, что выдает ошибку:

Error => {"code":"UnknownError", "message":"Неизвестная ошибка, тело ответа от выборки не определено"}

** И на трассировке стека я получил: ** Stack Trace : Error at Object.onFailure (E:\Karma\node_aws\medium_try\index.js:78:79) at E:\Karma\node_aws\medium_try\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:376:31 at E:\Karma\node_aws\medium_try\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:361:22 at E:\Karma\node_aws\medium_try\node_modules\amazon-cognito-identity-js\lib\Client.js:114:14 at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:228:7)

**НО СНОВА :::: **ОТР приходит на мой мобильный...

Пожалуйста, кто-нибудь может мне помочь????

Спасибо заранее


person Shoubhik Hexa    schedule 25.08.2018    source источник


Ответы (2)


Добавьте функции пропущенных обратных вызовов, чтобы вы могли правильно обрабатывать состояние:

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
}
person weizenberg    schedule 26.12.2018

global['fetch'] = require('node-fetch');

Используйте приведенный выше код в верхней части файла.

person Vishal Gupta    schedule 19.12.2019