KvStateStore

@atiproto/kv-oauth-state-store

Implements the StateStore interface from @atproto/oauth-client using a Cloudflare KV namespace. Stores transient OAuth state between the authorization request and the callback, including the DPoP key in JWK format.

Constructor

typescript
new KvStateStore(kv: KVNamespace, options?: KvStateStoreOptions)
ParameterTypeDescription
kvKVNamespaceThe Cloudflare KV namespace binding. Bind this in wrangler.jsonc as OAUTH_STATE_KV.
optionsKvStateStoreOptionsSee options table below.

Options

OptionTypeDefaultDescription
prefixstring"oauth_state:"Key prefix for all KV entries. Change this if you share a KV namespace with other data.
ttlSecondsnumber600Time-to-live in seconds for each state entry. State is only needed during the login flow, so the default 10-minute TTL is sufficient for most cases.

Example

typescript
import { KvStateStore } from "@atiproto/kv-oauth-state-store";
new KvStateStore(env.OAUTH_STATE_KV, {
prefix: "oauth_state:", // default
ttlSeconds: 600, // default: 10 minutes
});