我正在尝试使用其JavaScript SDK来了解Cognito身份验证。我有以下代码(由React应用程序中的表单触发):
import {
CognitoUserPool,
AuthenticationDetails,
CognitoUser
} from "amazon-cognito-identity-js";
const poolData = {
UserPoolId: MY_POOL_ID,
ClientId: APP_CLIENT_ID
};
export function cognitoLogin(credentials, callback) {
const authenticationDetails = new AuthenticationDetails(credentials);
const userPool = new CognitoUserPool(poolData);
const cognitoUser = new CognitoUser({
Username: credentials.username,
Pool: userPool
});
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function(response) {
console.log("SUCCESS!");
console.log(response);
},
onFailure: function(error) {
console.log("FAILURE!");
console.log(error);
}
});
}
我生成的客户端应用程序没有任何秘密。我生成了一个用户,并使用自定义域UI来登录该用户并进行确认。但是,当我尝试通过SDK登录时,
{
code: "NotAuthorizedException",
message: "Incorrect username or password.",
name: "NotAuthorizedException"
}
错误。我可能会缺少什么?
最佳答案
credentials
对象必须包含键Username
和Password
-注意它们的首字母大写,但您的字母似乎全部为小写。