amazon-cognito-identity-js - 无法通过电子邮件验证用户身份

时间:2016-06-02 19:06:38

标签: amazon-web-services amazon-s3 aws-sdk amazon-cognito

如果我按照示例"验证用户"显示在http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html页面或"用例4"使用用户名在https://github.com/aws/amazon-cognito-identity-js/blob/master/README.md页面上的示例,该示例有效。

我正在尝试使用他们的电子邮件属性来验证用户,而不是用户名。我已将电子邮件属性标记为我的用户池中的别名。

AWS中的用户池控制台 User Pools Console in AWS

当我在"认证用户"中使用电子邮件代替用户名时示例我收到以下错误: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);
    },
});            
}

1 个答案:

答案 0 :(得分:2)

您确认了自己的电子邮件地址吗?如果您未确认您的电子邮件地址,则不能将其用作登录的别名。