2015-06-25 97 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