SwiftyHawk
https://github.com/hueniverse/hawk。
基于原生的 Hawk 实现:安装
SwiftyHawk 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'SwiftyHawk'
使用方式
使用方法简单直接,以下是基本用法
let creds = HawkCredentials(id: "123456", key: "2983d45yun89q", algorithm: .SHA1)
let client = try! HawkClient(creds: creds)
let options = HawkOptions(url: URL(string: "http://www.example.com/resource/q?x=z&y=r"), method: .post)
let header = try! client.generateAuthorizationHeader(usingOptions: options) // example output: Hawk id=\"123456\", ts=\"1353809207\", nonce=\"Ygvqdz\", ext=\"Bazinga!\", mac=\"qbf1ZPG/r/e06F4ht+T77LXi5vw=\"
options
类中更改以下属性
根据服务器的实现和您的需求,您可以在 /// Extra information to pass to the server
public var ext: String?
/// A pre-calcualated hash of the payload, if the payload validation is required.
public var payloadHash: String?
/// If the payload validation is required, and the hash not calcualted.
public var payload: String?
/// Payload ContentType, If the payload validation is required, and the hash not calcualted.
public var contentType: String?
/// Optional Timestamp, if not provided HawkClient will get the current TimeStamp
public var ts: Int?
/// Optional Nonce, if not provided HawkClient will generate a random nonce.
public var nonce: String?
/// Oz Application Id
public var app: String?
/// Oz delegator
public var dlg: String?
测试
目前项目中包含少量客户端测试以测试 generateAuthorizationHeader
方法的结果,欢迎提交贡献来实现更结构化、更全面的测试!
下一步是什么?
目前只实现了 generateAuthorizationHeader
,因此还有很多工作要做。
如何贡献?
针对Hawk缺失的部分存在一些开放性问题,你可以从那里开始。欢迎PRs(Pull Requests)!
作为参考,克隆 https://github.com/hueniverse/hawk
以获取规范(或你也可以直接在github上阅读)。