如果我按照http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html页面上显示的示例"Authenticate a User"或使用用户名在https://github.com/aws/amazon-cognito-identity-js/blob/master/README.md页面上的"Use case 4"示例,则示例有效 .
我正在尝试使用他们的电子邮件属性而不是用户名对用户进行身份验证 . 我已将电子邮件属性标记为我的用户池中的别名 .
User Pools Console in AWS
当我在"Authenticate a User"示例中使用电子邮件代替用户名时,我收到以下错误: ResourceNotFoundException: Username/client id combination not found.
我在下面包含了我的代码示例 .
如何使用"Amazon Cognito Identity SDK for JavaScript"(https://github.com/aws/amazon-cognito-identity-js)通过电子邮件地址对用户进行身份验证?
Code Sample
function authenticateUserViaEmail() {
log("authenticateUserViaEmail called");
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: identityPoolId,
});
AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: identityPoolId,
});
var authenticationData = {
Username : document.getElementById("email").value,
Password : document.getElementById("password").value
};
log("using: " + JSON.stringify(authenticationData));
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = { UserPoolId : userPoolId,
ClientId : clientId
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : document.getElementById("email").value,
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
log("About to call authenticateUser...");
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
log('Access token: ' + result.getAccessToken().getJwtToken());
},
onFailure: function(err) {
log(err);
console.error(err);
},
});
}
1 回答
你确认了你的电子邮件地址吗?如果您未确认您的电子邮件地址,则不能将其用作登录的别名 .