Amazon-cognito-identity-js: Error: Missing required parameter Session when calling sendMFACode

Created on 1 Feb 2017  路  4Comments  路  Source: amazon-archives/amazon-cognito-identity-js

When executing the following code:

export const sendMFACode = ( mfaCode ) => {

    // Create userPool
    let userPool = new CognitoUserPool( poolData );

    //Get logged in user
    let cognitoUser = userPool.getCurrentUser();

    // sendMFACode    
    cognitoUser.sendMFACode( mfaCode, {
        onSuccess: function( result ) {
           // User authentication was successful
            console.log( 'result', result );
        },

        onFailure: function( err ) {
           // User authentication was not successful
            console.log( 'err', err );
        },
    } );
};

I get the following error:

x-amzn-ErrorMessage:Missing required parameter Session
x-amzn-ErrorType:InvalidParameterException:

Wrapping the cognitoUser.sendMFACode call in a cognitoUser.getSession() doesn't seem to work.

It's probably due to calling the sendMFACode function from out of the authenticateUser scope.

I can't figure out how to fix this, any ideas?

Most helpful comment

Yes this should be closed, excuse me for this non-issue.

For anyone coming here in the future via Google: My mistake was assuming that when calling authenticateUser, when MFA is required, the user will be stored and can be gotten again with cognitoUser = userPool.getCurrentUser();. This is not the case.

If you have sending authenticateUser and sendMFA in different functions (unlike the example), you need to call these functions on the same cognitoUser, to which you would need to keep a reference to.

All 4 comments

Never mind, I resolved this issue. I included a call to userPool.getCurrentUser(), which was not supposed to be there. The result of this function was a previously logged in user, when MFA was not activated.

@ZwaarContrast should the issue be closed then?

Yes this should be closed, excuse me for this non-issue.

For anyone coming here in the future via Google: My mistake was assuming that when calling authenticateUser, when MFA is required, the user will be stored and can be gotten again with cognitoUser = userPool.getCurrentUser();. This is not the case.

If you have sending authenticateUser and sendMFA in different functions (unlike the example), you need to call these functions on the same cognitoUser, to which you would need to keep a reference to.

Hi , I do see this issue still happening, I have mfa flow from login and i try to confirm the code

cognitoUser.sendMFACode(code, callback)

I always get exception InvalidParameterException: Missing required parameter Session , Btw, this is used in context of a Lambda not in client side Javascript

Any pointers on this is appreciated

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpitzen picture kpitzen  路  3Comments

magnattic picture magnattic  路  5Comments

JakubMatejka picture JakubMatejka  路  4Comments

m-schrepel picture m-schrepel  路  6Comments

sarah-pixvana picture sarah-pixvana  路  5Comments