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)"]
    }
}