ClientCredentials

public protocol ClientCredentials

A protocol that credentials must implement to be used in KituraKit routes.

Classes or structs that conform to ClientCredentials must contain a getHeaders() function that will return the HTTP headers required to authenticate using the provided credentials.

Usage Example:

public struct MyToken: ClientCredentials {
   public let token: String

   public func getHeaders() -> [String : String] {
       return ["X-token-type": "MyToken", "access_token": self.token]
   }
}

client.get("/protected", credentials: MyToken(token: "12345")) { (user: User?, error: RequestError?) -> Void in
    guard let user = user else {
       print("failed request")
    }
    print(user)
}
  • Function to generate headers that will be added to the client request using the provided credentials.

    Declaration

    Swift

    func getHeaders() -> [String : String]