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

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则