【问题标题】:How do I create a Cognito Identity with Facebook token如何使用 Facebook 令牌创建 Cognito 身份
【发布时间】:2017-09-14 15:57:17
【问题描述】:

我已完成文档中的所有步骤,通过电子邮件/密码组合进行注册的用户池(工作),在身份池和身份提供者的用户池部分中配置了 FB 身份提供者,并实现了以下代码在此处找到示例http://docs.aws.amazon.com/cognito/latest/developerguide/facebook.html,并在下面使用我的身份池进行了修改。

{代码}

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 并且没有错误,但用户从未在我的身份池或用户池中注册。

我错过了什么吗?

【问题讨论】:

  • 我现在遇到了同样的问题。有人有解决方案吗?谢谢。
  • 我从来没有得到它,最终为 FB 和 Google 做了一个自定义解决方案。

标签: facebook-javascript-sdk aws-sdk aws-cognito


【解决方案1】:

这是我用于在 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");
            }

        });
    }

【讨论】:

  • 这与示例发布的代码相同,这如何帮助用户使用 fb 在 cognito 中注册?
猜你喜欢
  • 2018-10-05
  • 2012-12-09
  • 2020-08-30
  • 1970-01-01
  • 2017-04-23
  • 2018-04-18
  • 1970-01-01
  • 1970-01-01
  • 2016-04-11
相关资源
最近更新 更多