HTTPBasic

public struct HTTPBasic : ClientCredentials

A struct for providing HTTP basic credentials to a KituraKit route. The struct is initialized with a username and password, which will be used to authenticate the user. This client route mirrors a Kitura Codable route that implements TypeSafeHTTPBasic authentication to verify a users identity.

Usage Example:

struct User: Codable {
   let name: String
}

client.get("/protected", credentials: HTTPBasic(username: "John", password: "12345")) { (user: User?, error: RequestError?) -> Void in
   guard let user = user else {
       print("failed request: \(error)")
   }
   print("Successfully authenticated and recieved \(user)")
}
  • The user id that uniquely identifies the user

    Declaration

    Swift

    public let username: String
  • The password for the given username

    Declaration

    Swift

    public let password: String
  • Create an HTTP Basic credentials instance with the specified username and password.

    Declaration

    Swift

    public init(username: String, password: String)
  • Function to generate headers using a username and password for HTTP basic authentication. The “Authorization” header is set to be the string “Basic” followed by username:password encoded as a base64 encoded string.

    Declaration

    Swift

    public func getHeaders() -> [String : String]