2016-08-08 24 views
0

Ich konnte erfolgreich einen Benutzer anmelden, der Facebook zur Authentifizierung verwendet. Dies funktionierte gut und die Seite wurde wie erwartet auf eine andere Seite umgeleitet. Der Code ist unten angegeben.Abrufen der Cognito Identitäts-ID, wenn ich auf einer anderen Seite bin

Meine Frage ist Wie kann ich die Benutzer-ID (oder die Cognito Identity ID) abrufen, wenn ich auf einer anderen Seite bin? (Nicht in der gleichen Seite, aber, wenn ich auf einer anderen Seite bin)

AWS.config.region='us-east-1'; 
     AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 

      // either IdentityPoolId or IdentityId is required 
      // See the IdentityPoolId param for AWS.CognitoIdentity.getID (linked below) 
      // See the IdentityId param for AWS.CognitoIdentity.getCredentialsForIdentity 
      // or AWS.CognitoIdentity.getOpenIdToken (linked below) 
      IdentityPoolId: CognitoIdentityPoolId, 

      // optional, only necessary when the identity pool is not configured 
      // to use IAM roles in the Amazon Cognito Console 
      // See the RoleArn param for AWS.STS.assumeRoleWithWebIdentity (linked below) 
      RoleArn: 'arn:aws:iam::9287589741169:role/Cognito_111Auth_Role', 

      // optional tokens, used for authenticated login 
      // See the Logins param for AWS.CognitoIdentity.getID (linked below) 
      Logins: { 
       'graph.facebook.com': accessToken 
      }, 

      // optional name, defaults to web-identity 
      // See the RoleSessionName param for AWS.STS.assumeRoleWithWebIdentity (linked below) 
      RoleSessionName: 'web', 

      expired: 'true' 



     }); 
     console.log('Refreshing cognito credentials'); 
     AWS.config.credentials.refresh(function(err) { 
      if (err) { 
       console.log('Failed to refresh'); 
       return; 
      } else { 
       AWS.config.credentials.get(function(err){ 
        if (!err) { 
        var id = AWS.config.credentials.identityId; 
        console.log('Cognito Identity ID '+ id); 
        } 
       }); 

       var s3 = new AWS.S3(); 
       console.log('Creds '+ s3.config.credentials.sessionToken); 
      } 


     }); 


    } 

Antwort

0

Die Identität ID zwischen Seite Lasten zwischengespeichert wird, und Sie können sie abgerufen

var identityId = AWS.config.credentials.identityId ;

Anmeldeinformationen sind jedoch nicht zwischengespeichert, und Sie müssen Anmeldeinformationen jedes Mal erhalten.

Dieses Forum Beitrag helfen: https://forums.aws.amazon.com/thread.jspa?threadID=179420&tstart=25