0
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
     IdentityPoolId: 'us-east-1:2ce7b2c2-898f-4a26-9066-d4feff8ebfe4' 
    }); 

    // Make the call to obtain credentials 
    AWS.config.credentials.get(function(){ 

     // Credentials will be available when this function is called. 
     var accessKeyId = AWS.config.credentials.accessKeyId; 
     var secretAccessKey = AWS.config.credentials.secretAccessKey; 
     var sessionToken = AWS.config.credentials.sessionToken; 
     //var identityId = AWS.config.credentials.identityId; 

     return res.send({ 
     accessKeyId: accessKeyId 
     }); 

    }); 

所有變量都有空值。爲什麼?我究竟做錯了什麼?有沒有其他方法可以訪問它?從aws中獲取訪問令牌,祕密訪問密鑰和會話令牌

而且我應該送一個祕密密鑰和令牌來獲取會話密鑰

UPDATE:

當我嘗試這種方法,我得到一個錯誤說: 錯誤:NotAuthorizedException:未認證此身份池不支持訪問。

AWS.config.credentials.get(function(err) { 
    if (err) { 
     console.log("Error: "+err); 
     return; 
    } 
    console.log("Cognito Identity Id: " + AWS.config.credentials.identityId); 

    // Other service clients will automatically use the Cognito Credentials provider 
    // configured in the JavaScript SDK. 
    var cognitoSyncClient = new AWS.CognitoSync(); 
    cognitoSyncClient.listDatasets({ 
     IdentityId: AWS.config.credentials.identityId, 
     IdentityPoolId: "" 
    }, function(err, data) { 
     if (!err) { 
      console.log(JSON.stringify(data)); 
     } 
     return res.send({ 
      data: data 
     }); 
    }); 
    }); 

回答

0

你看到你沒有設置你的身份池允許未經授權的身份表示異常。

當您調用獲取憑證時,您沒有在登錄映射中傳遞任何登錄,這意味着您的用戶未經身份驗證(身份池不允許)。

下面是描述如何使用外部標識提供者來驗證一些文檔: http://docs.aws.amazon.com/cognito/latest/developerguide/external-identity-providers.html

+0

謝謝!我必須在aws控制檯設置中檢查允許未經身份驗證的連接。 – karankumar89

相關問題