使用 OAuthSwift 对 Alamofire 请求进行签名的实用方法。
此框架提供一个 RequestInterceptor 用于设置到 Alamofire Session 中。
let interceptor = oauthswift.requestInterceptor
let session = Session(interceptor: interceptor)
然后您可以像往常一样发起请求。
session.request("http://oauthbin.com/v1/echo")
或者将 interceptor 作为 request 函数的参数传递。
session.request("http://oauthbin.com/v1/echo", interceptor: interceptor)
OAuthSwift 上的 authorize 函数,否则任何请求都不会被签名。
OAuth2 interceptor 还会自动刷新访问令牌,使用 Alamofire 的 RequestRetrier 机制。
github "OAuthSwift/OAuthSwiftAlamofire"
carthage update。use_frameworks!
pod 'OAuthSwiftAlamofire'