tokens

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReservedClaim = platformerrors.New("reserved claim key in extraClaims")

ErrReservedClaim indicates that a caller passed a JWT registered-claim key in extraClaims. Reserved claim keys (iss, sub, aud, exp, nbf, iat, jti) are owned by the issuer and cannot be overridden by callers.

View Source
var ReservedClaimKeys = map[string]struct{}{
	"iss": {},
	"sub": {},
	"aud": {},
	"exp": {},
	"nbf": {},
	"iat": {},
	"jti": {},
}

ReservedClaimKeys is the set of JWT registered claim names (RFC 7519) the issuer owns. Callers MUST NOT include these in extraClaims passed to IssueToken.

Functions

This section is empty.

Types

type Claims

type Claims interface {
	// Subject returns the "sub" claim.
	Subject() string
	// JTI returns the "jti" claim.
	JTI() string
	// ExpiresAt returns the "exp" claim as a UTC time. Zero if unset.
	ExpiresAt() time.Time
	// Get returns the raw value for key and whether it was present.
	Get(key string) (any, bool)
	// GetString returns the string value for key and whether it was
	// present AND a string. Missing keys and non-string values both
	// return ("", false).
	GetString(key string) (string, bool)
}

Claims is the parsed claim set from a token. Implementations expose issuer-owned registered claims via typed accessors (Subject, JTI, ExpiresAt) and any application-specific claims via Get / GetString.

Callers that need claims not surfaced by the typed accessors look them up by name, e.g. claims.GetString("account_id").

type Issuer

type Issuer interface {
	IssueToken(ctx context.Context, subject string, expiry time.Duration, extraClaims map[string]any) (tokenStr, jti string, err error)
	ParseToken(ctx context.Context, token string) (Claims, error)
}

Issuer issues and parses authentication tokens. Implementations own the standard registered claims (sub, jti, iat, nbf, exp, aud, iss); callers supply any application-specific claims via extraClaims and read them back through the Claims returned by ParseToken.

func NewNoopTokenIssuer

func NewNoopTokenIssuer() Issuer

Directories

Path Synopsis
Package mock provides moq-generated mock implementations of interfaces in the tokens package.
Package mock provides moq-generated mock implementations of interfaces in the tokens package.

Jump to

Keyboard shortcuts

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