我正在使用带有nodejs的amazon-cognito-identity-js创建一个auth api。我在尝试使用登录期间收到的refreshToken更新idToken时遇到问题。 这是我的下面的代码。
module.exports = class AuthenticationService{
constructor() {
this.poolData = {
UserPoolId: "xxxx", // Your user pool id here
ClientId: "xxxx" // Your client id here
};
this.pool_region = 'xxxx';
this.userPool = new AmazonCognitoIdentity.CognitoUserPool(this.poolData);
}
renewToken(data) {
const RefreshToken = new AmazonCognitoIdentity.CognitoRefreshToken({RefreshToken: data.refreshToken});
const userData = {
Username: data.username,
Pool: this.userPool
};
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
return new Promise((resolve, reject) => {
cognitoUser.refreshSession(RefreshToken, (err, session) => {
if (err) {
reject(err);
} else {
resolve(session);
}
});
});
};
}
refreshToken是我收到一个登录名的那个。但是,出现错误
{
"code": "NotAuthorizedException",
"name": "NotAuthorizedException",
"message": "Invalid Refresh Token."
}
有什么想法可能会出错吗?