2017-08-17 55 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

相关问题