2017-08-17 29 views
2

我已經按照文檔中的所有步驟操作,通過電子郵件/密碼組合(工作)註冊用戶池,在身份池和用戶池中配置了FB身份提供程序部分爲身份提供者,並且實現了以下代碼示例http://docs.aws.amazon.com/cognito/latest/developerguide/facebook.html,並在下面使用我的身份池對其進行了修改。如何使用Facebook令牌創建Cognito身份

{代碼}

function facebookLogin(){ 
    FB.login(function (response) { 

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

     console.log('You are now logged in.' + response.authResponse.accessToken); 

     // Add the Facebook access token to the Cognito credentials login map. 
     AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
      IdentityPoolId: 'us-east-1:eb997110-50b3-4e40-97ff-fbaf796da9ef', 
      Logins: { 
       'graph.facebook.com': response.authResponse.accessToken // cognitouser.idToken 
      } 
     }); 
     console.log('Added FB access token to Cognito.'); 

     // Obtain AWS credentials 
     AWS.config.credentials.get(function(){ 
      //getCurrentUser(); 
      console.log('Got the aws creds.'); 
     }); 

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

{代碼}

我可以單步,看看FB令牌傳遞到CognitoIdentityCredentials並沒有錯誤,但用戶從來沒有在任何我的身份池被註冊或用戶池。

我錯過了什麼嗎?

+0

我有此刻的同一問題的代碼示例。任何人都有解決方案?謝謝。 – loveNZ

+0

我從來沒有得到過它,最終爲FB和Google做了一個自定義解決方案。 – Michael

回答

0

這裏是我使用的AWS

創建聯合身份
function loadCredentials(identityPool, provider, accessToken) { 

     var params = { 
      /*AccountId: window.appInfo.accountId,*/ 
      //RoleArn: window.ap 
      IdentityPoolId: identityPool, 
      Logins: {} 
     }; 
     params.Logins[provider] = accessToken; 
     AWS.config.credentials = new AWS.CognitoIdentityCredentials(params); 
     AWS.config.credentials.get(function (err) { 
      if (err) { 
       console.log(err.message); 
       console.log(err.stack); 
      } 
      else 
      { 
       console.log("Cognito Identity Id: " + AWS.config.credentials.identityId); 
       console.log("Worked"); 
      } 

     }); 
    } 
+0

這是與例子相同的代碼發佈,這是如何幫助使用fb註冊認知用戶? – user2976753

相關問題