Skip to content
mercury framework
GitHub

Static auth

Package
@mercury-fw/auth-static
Role
Auth provider
Version
0.2.2
Terminal window
bun add @mercury-fw/auth-static
VariableWhat it is
AUTH_STATIC_TOKENSRequired. JSON from bearer token to user, test tokens only: {"<token>": {"id": "alice", "displayName": "Alice"}}

A fixed map from token to user, for trying the HTTP channel on your machine and for end-to-end tests: two tokens are two users, and you can check that one doesn’t see the other’s things. For real people use OpenID Connect auth.

mercury.config.ts
import { staticAuth } from "@mercury-fw/auth-static";
auth: staticAuth,
.env
AUTH_STATIC_TOKENS={"alice-token": {"id": "alice", "displayName": "Alice"}, "bob-token": {"id": "bob"}}

A caller sending Authorization: Bearer alice-token is static:alice; anything else is refused. The tokens are secrets even here, so they live in .env only. A missing or malformed list stops the provider, and the HTTP channel doesn’t start.