jwt

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 4 Imported by: 1 module, 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

Index

Constants

View Source
const (
	TokenTypeAccess  = "access"
	TokenTypeRefresh = "refresh"
	TokenType2FA     = "2fa"
)

Token types, embedded as a claim and verified on validation.

Variables

View Source
var (
	ErrInvalidToken = errors.New("invalid token")
	ErrExpiredToken = errors.New("token has expired")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserID uuid.UUID `json:"user_id"`
	// SessionID identifies the login the token belongs to. Zero on tokens
	// minted before sessions existed.
	SessionID uuid.UUID `json:"session_id,omitempty"`
	TokenType string    `json:"token_type,omitempty"`
	jwt.RegisteredClaims
}

type Manager

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

func NewManager

func NewManager(accessSecret, refreshSecret string, accessExpiry, refreshExpiry time.Duration) *Manager

func (*Manager) Generate2FAToken

func (m *Manager) Generate2FAToken(userID uuid.UUID) (string, error)

Generate2FAToken creates a short-lived token for 2FA challenge (5 minutes)

func (*Manager) GenerateAccessToken

func (m *Manager) GenerateAccessToken(userID, sessionID uuid.UUID) (string, error)

GenerateAccessToken creates a new JWT access token bound to sessionID.

func (*Manager) GenerateRefreshToken

func (m *Manager) GenerateRefreshToken(userID, sessionID uuid.UUID) (string, error)

GenerateRefreshToken creates a new JWT refresh token bound to sessionID.

func (*Manager) GetRefreshTokenExpiry

func (m *Manager) GetRefreshTokenExpiry() time.Duration

func (*Manager) Validate2FAToken

func (m *Manager) Validate2FAToken(tokenString string) (*Claims, error)

Validate2FAToken validates a 2FA challenge token

func (*Manager) ValidateAccessToken

func (m *Manager) ValidateAccessToken(tokenString string) (*Claims, error)

ValidateAccessToken validates and parses an access token. 2FA challenge tokens are rejected.

func (*Manager) ValidateRefreshToken

func (m *Manager) ValidateRefreshToken(tokenString string) (*Claims, error)

ValidateRefreshToken validates and parses a refresh token

Jump to

Keyboard shortcuts

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