jwt

package
v0.0.0-...-35a4376 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TenantClaim        = "tenant"
	TokenTypeClaimKey  = "type"
	ExpirationClaimKey = "exp"
)

Variables

This section is empty.

Functions

func ExtractClaim

func ExtractClaim[T any](claims Claims, key string) (T, error)

Types

type Claim

type Claim struct {
	Key   string
	Value any
}

func NewClaim

func NewClaim(key string, value any) *Claim

type Claims

type Claims map[string]any

func (Claims) ExtractExpiration

func (c Claims) ExtractExpiration() (time.Time, error)

func (Claims) ExtractTenantID

func (c Claims) ExtractTenantID() (string, error)

func (Claims) ExtractTokenType

func (c Claims) ExtractTokenType() (TokenType, error)

type Manager

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

func NewManager

func NewManager(secretKey string) *Manager

func (Manager) CreateToken

func (m Manager) CreateToken(
	tenant string,
	expirationDuration time.Duration,
	tokenType TokenType,
	claims ...*Claim,
) (*Token, error)

func (Manager) ExtractClaims

func (m Manager) ExtractClaims(token string) (Claims, error)

func (Manager) ValidateToken

func (m Manager) ValidateToken(token string, claimsValidator ...ValidateClaim) error

type Token

type Token struct {
	Token      string
	Expiration time.Time
}

type TokenType

type TokenType string
const (
	AccessTokenType  TokenType = "access"
	RefreshTokenType TokenType = "refresh"
)

type ValidateClaim

type ValidateClaim struct {
	Key       string
	Validator func(any) error
}

func NewValidateClaim

func NewValidateClaim[T any](key string, compare func(T) bool) ValidateClaim

func ValidateExpirationClaim

func ValidateExpirationClaim() ValidateClaim

func ValidateTenantClaim

func ValidateTenantClaim(tenant string) ValidateClaim

func ValidateTokenTypeClaim

func ValidateTokenTypeClaim(tokenType TokenType) ValidateClaim

Jump to

Keyboard shortcuts

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