- Building Microservices with Go
- Nic Jackson
- 209字
- 2021-07-15 17:28:12
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.
- 軟件安全技術
- JavaScript從入門到精通(微視頻精編版)
- Flutter開發實戰詳解
- LabVIEW Graphical Programming Cookbook
- Mastering OpenCV Android Application Programming
- Python爬蟲開發:從入門到實戰(微課版)
- MongoDB權威指南(第3版)
- 小學生C++創意編程(視頻教學版)
- ASP.NET開發與應用教程
- Yii Project Blueprints
- Learning AngularJS for .NET Developers
- D3.js By Example
- Hands-On Full Stack Development with Spring Boot 2.0 and React
- 案例式C語言程序設計實驗指導
- HTML5移動前端開發基礎與實戰(微課版)