当错误消息说userName和password不匹配时,如何通过Cognito对用户池中的用户进行身份验证? [英] How do you authenticate a user in a user pool via Cognito when error messages say userName and password don't match even though they do?
问题描述
因此,我搞不清Cognito及其Javascript中的Beta用户池功能.由于可以在此处找到文档,因此我可以成功创建用户:
So I am messing around with Cognito and their Beta User Pools feature in Javascript. I am successfully creating users thanks to the documentation found here:
当我尝试对用户进行身份验证时,尽管收到一条奇怪的错误消息,提示:
When I try and authenticate the users though I get a strange error message saying:
NotAuthorizedException:用户名或密码错误.
NotAuthorizedException: Incorrect username or password.
我不明白为什么会这样,因为我从字面上复制并粘贴了用于创建用户的userName和password的值,效果很好.
I don't understand why this is the case as I am literally copying and pasting the values for userName and password that I used to create the user, which is working fine.
下面是我的用于验证用户身份的代码:
Below is my code to authenticate the user:
//----- Setup
AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'myIdentityPoolId'
});
AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'myIdentityPoolId'
});
var poolData = { UserPoolId : 'myUserPoolId',
ClientId : 'myClientId'
};
//-----Authenticate a user
alert('Authenticate a user with application');
var authenticationData = {
Username : 'markie17061993',
Password : 'MeowWoof123456789!',
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = { UserPoolId : 'myUserPoolId',
ClientId : 'myClientId'
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : 'markie17061993',
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
alert('hiss');
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
},
onFailure: function(err) {
alert(err);
},
});
您在这里看到任何问题吗?我以为在这两个地方,我的UserName参数可能是一个不同的值或其他值:
Do you see anything wrong here? I thought perhaps my UserName parameter in these two places is meant to be a different value or something:
var authenticationData = {
Username : 'markie17061993',
Password : 'MeowWoof123456789!',
};
var userData = {
Username : 'markie17061993',
Pool : userPool
};
谢谢
推荐答案
如果您没有确认新注册的用户,则不会显示您的代码.如果不是,那将解释NotAuthorizedException
.
Your code doesn't show if you are confirming the newly signed up user not. If you are not, that would explain the NotAuthorizedException
. This example specifically is what you want to follow.
If you do not want to confirm the users being signed up from you app, you should use a PreSignUp trigger to autoConfirm
your users.
这篇关于当错误消息说userName和password不匹配时,如何通过Cognito对用户池中的用户进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!