2016-08-08 6 views
0

認証するためにFacebookを使用するユーザーに正常にログインできました。これは正常に動作し、ページは期待どおりに別のページにリダイレクトされました。コードは以下の通りです。私は別のページにいるときにCognito ID IDを取得する

私の質問はどのように私は別のページにいるときにユーザーID(またはCognito Identity ID)を取得できますか?

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); 
      } 


     }); 


    } 

答えて

0

(同じページしかし、私は別のページに午前中でない)アイデンティティIDは、ページがロードの間でキャッシュされている、とあなたはそれを取得したことができ

VAR identityId = AWS.config.credentials.identityId ;

資格情報はで、キャッシュされていない場合はとなり、毎回資格情報を取得する必要があります。

このフォーラムの投稿は役に立ちます: https://forums.aws.amazon.com/thread.jspa?threadID=179420&tstart=25

関連する問題