由于AWS Cognito不目前支持密码认证需要实现随机密码解决方法外部存储。您可以实现认证流程如下。
- 用户注册后(也索要手机号码,并强制),存储手机号码,用户名和密码也是我n使用AWS KMS加密的Dynamodb(用于额外的安全性)。
- 您可以使用带手机号码的MFA进行身份验证质询,以便在用户输入手机号码并按登录(在前端)后,您可以在后端自动执行用户名密码匹配(通过)并触发MFA发送代码用于用户的移动设备并验证是否使用AWS Cognito SDK(不实施自定义移动消息和挑战)。
- 如果您计划手动实施流程(不使用MFA)发送SMS &验证,则可以将AWS SNS用于此目的。
请查看以下代码示例以了解MFA的见解,并参考this link了解更多详细信息。
var userData = {
Username : 'username',
Pool : userPool
};
cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
var authenticationData = {
Username : 'username',
Password : 'password',
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
alert('authentication successful!')
},
onFailure: function(err) {
alert(err);
},
mfaRequired: function(codeDeliveryDetails) {
var verificationCode = prompt('Please input verification code' ,'');
cognitoUser.sendMFACode(verificationCode, this);
}
});
注意:这里带移动号码的MFA并不是用于MFA的目的,而是作为解决方法来满足您的要求。
非常感谢Ashan。这回答我的问题:) – spar