token

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTokenTTL = 90 * 24 * time.Hour

DefaultTokenTTL defines the default time-to-live for worker tokens. Tokens are valid for 90 days from creation. After expiration, the system will log a warning but continue to accept the token, allowing operations to proceed.

Variables

This section is empty.

Functions

func Generate

func Generate(spec *Spec) (string, error)

func Verify

func Verify(spec *Spec, token string) error

Verify verifies a token with no logging (for backward compatibility)

func VerifyWithLogger

func VerifyWithLogger(spec *Spec, token string, logger *zap.Logger) error

VerifyWithLogger verifies a token and logs warnings using the provided zap logger. If logger is nil, nothing is printed.

Types

type Spec

type Spec struct {
	Prefix       string
	RandomLength int           // number of random bytes
	SecretKey    []byte        // secret key for HMAC
	TTL          time.Duration // token time-to-live
	RandReader   io.Reader     // random number generator
}

func DefaultSpec

func DefaultSpec() *Spec

func (*Spec) WithPrefix

func (s *Spec) WithPrefix(prefix string) *Spec

WithPrefix sets a custom prefix for the spec

func (*Spec) WithRandReader

func (s *Spec) WithRandReader(reader io.Reader) *Spec

WithRandReader sets a custom random number generator

func (*Spec) WithRandomLength

func (s *Spec) WithRandomLength(length int) *Spec

WithRandomLength sets the length of random bytes

func (*Spec) WithSecretKey

func (s *Spec) WithSecretKey(key []byte) *Spec

WithSecretKey sets a custom secret key

func (*Spec) WithTTL

func (s *Spec) WithTTL(ttl time.Duration) *Spec

WithTTL sets a custom time-to-live duration

Jump to

Keyboard shortcuts

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