【发布时间】:2018-04-01 11:05:57
【问题描述】:
首先,我已经阅读了类似的问题:
- Using AWS Cognito can I resolve the authenticated IdentityId given a disabled unauthenticated IdentityId?
- AWS Lambda API gateway with Cognito - how to use IdentityId to access and update UserPool attributes?
我们使用 Cognito 用户并通过存储桶策略为他们提供对存储桶中文件夹的访问权限 - 例如 BUCKET_NAME/user_data/eu-west-2:00000000-0000-0000-0000-000000000000。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::BUCKET_NAME",
"Condition": {
"StringLike": {
"s3:prefix": [
"user_data/${cognito-identity.amazonaws.com:sub}/",
]
}
}
},
{
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": [
"arn:aws:s3:::BUCKET_NAME/user_data/${cognito-identity.amazonaws.com:sub}/*"
]
}
]
}
这非常适合使用 javascript API 的客户端。他们进行身份验证,我可以使用 AWS.config.credentials.identityId1 访问 S3。
但是,如果我想从我的 .Net Web API 后端访问用户的存储桶,我找不到获取 IdentityId 的方法。所以我不知道哪个文件夹是用户的,这违背了能够创建用户文件夹的整个目的。例如,当用户注册时,我可能想创建包含现有项目的文件夹...
一种解决方法是让客户端发布 IdentityId,以便它可以针对用户子存储,但是假设 - 1.它发生了; 2.身份证有效。
TLDR:如何使用 AWSSDK.CognitoIdentity 从 Cognito 用户名(子)中获取 Cognito IdentityId?
1 重要的一点 - 正如我在很长一段时间后发现的那样,${cognito-identity.amazonaws.com:sub} 不是用户子。文档非常不清楚,以至于我不知道 ${cognito-identity.amazonaws.com:sub} 会是什么样子。
【问题讨论】:
标签: .net amazon-web-services authentication amazon-s3 amazon-cognito