【问题标题】:AWS Node JS MFA CognitoAWS 节点 JS MFA Cognito
【发布时间】:2019-01-31 15:19:06
【问题描述】:

我正在为 node js 开发 aws sdk,并尝试对来自特定用户池的用户进行身份验证。 注意:我的用户池启用了多重身份验证并通过 SMS 接收 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);
            }

        });` 

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

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

**我得到了堆栈跟踪:** 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)

**BUT AGAIN :::: **OTP 来到我的手机...

谁能帮帮我???

提前感谢

【问题讨论】:

    标签: aws-sdk aws-cognito aws-sdk-nodejs


    【解决方案1】:

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

    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
    }
    

    【讨论】:

      【解决方案2】:
      global['fetch'] = require('node-fetch');
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-19
        • 2021-08-29
        • 1970-01-01
        • 2023-03-05
        相关资源
        最近更新 更多