【问题标题】:Retrieve the access token, secret access key and session token from aws cognito从 aws cognito 检索访问令牌、秘密访问密钥和会话令牌
【发布时间】:2016-06-10 06:28:18
【问题描述】:
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
      IdentityPoolId: 'us-east-1:2ce7b2c2-898f-4a26-9066-d4feff8ebfe4'
  });

  // Make the call to obtain credentials
  AWS.config.credentials.get(function(){

      // Credentials will be available when this function is called.
      var accessKeyId = AWS.config.credentials.accessKeyId;
      var secretAccessKey = AWS.config.credentials.secretAccessKey;
      var sessionToken = AWS.config.credentials.sessionToken;
      //var identityId = AWS.config.credentials.identityId;

      return res.send({
        accessKeyId: accessKeyId
      });

  });

所有变量都有空值。为什么?我究竟做错了什么?有没有其他方法可以访问它?

我还应该发送一个密钥和令牌来检索会话密钥

更新:

当我尝试这种方法时,我收到一条错误消息: 错误:NotAuthorizedException:此身份池不支持未经身份验证的访问。

AWS.config.credentials.get(function(err) {
    if (err) {
        console.log("Error: "+err);
        return;
    }
    console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);

    // Other service clients will automatically use the Cognito Credentials provider
    // configured in the JavaScript SDK.
    var cognitoSyncClient = new AWS.CognitoSync();
    cognitoSyncClient.listDatasets({
        IdentityId: AWS.config.credentials.identityId,
        IdentityPoolId: ""
    }, function(err, data) {
        if ( !err ) {
            console.log(JSON.stringify(data));
        }
        return res.send({
          data: data
        });
    });
  });

【问题讨论】:

    标签: javascript node.js authentication amazon-web-services amazon-cognito


    【解决方案1】:

    您看到的异常意味着您尚未设置身份池以允许未经身份验证的身份。

    当您调用 get credentials 时,您没有在登录映射中传递任何登录信息,这意味着您的用户未经过身份验证(您的身份池不允许这样做)。

    以下是一些描述如何使用外部身份提供者进行身份验证的文档: http://docs.aws.amazon.com/cognito/latest/developerguide/external-identity-providers.html

    【讨论】:

    • 谢谢!我必须在 aws 控制台设置中检查允许未经身份验证的连接。
    猜你喜欢
    • 2011-12-31
    • 2012-04-28
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 2012-12-29
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多