Resolve the session on any call
authdog.resolve(call) returns a typed AuthdogContext with token, user, and isAuthenticated, caching the result on the call so a route reads it without boilerplate.
- Typed AuthdogContext
- Cached on the call
Kotlin · Ktor
A session resolver, a requireAuth gate, and a logout handler for Kotlin/Ktor backends. Validate Authdog sessions on every call, on the same wire as the Node SDKs.
Resolve the session
// Application.kt
val authdog = Authdog(System.getenv("PK_AUTHDOG"))
routing {
get("/me") {
val ctx = authdog.requireAuth(call) ?: return@get
}
}
Gate routes on the call
// Routes.kt
get("/me") {
val ctx = authdog.requireAuth(call) ?: return@get
call.respond(ctx.user)
}
Idiomatic Ktor, not a framework
A session resolver, a requireAuth gate, and a typed context, all wire-compatible with the rest of your Authdog stack.
authdog.resolve(call) returns a typed AuthdogContext with token, user, and isAuthenticated, caching the result on the call so a route reads it without boilerplate.
authdog.requireAuth(call) responds 401 and returns null for unauthenticated requests, so `?: return@get` halts the handler before it runs. This is the security boundary.
The Authdog constructor parses and validates the public key once, enforcing the trusted identity-host allowlist, so a malformed or untrusted key fails fast instead of at the first request.
It reads the authdog-session cookie or an Authorization: Bearer header directly, with an injectable Ktor HttpClient for the userinfo lookup that is easy to mock in tests.
authdog.logout(call) expires the session cookie with HttpOnly and SameSite=Lax and redirects to a redirect_uri sanitized against open redirects.
It mirrors @authdog/express and @authdog/fastify on the wire, so one Authdog environment serves your Node and Kotlin services interchangeably.
Pull com.authdog:authdog-ktor from Maven Central.
Instantiate Authdog with your environment's public key.
Call requireAuth(call) in the handlers you protect.
Add the dependency, resolve the session, and gate your routes with requireAuth today. Free to start, with secure defaults built in.