【问题标题】:How to make authenticated Cognito request如何发出经过身份验证的 Cognito 请求
【发布时间】:2021-05-23 14:21:39
【问题描述】:

我可以为 Cognito 身份池成功运行 describeIdentityPool 命令,并启用“启用对未经身份验证的身份的访问”:

 var AWS = require("aws-sdk"); 
 let cognitoidentity = new AWS.CognitoIdentity();

  var params = {IdentityPoolId: "myIdentityPoolID"}; 

  cognitoidentity.describeIdentityPool(params, function(err, data) {
    if (err) {
      console.log(err, err.stack); 
    }
    else {
      console.log( "...getCredentials.describeIdentityPool.data:", data); 
    }
  });

但如果我禁用“启用对未经身份验证的身份的访问”复选框,我会收到错误消息:

NotAuthorizedException: Unauthenticated access is not supported for this identity pool.

有没有办法授权我向 Cognito 身份池发出的请求以避免此错误?

【问题讨论】:

    标签: javascript amazon-web-services amazon-cognito


    【解决方案1】:

    这完全在意料之中。 AWS 上的几乎所有 API 都需要访问密钥 ID 和秘密访问密钥。 describeIdentityPool API 就是其中之一。

    如果您为未经身份验证的用户启用访问权限,他们会收到允许他们执行该操作的临时凭据。默认允许的操作之一是cognito-identity:*。这是允许未经身份验证的用户调用此 API 的方法。您将能够在分配给“未经身份验证的身份”设置的角色中找到它。

    当您禁用未经身份验证的实体时,它们不再接收临时凭据,因此无法调用该 API。

    长话短说:按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 2012-04-24
      • 1970-01-01
      • 2019-03-29
      • 2014-12-05
      • 2019-09-25
      相关资源
      最近更新 更多