【发布时间】:2016-12-07 10:41:37
【问题描述】:
所以我使用了在 AWS JS SDK 的官方仓库中找到的这段代码。 它用于对用户进行身份验证。
它返回一个空白响应。
AWSCognito.config.region = 'us-east-1';
var authenticationData = {
Username : '+1112223333', //some phone number used as an Alias
Password : 'password123456',
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : 'us-east-1_P00l1d', // Your user pool id here
ClientId : 'xxx' // Your client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : 'myusername',
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : 'xxx', // your identity pool id here
Logins : {
// Change the key below according to the specific region your user pool is in.
'cognito-idp.pool_id_number_here_xxx' : result.getIdToken().getJwtToken()
}
});
},
onFailure: function(err) {
alert(err)
console.log("Error " + err);
},
});
因此,对于 authenticationData,我使用电话号码作为用户名(电话号码设置为别名)和密码。我也直接尝试使用用户名。 UserPoolId 和 ClientId 是正确的,因为我使用相同的值来注册和确认电话号码。 在 userData 中,我将用户名设置为正确的 myusername。
关于身份池,我在 AWS 控制台上创建了一个身份池,该身份池链接到我的应用程序和我的 UserPool,并替换了 authenticateUser 中的 IdentityPoolId 和 Logins 值。 不过,我并不完全确定 Logins 中的值。我使用了 cognito-idp.POOLIDNUMBER。
AWS 的输出为空白。 我在想我什至无法访问服务器,并且我怀疑角色或身份池存在问题(我想 userPool 很好)。
我的身份池仅使用 AWS Cognito 用户,而不是 Facebook 或其他身份提供商。
【问题讨论】:
标签: javascript amazon-web-services cloud aws-sdk amazon-cognito