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개 답변
1
수락된 답변

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
전문가
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인