Documentation
¶
Overview ¶
Package nonce provides authentication middleware for agbero REST replay endpoints.
A replay endpoint is a serverless rest block with no fixed url — the target URL is supplied by the client at request time. Because the endpoint effectively proxies arbitrary upstream resources on behalf of a browser, it must be guarded so that only legitimate clients on the same agbero host can use it.
Three guard methods are supported, selected via auth.method in HCL:
meta — agbero injects a single-use nonce into HTML responses served from
the same host. Client JS reads it from
and sends it back in the X-Agbero-Replay-Nonce header. Nonces are
single-use and expire after a configurable TTL (default 1 h).
Suitable for public pages.
token — a short-lived scoped JWT is minted by agbero and fetched by the
client from /.agbero/replay//token. The token is validated on
every request. Suitable for pages behind agbero auth.
direct — a valid agbero session cookie (agbero_sess) is required on every
request. Suitable when the page is already behind agbero's admin
or OAuth auth.
Index ¶
Constants ¶
const ( // DefaultNonceTTL is how long a generated nonce remains valid. DefaultNonceTTL = time.Hour // NonceBytes is the length of the random nonce in bytes (32 → 64 hex chars). NonceBytes = 32 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard enforces replay authentication using one of three methods.
func NewDirectGuard ¶
func NewDirectGuard() *Guard
NewDirectGuard creates a Guard that checks for an agbero session cookie.
func NewMetaGuard ¶
NewMetaGuard creates a Guard that validates single-use nonces from store.
func NewTokenGuard ¶
NewTokenGuard creates a Guard that validates Bearer JWTs using verify. verify must return true iff the token is valid and unexpired.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a lock-free, single-use nonce store backed by mappo.Concurrent.
Each nonce is consumed on first use. Expired nonces are swept lazily on access and periodically by the background goroutine started via StartSweeper.
func (*Store) Consume ¶
Consume validates and removes the nonce atomically. Returns true only if the nonce exists and has not expired. A consumed or unknown nonce returns false.
func (*Store) Generate ¶
Generate creates a cryptographically random nonce, stores it, and returns its hex-encoded value. The nonce expires after the store's TTL.
func (*Store) Len ¶
Len returns the number of nonces currently in the store. For tests and monitoring.
func (*Store) StartSweeper ¶
StartSweeper launches a background goroutine that cleans up expired nonces every interval. The goroutine exits when done is closed.