我正在尝试使用其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
-请注意,它们的首字母大写,但您的似乎全部为小写。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句