JWTCredentials

public struct JWTCredentials : ClientCredentials

A struct for providing a JWT as credentials to a KituraKit route. The struct is initialized with a token, which will be used to authenticate the user and generate their user profile.

Usage Example:

struct JWTUser: Codable {
   let name: String
}

client.get("/protected", credentials: JWTCredentials(token: "exampleToken")) { (user: JWTUser?, error: RequestError?) -> Void in
   guard let user = user else {
       print("failed request: \(error)")
   }
   print("Successfully authenticated and recieved \(user)")
}
  • The users JWT

    Declaration

    Swift

    public let token: String
  • Create a JWT credentials instance with the specified token data.

    Declaration

    Swift

    public init(token: String)
  • Function to generate headers using a provided token JWT authentication. The “X-token-type” header is set to be “JWT” and the “Authorization: Bearer ” is the header for a JWT

    Declaration

    Swift

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