官术网_书友最值得收藏!

Authorization - string

Authorization is one of the most commonly used request headers, even if you have a public read only API I advise you to ask the user to authorize their requests. By requesting that the user authorizes a request, you have the capability to perform operations such as user level logging and rate limiting. Quite often you may see authorization conducted with a custom request header such as "X-API-Authorization". I would recommend you do not use this approach as the standard Authorization header as specified by the W3C RFC 2616 (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) has all the capability we need. Many companies such as Twitter and PayPal use this header to authenticate requests let's. Let's look at a simple example from Twitter's developer documentation to see how this can be implemented:

Authorization:  
OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",
oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1318622958",
oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
oauth_version="1.0"

The header is in the form of [Authorization method] [Comma separated URL encoded values]. This clearly informs the server that the authorization type is OAuth and the various components of this authorization follow this in a comma delaminated format. By following this standard approach you can enable your consumers to use a third-party library that implements this standard and thus save them the work of having to build a bespoke implementation.

主站蜘蛛池模板: 大庆市| 上思县| 济南市| 韩城市| 金沙县| 栾川县| 新巴尔虎左旗| 九寨沟县| 台安县| 水富县| 盘锦市| 射洪县| 柳林县| 万安县| 万荣县| 南康市| 道孚县| 五华县| 县级市| 佛学| 马尔康县| 门头沟区| 长岭县| 长沙市| 贵南县| 天镇县| 陈巴尔虎旗| 石屏县| 德钦县| 青海省| 静安区| 通州市| 金阳县| 汉中市| 康乐县| 闸北区| 伊宁市| 玛曲县| 南宁市| 清镇市| 磴口县|