jwt

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrJWTSecretRequired = fmt.Err("JWTSecret", "is", "required")

ErrJWTSecretRequired is returned by New when secret is empty.

Functions

This section is empty.

Types

type Strategy

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

Strategy is a stateless SessionStrategy: no DB lookup per request, no server-side revocation. bearer=false (default) carries the JWT in an HttpOnly cookie (browser-friendly, supports the same redirect-after-login flow as cookie.Strategy). bearer=true reads/writes via the "Authorization: Bearer" header instead (API/MCP clients that can't use cookies) — call AsBearer().

func New

func New(secret []byte, ttl int, notify user.SecurityNotifier, users user.IdentityStore) (*Strategy, error)

New builds a JWT strategy. Fails fast if secret is empty — a JWT strategy with no secret can mint tokens nobody can validate.

func (*Strategy) AsBearer

func (s *Strategy) AsBearer() *Strategy

AsBearer switches transport to the Authorization header — for stateless API clients (MCP servers, IDEs, LLMs) that cannot use cookies.

func (*Strategy) GenerateAPIToken

func (s *Strategy) GenerateAPIToken(userID string, ttl int) (string, error)

GenerateAPIToken mints a signed, long-lived Bearer token for API access (MCP clients, IDEs, LLMs) — independent of how browser sessions are carried. ttl==0 → 50 years (effectively no expiry; not 100: this module compiles for the edge, where int is 32-bit, and 100 years of seconds overflows int32). Call it on whichever Strategy value the app already holds (bearer or not — signing doesn't depend on transport).

func (*Strategy) Identify

func (s *Strategy) Identify(ctx router.Context) (string, error)

func (*Strategy) Issue

func (s *Strategy) Issue(ctx router.Context, userID string) error

func (*Strategy) Revoke

func (s *Strategy) Revoke(ctx router.Context) error

func (*Strategy) WithCookieName

func (s *Strategy) WithCookieName(name string) *Strategy

WithCookieName overrides the cookie the JWT travels in (bearer mode ignores it).

Jump to

Keyboard shortcuts

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