Cognito custom authentication flow - initiateAuth giving error

0

I am trying to make a custom authentication flow using AWS Cognito so that i can send MFA codes via email instead through the cognito triggers. I am using the initiateAuth() method to do this which is correct according to the documentation;

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#initiateAuth-property

My payload seems to be valid but when i try login with a user i get the error 't.getauthparameters is not a function'

I've had a look through some other stackoverflow posts but nothing is helping

Any ideas what is going wrong?

This is a snippet from my code below:

const payload = {
		  AuthFlow: 'CUSTOM_AUTH',
		  ClientId: 'my client id', 
		  AuthParameters: {
			 USERNAME: $('input[name=username]').val(),
			 PASSWORD: $('input[name=password]').val(),
			 CHALLENGE_NAME: 'SRP_A'
		  }
		};
		
		cognitoUser.initiateAuth(payload, {
			onSuccess: function(result) {
				// User authentication was successful
			},
			onFailure: function(err) {
				// User authentication was not successful
			},
			customChallenge: function(challengeParameters) {
				// User authentication depends on challenge response
				var verificationCode = prompt('Please input OTP code' ,'');
				cognitoUser.sendCustomChallengeAnswer(verificationCode, this);
			},
        });

1 Respuesta
1
Respuesta aceptada

Hi,

You shouldn't add CHALLENGE_NAME in your payload and you should use the API cognitoUser.authenticateUser instead of InitiateAuth (since you are using SRP-based authentication then adding a custom challenge).

Here is a some what similar example that uses the same SDK that you are tying to use to implement custom auth flow. If you would like to use Amplify instead of the cognito-identity-sdk then here is a blog post that implements something similar.

AWS
EXPERTO
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas