我正在尝试为我的应用创建登录页面。它是纯HTML CSS和JS。我已经在AWS-cognito cl中创建了用户,但是当我尝试使用凭证时,该用户无法登录,而我得到的唯一信息是这是一个未知错误。
我已尝试在此周围找到一些东西,但实际上什么都没发生。我设法找到的很多答案将引用newPasswordRequired函数或所使用的sdk版本。我已仔细检查并三重检查了用户池ID和客户端ID。
function signInButton() {
var authenticationData = {
Username : document.getElementById("inputUsername").value,
Password : document.getElementById("inputPassword").value,
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : _config.cognito.userPoolId,
ClientId : _config.cognito.clientId,
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : document.getElementById("inputUsername").value,
Pool : userPool,
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
resolve(result.getAccessToken().getJwtToken());
},
onFailure: function (err) {
console.log("Error from cognito promise: ", err);
},
newPasswordRequired: function (userAttributes) {
delete userAttributes.email_verified;
cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, this);
}
});
};
我显然希望它执行的操作是登录并转到指定的页面,我知道错误功能确实起作用,因为在此之前我实际上已经获得了信息。我既不希望也不需要MFA,或者我只是想与用户登录并通过管理员设置的通行证,所以我可能在cl中设置了错误。
在这里要做的聪明的事情是看一下我如何处理newPassword函数。我没有给它一种更改密码的方法或机会,因为我的应用程序要求用户获得由admin创建的登录名,而该登录名是由admin创建的,要求用户在登录时更改密码。
newPasswordRequired: function (userAttributes,requiredAttributes) {
delete userAttributes.email_verified;
let attributesData = {name: authenticationData.Username}
var newPassword = prompt('Enter new password ' ,'');
cognitoUser.confirmPassword( newPassword, this);
cognitoUser.completeNewPasswordChallenge(newPassword, attributesData, this);
}