Amazon Cognito javascript sdk列表记录了无效的安全令牌

Amazon Cognito javascript sdk列表记录了无效的安全令牌,javascript,node.js,amazon-web-services,amazon-cognito,Javascript,Node.js,Amazon Web Services,Amazon Cognito,我正在努力学习如何使用nodejs和amazon cognito。我使用的不是谷歌、facebook等,而是经过开发者身份验证的身份。我已经让这部分工作,可以看到在cognito中创建的身份。当我尝试运行listRecords时,尽管它不起作用。我只想将用户名添加到数据集中,看看它是否有效。它给了我下面的错误。我不太清楚安全令牌意味着什么,因为开发人员的访问权限和秘密密钥在从cognito中获取标识ID方面工作得很好 undefinedUnrecognizedClientException: T

我正在努力学习如何使用nodejs和amazon cognito。我使用的不是谷歌、facebook等,而是经过开发者身份验证的身份。我已经让这部分工作,可以看到在cognito中创建的身份。当我尝试运行listRecords时,尽管它不起作用。我只想将用户名添加到数据集中,看看它是否有效。它给了我下面的错误。我不太清楚安全令牌意味着什么,因为开发人员的访问权限和秘密密钥在从cognito中获取标识ID方面工作得很好

undefinedUnrecognizedClientException: The security token included in the request is invalid. UnrecognizedClientException: The security token included in the request is invalid.
下面是我使用的代码。错误发生在listRecords上,它没有执行error函数。据我所知,它在调用listRecords时失败。我也仔细检查了钥匙

// initialize the Credentials object
            AWS.config.credentials = new AWS.CognitoIdentity(params);

            AWS.config.credentials.getOpenIdTokenForDeveloperIdentity(params, function (err, data) {
                if (err) console.log("## credentials.get: ".red + err, err.stack);
                else {

                    AWS.config.credentials.identityId = data.IdentityId;
                    console.log(data);
                    var cognitosync = new AWS.CognitoSync();
                    cognitosync.listRecords({
                        DatasetName: "userData",
                        IdentityId: AWS.config.credentials.identityId,
                        IdentityPoolId: IDENTITY_POOL,
                    }, function (err, data) {
                        if (err) console.log("## listRecords: ".red + err, err.stack); // an error occurred
                        else {
                            console.log("This is the sync session token: " + data.SyncSessionToken);

                            //Parameters for updating the dataset
                            var params = {
                                DatasetName: "userData",
                                IdentityId: AWS.config.credentials.identityId,
                                IdentityPoolId: IDENTITY_POOL,
                                RecordPatches: [{
                                    Key: 'UserName',
                                    Op: 'replace',
                                    SyncCount: data.DatasetSyncCount,
                                    Value: 'FirstName' //this needs to be tied into first and last name
                                }]
                            };

                            //Make the call to Amazon Cognito
                            cognitosync.updateRecords(params, function (err, data) {
                                if (err) {
                                    console.log("## updateRecords: ".red + err, err.stack);
                                } // an error occurred
                                else {
                                    var dataRecords = JSON.stringify(data);
                                }
                            });
                        }

                    });

                }

本文档可能对您有所帮助:

大体上

(1) 您需要首先使用AWS.CognitoIdentity获取openIdToken来调用GetOpenIdTokenForDeveloperIdentity

上述文档中的“获取令牌(服务器端)”部分对此进行了描述

(2) 从上面获得令牌后,将AWS.config.credentials设置为:

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
   IdentityPoolId: 'IDENTITY_POOL_ID',
   IdentityId: 'IDENTITY_ID_RETURNED_FROM_YOUR_PROVIDER',
   Logins: {
      'cognito-identity.amazonaws.com': 'TOKEN_RETURNED_FROM_YOUR_PROVIDER'
   }
});
然后,您应该能够使用用户的凭据拨打电话