doukun0888 2017-01-24 12:18
浏览 32

在自定义API中处理FB访问令牌的最佳实践

I have developing a restful api where the client provides a facebook user id (let say myapi/get_user/123) and the API must retrieve user's public information like name, birthday, etc. That it's done.

Current code:

$fb = new Facebook\Facebook([
        'app_id' => $fbSettings['app_id'],
        'app_secret' => $fbSettings['app_secret'],
        'default_graph_version' => $fbSettings['default_graph_version']
]);

$token = 'EAAD...';

try {
  // Returns a `Facebook\FacebookResponse` object
  $fbResponse = $fb->get('/' . $request->getAttribute('id') . '?fields=link, name, birthday', $token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    return $response->withStatus(500)->withJson(['msg' => $e->getMessage()]);
  exit;
}

$user = $fbResponse->getGraphUser();
return $response->withJson($user);

My problem it's that I don't know what is the best way to handle the access token. Should the token be provided by the client? In that case, should pass as param in the same request (e.g: myapi/get_user/123?token=ABC123) or should do another api call (let say myapi/register_token/ABC123) breaking the principle of being stateless.

I looking for the best way (or the best practice) to handle the access token.

  • 写回答

1条回答 默认 最新

  • douxiong3245 2017-01-24 12:21
    关注

    The best way to pass access token is in authorization request header :

     GET myapi/get_user/123 HTTP/1.1
     Host: mysite.com
     Authorization: <YOUR_ACCESS_TOKEN>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程