mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 04:35:56 +03:00
1
Custom authentication headers
Eric Marchand edited this page 2017-01-11 11:50:22 +01:00
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)"]
}
}