KAuthProvider
Defines how authentication headers are injected into every outgoing request.
Pass an instance via KHttpConfig.authProvider. When null, no auth header is added automatically (useful for cookie-based auth or public APIs).
Built-in providers:
Bearer —
Authorization: Bearer <token>Basic —
Authorization: Basic <base64(user:pass)>ApiKey — custom header or
Authorization: ApiKey <key>Custom — full control via a lambda
Usage:
// Bearer / JWT
KHttpConfig(
baseUrl = "https://api.example.com/",
authProvider = KAuthProvider.Bearer { tokenStore.getToken() },
)
// API key in custom header
KHttpConfig(
baseUrl = "https://api.example.com/",
authProvider = KAuthProvider.ApiKey(header = "X-Api-Key") { "my-secret-key" },
)
// Custom
KHttpConfig(
baseUrl = "https://api.example.com/",
authProvider = KAuthProvider.Custom { request ->
request.header("X-Tenant-Id", "acme")
request.header("X-Signature", computeSignature())
},
)Content copied to clipboard
Inheritors
Types
Link copied to clipboard
Injects Authorization: Bearer <token>.
Link copied to clipboard
Escape hatch for any auth scheme not covered above.
Link copied to clipboard
Semantic alias for Bearer — identical behaviour, clearer intent for JWT flows.