AWS Cognito:首次登录管理员创建的用户时出现未知错误
AWS Cognito: unknown error when logging in the admin created user for the first time
每当我第一次尝试登录状态为 FORCE_PASSWORD_CHANGE 的用户时,我都会在 OnFailure 回调函数.
code:"UnknownError"
message:"200"
name:"UnknownError"
statusCode:200
当我点击登录按钮时,执行以下函数。
logInUser({username, password}){
const p = new Promise((res, rej)=> {
var authenticationData = {
Username: username,
Password: password,
};
var authenticationDetails = new AuthenticationDetails(authenticationData);
var userData = {
Username: username,
Pool: UserPool
};
var cognitoUser = new CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
alert("Success")
console.log('access token + ' + result.getAccessToken().getJwtToken());
console.log('idToken + ' + result.idToken.jwtToken);
res({result})
},
onFailure: function (err) {
console.log("Got an error")
console.log(err);
rej(err)
},
});
});
return p;
}
您需要传入newPasswordRequired 的回调来验证用户。
https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
res({result})
},
onFailure: function (err) {
rej(err)
},
newPasswordRequired: function(userAttributes, requiredAttributes) {
console.log("User needs new password");
res({userAttributes, requiredAttributes});
},
});
每当我第一次尝试登录状态为 FORCE_PASSWORD_CHANGE 的用户时,我都会在 OnFailure 回调函数.
code:"UnknownError"
message:"200"
name:"UnknownError"
statusCode:200
当我点击登录按钮时,执行以下函数。
logInUser({username, password}){
const p = new Promise((res, rej)=> {
var authenticationData = {
Username: username,
Password: password,
};
var authenticationDetails = new AuthenticationDetails(authenticationData);
var userData = {
Username: username,
Pool: UserPool
};
var cognitoUser = new CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
alert("Success")
console.log('access token + ' + result.getAccessToken().getJwtToken());
console.log('idToken + ' + result.idToken.jwtToken);
res({result})
},
onFailure: function (err) {
console.log("Got an error")
console.log(err);
rej(err)
},
});
});
return p;
}
您需要传入newPasswordRequired 的回调来验证用户。 https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
res({result})
},
onFailure: function (err) {
rej(err)
},
newPasswordRequired: function(userAttributes, requiredAttributes) {
console.log("User needs new password");
res({userAttributes, requiredAttributes});
},
});