jwt

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package jwt signs and verifies moth access tokens: compact JWS with ES256, a kid header, and the fixed claim set moth mints. It is deliberately not a general JOSE library — third-party libraries verify these tokens against the project JWKS; this package only has to produce and check moth's own.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformed        = errors.New("malformed token")
	ErrInvalidSignature = errors.New("invalid signature")
	ErrExpired          = errors.New("token expired")
)

Verification errors.

Functions

func Kid

func Kid(token string) (string, error)

Kid returns the kid header of a token without verifying it, so callers can pick the right key.

func Sign

func Sign(priv *ecdsa.PrivateKey, kid string, claims Claims) (string, error)

Sign returns the compact ES256 JWS of claims, with kid in the header.

Types

type Claims

type Claims struct {
	Issuer        string `json:"iss,omitempty"`
	Subject       string `json:"sub,omitempty"`
	Audience      string `json:"aud,omitempty"`
	IssuedAt      int64  `json:"iat,omitempty"`
	ExpiresAt     int64  `json:"exp,omitempty"`
	Email         string `json:"email,omitempty"`
	EmailVerified bool   `json:"email_verified"`
	// Custom is the user's custom_claims object (roles, permissions, ...),
	// embedded verbatim under the "claims" claim.
	Custom map[string]any `json:"claims,omitempty"`
}

Claims is the moth access-token claim set.

func ParseUnverified

func ParseUnverified(token string) (Claims, error)

ParseUnverified decodes the claims WITHOUT checking the signature or expiry. Introspection uses it to identify which project a token claims to belong to before verification; never trust its output for authentication.

func Verify

func Verify(token string, lookup func(kid string) (*ecdsa.PublicKey, error), now time.Time) (Claims, error)

Verify checks the signature and expiry of a compact ES256 JWS and returns its claims. lookup resolves the header kid to a public key; issuer/audience checks are the caller's job.

Jump to

Keyboard shortcuts

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