Cognito 自定义身份验证流程 - initiateAuth 提示错误

0

【以下的问题经过翻译处理】 我正试图使用 AWS Cognito 创建一个自定义身份验证流程,以便通过电子邮件发送 MFA 代码,而不是通过 Cognito 触发器。我正在使用 initiateAuth() 方法来实现这一功能,根据文档,该方法是正确的;

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

我的payload似乎是有效的,但当我尝试使用用户登录时,我收到错误消息“t.getauthparameters is not a function”

我查看了一些其他的stackoverflow帖子,但没有帮助

有没有什么想法出了什么问题?

以下是我的代码片段:

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);
			},
        });
profile picture
EXPERTE
gefragt vor 5 Monaten45 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 您不应在负载中添加CHALLENGE_NAME,而且您应该使用cognitoUser.authenticateUserAPI,而不是InitiateAuth(因为您正在使用基于SRP的身份验证,然后添加自定义挑战)。

以下是一个类似的示例,使用了与您尝试使用的SDK相同的SDK来实现自定义身份验证流程。如果您想使用Amplify而不是cognito-identity-sdk,那么这是一个实现类似功能的[博客文章](https://aws.amazon.com/blogs/mobile/extending-amazon-cognito-with-email-otp- for-2fa-using-amazon-ses/) 。

profile picture
EXPERTE
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen