jwt

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSubFromToken added in v0.5.6

func GetSubFromToken(c *ar.Ctx) (any, error)

func JWTMiddleware

func JWTMiddleware(config JWTConfig) ar.Middleware

func NewAccessToken

func NewAccessToken(c *ar.Ctx, userID any) (string, error)

func NewAccessTokenWithRefreshToken

func NewAccessTokenWithRefreshToken(c *ar.Ctx, userID any, refreshToken string) (string, error)

func SetLogger

func SetLogger(logger logger.Logger)

func ValidateAccessToken

func ValidateAccessToken(c *ar.Ctx, accessToken string) error

func ValidateRefreshToken

func ValidateRefreshToken(c *ar.Ctx, refreshToken string) (any, error)

Types

type Claims

type Claims = jwt.MapClaims

type JWTConfig

type JWTConfig struct {
	Issuer string

	SecretRefreshToken string
	SecretAccessToken  string

	SigningMethod SigningMethod

	TTL             time.Duration
	TTLRefreshToken time.Duration
	// MaxRefreshTokenAge is the maximum age of a refresh token.
	// If set to 0, RefreshToken will live forever.
	MaxRefreshTokenAge time.Duration
	Leeway             time.Duration

	AdditionalClaimsFunc func(*ar.Ctx) Claims
}

func DefaultJWTConfig

func DefaultJWTConfig() *JWTConfig

type SigningMethod

type SigningMethod = jwt.SigningMethod

type TokenPair

type TokenPair struct {
	AccessToken  string `json:"access_token" xml:"access_token" yaml:"access_token"`
	RefreshToken string `json:"refresh_token" xml:"refresh_token" yaml:"refresh_token"`
}

func NewTokenPair

func NewTokenPair(c *ar.Ctx, userID any) (TokenPair, error)

Jump to

Keyboard shortcuts

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