Custom authentication headers
Eric Marchand edited this page Jan 11, 2017
·
1 revision
If you want to customise authentication headers implement the protocol OAuthSwiftCredentialHeadersFactory
and set your object into credential
oauthSwift.client.credential.headersFactory=<your custom object>
for instance change the header key name from "Authorization" to "X-Authorization"
class XHeaders: OAuthSwiftCredentialHeadersFactory {
let credential: OAuthSwiftCredential
init(credential: OAuthSwiftCredential) {
self.credential = credential
}
func make(_ url:URL, method: OAuthSwiftHTTPRequest.Method, parameters: OAuthSwift.Parameters, body: Data?) -> Dictionary<String, String> {
// assert credential.version == .oauth2
return credential.oauthToken.isEmpty ? [:] : ["X-Authorization": "Bearer \(credential.oauthToken)"]
}
}
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat
](http://mit-license.org) [![Platform](http://img.shields.io/badge/platform-iOS_OSX_TVOS-lightgrey.svg?style=flat ](https://developer.apple.com/resources/) [![Language](http://img.shields.io/badge/language-swift-orange.svg?style=flat ](https://developer.apple.com/swift)