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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南