token

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("token: invalid")

ErrInvalid is a single opaque error so callers cannot distinguish failure reasons.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	ContextID string `json:"-"`             // filled in by Verify from the request, never serialized
	Sub       string `json:"sub"`           // agent role bound to this token
	Owner     bool   `json:"own,omitempty"` // true only for the creator token (may issue participant tokens / close)
	Ver       int    `json:"ver"`
	Exp       int64  `json:"exp"`
}

Claims is the token body, kept intentionally small to minimize token length. The context id and audience are NOT stored here; they are folded into the MAC input instead, so the token stays bound to one context without carrying the id.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager signs with cur and verifies against cur then prev (for zero-downtime rotation).

func New

func New(cur, prev []byte, ttlHours int) *Manager

New builds a Manager. prev may be nil.

func (*Manager) Sign

func (m *Manager) Sign(contextID, sub string, owner bool, ver int) (string, error)

Sign returns "payload.mac" for a token bound to (contextID, sub, owner, ver). contextID is folded into the MAC, not stored in the payload.

func (*Manager) Verify

func (m *Manager) Verify(contextID, tok string) (Claims, error)

Verify checks the signature (cur or prev) and expiry for a token presented against contextID; it returns the claims with ContextID filled in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL