1

Ich arbeite für eine WebApp mit AWS. Ich versuche, Elemente aus meiner DynamoDB-Tabelle abzurufen, erhalte jedoch den Fehler "Nicht authentifizierter Zugriff wird für diesen Identitätspool nicht unterstützt". Ich möchte nicht, dass meine App über nicht authentifizierte Benutzer verfügt, ich mich jedoch vor dem Aufruf der DynamoDB-Abfrage anmelde. Kann mir jemand helfen? Hier ist mein Code:Melden Sie sich mit Facebook an, erhalten aber immer noch: "Nicht authentifizierter Zugriff wird für diesen Identitätspool nicht unterstützt"

function facebookLogin() { 

FB.login(function (response) { 
    if (response.authResponse) { // logged in 
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
     IdentityPoolId: 'myActualPoolId' 
    }); 

    AWS.config.region = 'us-east-1'; 
    AWS.config.credentials.params.logins = {} 
    AWS.config.credentials.params.logins['graph.facebook.com'] = response.authResponse.accessToken; 
    AWS.config.credentials.expired = true; 



    console.log("Importing drivers into DynamoDB. Please wait."); 


    var drivers = JSON.parse('[{"userId": "4","driverId": "4d","ratingValue": 3,"truckId": "4"},{"userId": "5","driverId": "5d","ratingValue": 2,"truckId": "5"}]'); 
    drivers.forEach(function(driver) { 
     var params = { 
      TableName: "myActualTableName", 
      Item: { 
       "userId": driver.year, 
       "driverId": driver.title, 
       "ratingValue": driver.info, 
       "truckId": driver.truckId 
      } 
     }; 

     var docClient = new AWS.DynamoDB.DocumentClient(); 
     docClient.put(params, function(err, data) { 
      if (err) { 
       console.error("Unable to add driver", driver.userId, ". Error JSON:", JSON.stringify(err, null, 2)); 
      } else { 
       console.log("PutItem succeeded:", driver.userId); 
      } 
     }); 
    }); 

    } else { 
    console.log('There was a problem logging you in.'); 
    } 
    }); 
} 

Ich würde jede Hilfe zu schätzen wissen. Vielen Dank!

Antwort

2

Sie sind sehr nah dran. Cognito-Anmeldeinformationsanbieter erhalten die Anmeldeinformationen langsam. Wenn Sie also die Logins einrichten, werden Sie nicht aufgefordert, die Anmeldung mit der Identität zu verknüpfen, sodass der Aufruf von Dynamo mit einer nicht authentifizierten ID erfolgt. Der Cognito dev guide hat spezifische Beispiele dafür, wie dies zu tun ist, ein relevanter ist unten:

FB.login(function (response) { 

// Check if the user logged in successfully. 
if (response.authResponse) { 

console.log('You are now logged in.'); 

// Add the Facebook access token to the Cognito credentials login map. 
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
    IdentityPoolId: 'IDENTITY_POOL_ID', 
    Logins: { 
    'graph.facebook.com': response.authResponse.accessToken 
    } 
}); 

// Obtain AWS credentials 
AWS.config.credentials.get(function(){ 
    // Access AWS resources here. 
}); 

} else { 
    console.log('There was a problem logging you in.'); 
} 

}); 
+0

Perfekt! Vielen Dank! –

Verwandte Themen