accesstoken

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package accesstoken issues and verifies short-lived JWT access tokens.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInactiveSession = errors.New("access token session is inactive")
	ErrInvalidConfig   = errors.New("invalid access token configuration")
	ErrInvalidToken    = errors.New("invalid access token")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	SessionID string `json:"sid"`
	jwtlib.RegisteredClaims
}

Claims are the verified identity and session references in an access token.

type Issued

type Issued struct {
	Token     string
	ExpiresAt time.Time
}

type Issuer

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

func NewIssuer

func NewIssuer(config IssuerConfig) (*Issuer, error)

func (*Issuer) Issue

func (issuer *Issuer) Issue(subjectID, sessionID string) (Issued, error)

Issue signs a JWT for an existing durable session.

func (*Issuer) IssueUntil

func (issuer *Issuer) IssueUntil(
	subjectID string,
	sessionID string,
	maximumExpiry time.Time,
) (Issued, error)

IssueUntil signs an access token without allowing it to outlive maximumExpiry.

type IssuerConfig

type IssuerConfig struct {
	Issuer     string
	Audience   string
	Lifetime   time.Duration
	KeyID      string
	PrivateKey ed25519.PrivateKey
	Now        func() time.Time
}

type Session

type Session struct {
	ID        string
	SubjectID string
	CreatedAt time.Time
	ExpiresAt time.Time
}

func (Session) ActiveAt

func (session Session) ActiveAt(at time.Time) bool

type SessionResolver

type SessionResolver interface {
	ResolveSession(ctx context.Context, sessionID string) (Session, error)
}

SessionResolver resolves an active durable session.

type Verifier

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

func NewVerifier

func NewVerifier(resolver SessionResolver, config VerifierConfig) (*Verifier, error)

func (*Verifier) Verify

func (verifier *Verifier) Verify(ctx context.Context, rawToken string) (Claims, error)

Verify validates the JWT and its durable session.

func (*Verifier) VerifySession

func (verifier *Verifier) VerifySession(
	ctx context.Context,
	rawToken string,
) (Claims, Session, error)

VerifySession validates the token and returns its durable session.

type VerifierConfig

type VerifierConfig struct {
	Issuer     string
	Audience   string
	PublicKeys map[string]ed25519.PublicKey
	Leeway     time.Duration
	Now        func() time.Time
}

Jump to

Keyboard shortcuts

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