2015-06-25 155 views
3

我想直接从角度js上的浏览器将对象放入AWS S3。
为此,我使用cognito开发人员身份验证。 我从我的Rails服务器获得了认证身份标识和令牌。AWS 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' }}); 

(0000部分只是样品)
不知有为 'identity_id'从cognito.get_open_id_token_for_developer_identity没有空间。
配置regioin和s3区域不同因为我使用东京S3但n.virginia Cognito。

++我在我的角色(myRoleName)中添加了s3对受管策略的完全访问权限,并将以下设置添加到内联策略中。 (我还在Inline策略中添加了'resource * version of below setting')

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
      "Sid": "0000", 
      "Effect": "Allow", 
      "Action": [ 
       "s3:GetObject", 
       "s3:PutObject" 
      ], 
      "Resource": [ 
       "arn:aws:s3:::myBucketName" 
      ] 
     } 
    ] 
} 

回答

3

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

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

我推荐使用“增强型authflow”。为此,请执行以下操作:
(1)确保您的身份池配置有您希望用户使用的角色:http://docs.aws.amazon.com/cognito/devguide/identity/concepts/iam-roles/
(2)删除身份构造函数的AccountId和RoleArn参数。

+0

我试过增强authflow,但使用基本的authflow方法。现在我知道发生了什么,它的工作原理!谢谢! – cancue