Node.js getCurrentUser()返回null[后端]
我正在尝试设置联合身份以获取身份的凭据。但是当我尝试执行getCurrentUser()时,得到的响应为null。关于这一点的另一件事是,我在后端尝试这一点。那么它会在后端工作吗?为什么在尝试getCurrentUser时得到空响应??有什么想法吗Node.js getCurrentUser()返回null[后端],node.js,amazon-cognito,Node.js,Amazon Cognito,我正在尝试设置联合身份以获取身份的凭据。但是当我尝试执行getCurrentUser()时,得到的响应为null。关于这一点的另一件事是,我在后端尝试这一点。那么它会在后端工作吗?为什么在尝试getCurrentUser时得到空响应??有什么想法吗 var data = { UserPoolId: userPoolId, ClientId: appClientId, }; var userPool = new AmazonCognitoIdentity.CognitoUse
var data = {
UserPoolId: userPoolId,
ClientId: appClientId,
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(data);
console.log(userPool);
var cognitoUser = userPool.getCurrentUser();
console.log(cognitoUser);
userPool的日志响应为
CognitoUserPool {
userPoolId: 'us-east-6_hxxxx2U',
clientId: '`6heh4h8h848h4884h05',
client:
Client {
endpoint: 'https://cognito-idp.us-east-1.amazonaws.com/',
userAgent: 'aws-amplify/0.1.x js' },
advancedSecurityDataCollectionFlag: true,
storage:
{ [Function: MemoryStorage]
setItem: [Function: setItem],
getItem: [Function: getItem],
removeItem: [Function: removeItem],
clear: [Function: clear] } }
cognitoUser的日志响应为NULL
那么,为什么响应为空,而我提供正确的值作为输入?几乎没有潜在的原因:
getCurrentUser()
而不是getCurrentUser(数据)
.....
// and the Audience (use claims.client_id if verifying an access token)
if (claims.aud != app_client_id) {
callback('Token was not issued for this audience');
}
//add your code here
callback(null, claims);
}).
catch(function() {
callback('Signature verification failed');
});
而且用户信息应该在
声明中
因为我在这里发布的代码是针对前端的。有一篇文章清楚地说明了我们应该如何验证用户
因此,在正确的身份验证流之后,我们将使用
cognitoidentity.getCredentialsForIdentity()
[参考官方sdk文档]传递所需的数据,那么我如何在后端登录用户?您能指定使用什么功能吗?用户是否从前端登录?否。我将令牌传递给前端。就这样!您是否使用Cognito托管ui?否。我使用admin\u srp\u auth从后端登录用户。你能解释一下你在答案上写的第二点吗??