amazon-cognito-identity-js - 无法通过电子邮件对用户进行身份验证
amazon-cognito-identity-js - Trouble Authenticating a User via email
如果我按照 http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html page or the "Use case 4" example on the https://github.com/aws/amazon-cognito-identity-js/blob/master/README.md 页面上显示的示例 "Authenticate a User" 使用用户名,则该示例有效。
我正在尝试使用用户的电子邮件属性而不是用户名对用户进行身份验证。我在我的用户池中将电子邮件属性标记为别名。
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) 通过电子邮件地址对用户进行身份验证?
代码示例
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);
},
});
}
您是否确认了您的电子邮件地址?如果您没有确认您的电子邮件地址,则不能将其用作登录的别名。
如果我按照 http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html page or the "Use case 4" example on the https://github.com/aws/amazon-cognito-identity-js/blob/master/README.md 页面上显示的示例 "Authenticate a User" 使用用户名,则该示例有效。
我正在尝试使用用户的电子邮件属性而不是用户名对用户进行身份验证。我在我的用户池中将电子邮件属性标记为别名。
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) 通过电子邮件地址对用户进行身份验证?
代码示例
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);
},
});
}
您是否确认了您的电子邮件地址?如果您没有确认您的电子邮件地址,则不能将其用作登录的别名。