0

我一直在将 fb AccounKit 与我的 ionic 应用程序(NodeJS 服务器)集成。前端部分已经完成,我可以发送和接收 OTP 和成功状态。

但是,在从授权代码中获取客户端令牌时,我不断收到““验证令牌中的“访问令牌”错误”错误。我遵循了他们官方文档中提到的相同程序。

这是我的代码:

var me_endpoint_base_url = 'https://graph.accountkit.com/v1.0/me';
token_exchange_base_url='https://graph.accountkit.com/v1.0/access_token';

var params = {
  grant_type: 'authorization_code',
  code: request.body.code,
  access_token: app_access_token
 };
}

// exchange tokens
console.log(Querystring.stringify(params))
var token_exchange_url = token_exchange_base_url + '?' + Querystring.stringify(params);
Request.get({url: token_exchange_url, json: true}, function(err, resp, respBody) {
  console.log(respBody);
  var view = {
    user_access_token: respBody.access_token,
    expires_at: respBody.expires_at,
    user_id: respBody.id,   
  };
  var me_endpoint_url = me_endpoint_base_url + '?access_token=' + respBody.access_token;
  Request.get({url: me_endpoint_url, json:true }, function(err, resp, respBody) {
    console.log(respBody);
    if (respBody.phone) {
      view.method = "SMS"
      view.identity = respBody.phone;
    } else if (respBody.email) {
      view.method = "Email"
      view.identity = respBody.email.address;
    }
  });
});

请帮忙?

4

1 回答 1

3

在进行服务器到服务器调用以交换令牌代码时,您需要在您发送的访问令牌中提供您的 Account Kit App Secret。因此访问令牌应如下所示:

'AA|{app_id}|{app_secret}'

例如。

var app_access_token = ['AA', app_id, app_secret].join('|');

您可以从 Account Kit 仪表板中找到您的应用程序密码。转到developers.facebook.com上您应用程序产品部分下的“Account Kit”页面,然后单击“Account Kit App Secret”框旁边的“显示”按钮以查看您的应用程序密码。

另请记住,您永远不应该在客户端运行的任何 javascript 代码中包含您的应用程序密码。这个秘密只能从你的服务器端 node.js 代码中使用,其他人应该不能看到它

于 2017-09-14T01:15:53.213 回答