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

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.

主站蜘蛛池模板: 方山县| 姚安县| 定结县| 咸宁市| 呈贡县| 庄浪县| 任丘市| 商都县| 如皋市| 沂南县| 襄城县| 大余县| 漯河市| 德兴市| 宜兰市| 微博| 定边县| 盈江县| 中牟县| 靖远县| 凤台县| 大宁县| 景谷| 陵水| 汉阴县| 巴中市| 宝山区| 丹凤县| 连江县| 沂南县| 沙雅县| 仁寿县| 襄汾县| 兖州市| 巴马| 确山县| 略阳县| 濉溪县| 花垣县| 九龙城区| 万年县|