AWS Cognito使用Developer身份验证中的令牌无效登录令牌错误

can*_*cue 5 amazon-s3 amazon-web-services angularjs amazon-cognito

我想直接从角度js上的浏览器将对象放到AWS S3.
为此,我使用了cognito开发人员身份验证.我从我的rails服务器获得了cognito身份标识和令牌.

使用该令牌(我认为它是有效的),我的put操作被拒绝来自AWS S3:无效的登录令牌.
我不知道为什么..

这是我的代码.

AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  AccountId: '0000',
  IdentityPoolId: 'us-east-1:0000-0000-0000',
  RoleArn: 'arn:aws:iam::0000:role/myRoleName',
  Logins: {
    'cognito-identity.amazonaws.com': 'token from cognito.get_open_id_token_for_developer_identity'
  }
});
var bucket = new AWS.S3({ params: { Region: 'ap-northeast-1', Bucket: 'my bucket name' }});
Run Code Online (Sandbox Code Playgroud)

(0000部分只是样本)
我想知道来自cognito.get_open_id_token_for_developer_identity的'identity_id'没有空间.
配置区域和s3区域是不同的,因为我使用东京S3但是n.virginia Cognito.

++我在我的角色(myRoleName)中添加了对托管策略的s3完全访问权限,并在下面的设置中添加了内联策略.(我还在内联策略中添加了'以下设置的资源*版本')

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "0000",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::myBucketName"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*rio 3

您似乎正在尝试使用“Basic authflow”。以下是我们有关身份验证流程的文档的链接:
http://docs.aws.amazon.com/cognito/devguide/identity/concepts/authentication-flow/#developer-authenticated-identities-authflow

这没有使用您在登录映射中提供的令牌。

我建议使用“增强的身份验证流程”。为此:
(1) 确保您的身份池配置了您希望用户使用的角色:http://docs.aws.amazon.com/cognito/devguide/identity/concepts/iam-roles/
(2 ) 删除身份构造函数的 AccountId 和 RoleArn 参数。