AWS Cognito 不使用联合身份进行身份验证

AWS Cognito does not authenticate using Federated Identity

我对这个问题束手无策。我一直在尝试对来自 Firebase 的 Facebook 登录用户进行身份验证,以便我可以允许将图像上传到 S3 存储桶。我倾注了文档、示例代码、博客条目等。但我不断收到以下错误:

Error: Not authorized to perform sts:AssumeRoleWithWebIdentity

这是我遵循但没有成功的文档: External Identity Providers » Facebook

我也多次阅读此博客条目 Understanding Amazon Cognito Authentication 并且这句话似乎是正在发生的事情:

If you see this, double check that you are using an appropriate role for your identity pool and authentication type.

我明白它在说什么,但我找不到解决方案。我不想存储用户,我只想进行身份验证并获取临时凭据。这是我的代码、角色和策略文件。

JavaScript

AWS.config.update({
  region: bucketRegion,
  credentials: new AWS.CognitoIdentityCredentials({
  IdentityPoolId: IdentityPoolId,
  Logins: {
      'graph.facebook.com': 'my-valid-auth-token-from-fb-after-login'
    }
  })
});

AWS.config.credentials.get(function(err) {
    // error here
}

经过身份验证的 IAM 角色策略 - 内联

{
  "Version": "2012-10-17",
  "Statement": [
    {
        "Sid": "myuserBucketActions",
        "Action": [
            "s3:GetBucketLocation",
            "s3:ListBucketMultipartUploads"
        ],
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::bucket-name"
    },
    {
        "Sid": "myuserListBucket",
        "Action": [
            "s3:ListBucket"
        ],
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::bucket-name",
        "Condition": {
            "StringLike": {
                "s3:prefix": "folder-in-bucket/*"
            }
        }
    },
    {
        "Sid": "myuserObjectActions",
        "Action": [
            "s3:AbortMultipartUpload",
            "s3:GetObject",
            "s3:PutObject"
        ],
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::bucket-name/folder-in-bucket/*"
    }
  ]
}

IAM 角色策略的信任关系

{
  "Version": "2012-10-17",
  "Statement": [
{
  "Sid": "",
  "Effect": "Allow",
  "Principal": {
    "Federated": "graph.facebook.com"
  },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": {
    "StringEquals": {
      "graph.facebook.com:appId": "FACEBOOK_APP_ID"
    }
   }
  }
 ]
}

我在信任关系和池中的身份验证提供程序中拥有正确的 FB 应用程序 ID。我还在我的池中的身份验证角色下选择了上述身份验证角色。我也不允许未经身份验证的身份。

老实说,我不知道出了什么问题。在这一点上,我正在向墙上扔意大利面条,看看有什么粘住。

快速附带的问题:如果我不能让它工作并与未经身份验证的用户一起使用,然后切换到经过身份验证的用户,潜在的后果是什么?

感谢您能给我的任何帮助!

似乎信任关系不允许您调用sts:AssumeRoleWithWebIdentity。

你能代替

"Condition": {
    "StringEquals": {
      "graph.facebook.com:appId": "FACEBOOK_APP_ID"
    }
   }
  }

由此

"ForAnyValue:StringLike": {
  "cognito-identity.amazonaws.com:amr": "graph.facebook.com"
}

也替换

 "Principal": {
    "Federated": "graph.facebook.com"
  }

来自

"Principal": {
        "Federated": "cognito-identity.amazonaws.com"
      }