refreshtoken

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 6 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 refreshtoken manages opaque tokens that renew JWT access tokens.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflict      = errors.New("refresh token conflict")
	ErrInactive      = errors.New("refresh token is inactive")
	ErrInvalidConfig = errors.New("invalid refresh token configuration")
	ErrInvalidRecord = errors.New("invalid refresh token record")
	ErrInvalidToken  = token.ErrInvalidToken
	ErrNotFound      = errors.New("refresh token not found")
	ErrReuseDetected = errors.New("refresh token reuse detected")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Lifetime time.Duration
	Now      func() time.Time
}

type Issued

type Issued struct {
	Token  string
	Record Record
}

type Manager

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

func NewManager

func NewManager(store Store, config Config) (*Manager, error)

func (*Manager) Create

func (manager *Manager) Create(ctx context.Context, sessionID string) (Issued, error)

Create issues the first refresh token for a durable session.

func (*Manager) Resolve

func (manager *Manager) Resolve(ctx context.Context, rawToken string) (Record, error)

Resolve validates a refresh token without consuming it.

func (*Manager) RevokeSession

func (manager *Manager) RevokeSession(ctx context.Context, rawToken string) error

RevokeSession revokes the session associated with rawToken.

func (*Manager) RevokeSessionID

func (manager *Manager) RevokeSessionID(ctx context.Context, sessionID string) error

RevokeSessionID revokes a durable access session and all of its refresh tokens.

func (*Manager) Rotate

func (manager *Manager) Rotate(ctx context.Context, rawToken string) (Issued, error)

Rotate consumes a token once and returns its replacement.

type Record

type Record struct {
	SessionID string
	TokenHash TokenHash
	CreatedAt time.Time
	ExpiresAt time.Time
	RotatedAt *time.Time
	RevokedAt *time.Time
}

Record is the durable state of one refresh token.

func (Record) ActiveAt

func (record Record) ActiveAt(at time.Time) bool

type Store

type Store interface {
	Create(ctx context.Context, record Record) error
	FindByTokenHash(ctx context.Context, tokenHash TokenHash) (Record, error)
	Rotate(ctx context.Context, current TokenHash, replacement Record, rotatedAt time.Time) error
	RevokeSession(ctx context.Context, sessionID string, revokedAt time.Time) error
}

Store is the durable authority for refresh tokens.

Rotate atomically consumes current and creates replacement. Reuse invalidates the durable session and all its refresh tokens before returning ErrReuseDetected. RevokeSession performs the same invalidation explicitly.

type TokenHash

type TokenHash = token.Hash

Jump to

Keyboard shortcuts

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