HostAuthentication

Authentication and per-caller rate limiting for the embedded servers this SDK ships.

These servers perform key custody operations — the DID registrar creates, updates and deactivates DIDs — and previously carried no authentication primitive at all, only a loopback bind default and documentation asking the operator to front them with a proxy. Documentation is not a control, and an operator who binds to 0.0.0.0 without reading it gets an open registrar.

So a server refuses mutating requests until the host has said what protects them. Saying so is cheap and explicit: configure bearerToken or custom, or state the deployment's actual control with frontedByProxy. Silence is the one thing that is not accepted.

This is authentication, not encryption. Use TLS, or a loopback-only bind behind a TLS proxy; a bearer token on a plaintext connection is readable by anything on the path.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class RateLimit @JvmOverloads constructor(permits: Int, windowMillis: Long, maxTrackedCallers: Int, clock: () -> Long = System::currentTimeMillis, failedAuthPermits: Int = defaultFailedAuthPermits(permits), attemptPermits: Int = defaultAttemptPermits(permits))

Fixed-window permit budgets per caller, keyed by remote host.

Link copied to clipboard
class Unconfigured @JvmOverloads constructor(serverName: String, protocolAuthenticatedPaths: Set<String> = emptySet(), protectedPathPrefixes: Set<String> = emptySet())

Installs the fail-closed default for a server the host never configured.

Properties

Link copied to clipboard

What protects this server, when nothing in this process does.

Functions

Link copied to clipboard

Whether this gate decides every mutating request (POST, PUT, PATCH, DELETE): it authenticates all of them, or it is frontedByProxy, which records that something in front does.

Link copied to clipboard
fun install(application: Application, protocolAuthenticatedPaths: Set<String> = emptySet())

Installs the gate ahead of routing. Call before the server starts.

Link copied to clipboard

Returns a copy that also requires the credential for every request, whatever its method, whose path starts with one of prefixes. Use it when a few read routes are privileged but the rest of the server's reads are not, e.g. job-status records in the DID registrar.