【发布时间】:2019-04-02 15:35:06
【问题描述】:
我将 AWS Cognito 与 Node.JS 结合使用。
我已成功注册和验证用户,但身份验证返回“未知错误,来自 fetch 的响应正文未定义。”
我正在使用 node-fetch 模块和 amazon-cognito-identity-js(在下面的代码中设置为 var AWSCognito)。用户未处于需要更改密码和验证的状态。
其他人是否遇到过这种情况,您是如何解决这个问题的? 提前感谢任何指导....
这是我的代码,我的完整模块在 npm 上作为 iditawsutils :
exports.authCognitoUser = function(theUserPoolID, theClientID, userName, userPassword) {
var authenticationData = {
Username : userName,
Password : userPassword
};
var authenticationDetails = new AWSCognito.AuthenticationDetails(authenticationData);
var poolData = { UserPoolId : theUserPoolID,
ClientId : theClientID
};
var userPool = new AWSCognito.CognitoUserPool(poolData);
var userData = {
Username : userName,
Pool : userPool
};
console.log('authentication details: ',authenticationDetails);
var cognitoUser = new AWSCognito.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
console.log('id token + ' + result.getIdToken().getJwtToken());
console.log('refresh token + ' + result.getRefreshToken().getToken());
return result;
},
onFailure: function(err) {
console.log(err.message || JSON.stringify(err));
return err;
},
});
}
//来自控制台日志:
authentication details: AuthenticationDetails {
validationData: {},
authParameters: {},
username: 'thesmarterstuff',
password: 'passW0rd!’ }
未知错误,来自 fetch 的响应正文是:未定义
【问题讨论】:
标签: node.js amazon-web-services amazon-cognito