客户应如何通过Facebook的访问令牌服务器? [英] How should a client pass a facebook access token to the server?

查看:191
本文介绍了客户应如何通过Facebook的访问令牌服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每次调用我的REST API,我需要的客户通过用户的Facebook访问令牌,这对用户进行验证。什么是传递此令牌最佳做法?


  1. 也许作为HTTP问号后面的参数

      GET / API /用户/ 123 / profile文件?=的access_token pq8pgHWX95bLZCML


  2. 或以某种方式在请求的报头,类似于HTTP基本身份验证


  3. 也许第三种选择? (我已经排除了向它传递一个JSON,因为我想令牌获得 GET 通过调用一样,所以JSON将不适合那里,我认为)


解决方案

如果你看一下所有流行的OAuth提供者提供的API端点(谷歌,Facebook,掌上,Git会等),你会发现它们都具有HTTPS端点。

您可以在其中传递一个访问令牌提供者的方式是 -

我)作为查询参数 -


  

<一个href=\"https://yourwebsite.com/api/endpoint?access_token=YOUR_ACCESS_TOKEN\">https://yourwebsite.com/api/endpoint?access_token=YOUR_ACCESS_TOKEN


二)在请求头 -

  GET / API /用户/ 123 / profile文件HTTP / 1.1
 主持人:yourwebsite.com
 日期:星期二,2013 12:00:00 GMT 5月14日
 授权:其中,YOUR_ACCESS_TOKEN&GT;

这两个是一般是由大多数API支持的方法。你可以认为做同样的。

三)掌上API不使用GET的。他们使用POST他们的所有请求,甚至检索数据。选中此链接看到自己的文档。请注意,他们使用POST用于检索数据并传递JSON参数。

On every call to my REST API, I require clients to pass user's facebook access token, which authenticates the user. What's best practice for passing this token?

  1. maybe as a parameter behind the HTTP question mark

    GET /api/users/123/profile?access_token=pq8pgHWX95bLZCML
    

  2. or somehow in the header of the request, similarly to HTTP basic authentication

  3. maybe a third option? (I've excluded passing it in a JSON because I want the token get passed in GET calls as well, so JSON wouldn't fit there I think)

解决方案

If you look at the API endpoints provided by all popular OAuth providers (Google, Facebook, Pocket, Git etc), you'd see that they all have HTTPS endpoints.

The ways in which you can pass an access token to the provider are -

i) As Query Parameter -

https://yourwebsite.com/api/endpoint?access_token=YOUR_ACCESS_TOKEN

ii) In the request header -

 GET /api/users/123/profile HTTP/1.1
 Host: yourwebsite.com
 Date: Tue, 14 May 2013 12:00:00 GMT
 Authorization: <YOUR_ACCESS_TOKEN>

These two are approaches that are generally supported by most APIs. You can think of doing the same.

iii) Pocket API does not use GET at all. They use POST for all their requests, even for retrieving data. Check this link to see their documentation. Notice that they use POST for retrieving data and pass JSON parameters.

这篇关于客户应如何通过Facebook的访问令牌服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆