SessionCodeAuthority

class SessionCodeAuthority(sessionAuthority: SessionAuthority, nowEpochMs: () -> Long = System::currentTimeMillis, codeTtlMs: Long = DEFAULT_SESSION_CODE_TTL_MS, random: SecureRandom = SecureRandom())

SESSION_CODE access flow: an 8-character, unambiguous-alphabet code with its own TTL, exchanged directly for a browser session -- no on-device Approve/Deny round trip. Possession of the code within its TTL is the authorization decision; mutating routes still separately require the relevant EditingCapabilities flag on the host.

Single-use, by design. The code is consumed by the first exchange attempt that matches it -- including one rejected for session capacity. That closes the window during which a code visible in a screen share, a shoulder surf, or browser history could be replayed by a second party after the intended browser already claimed it. A host that wants more than one browser connected issues a fresh code per browser; concurrent sessions are still bounded by SessionPolicy.maxAuthenticatedSessions either way, so single-use costs nothing there.

Only one code is ever live: issuing a new one immediately invalidates the previous one, consumed or not. There is no automatic regeneration and no fallback -- no-fallback expiry -- the host must call issueCode again explicitly.

Sessions minted by exchange are created through SessionAuthority.createSession, so they live in the exact same session store as every other session: refresh, logout, CSRF, and session-count limits behave identically regardless of how the session was minted.

Constructors

Link copied to clipboard
constructor(sessionAuthority: SessionAuthority, nowEpochMs: () -> Long = System::currentTimeMillis, codeTtlMs: Long = DEFAULT_SESSION_CODE_TTL_MS, random: SecureRandom = SecureRandom())

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Drops the live code without affecting sessions already minted from it.

Link copied to clipboard

The live, unexpired code's display info. A successful exchange consumes the old code and immediately mints a fresh one, so what this returns is always exchangeable -- the device surface never advertises a dead URL. Null once the code has expired or none was ever issued.

Link copied to clipboard
fun exchange(presented: String, browserLabel: String, sourceIp: String): SessionCodeExchangeResult

Exchanges presented for a browser session. No approval round trip: a valid, unexpired, not-yet-used code creates the session immediately.

Link copied to clipboard
fun issueCode(endpoint: Endpoint = lastEndpoint, ttlMs: Long = lastTtlMs): SessionCodeInfo

Issues a new code, immediately invalidating any previous one (one live code at a time).

Link copied to clipboard
Link copied to clipboard

Remaining TTL in ms for the live, unexpired code; null once it has expired or none was issued.

Link copied to clipboard
fun reset()