jwt

package
v0.0.0-...-72fb90f Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedSigningMethod = errors.New("unexpected signing method")
	ErrInvalidToken            = errors.New("invalid token")
	ErrSessionExpired          = errors.New("session expired")
	ErrInternalServer          = errors.New("internal server error")
	ErrRefreshExpired          = errors.New("refresh token expired due to logout / password change")
	ErrUnknownTokenType        = errors.New("unknown token type")
	ErrInBlackList             = errors.New("refresh token revoked or not found")
)

Functions

func NewRedisStorage

func NewRedisStorage(client *redis.Client) (*RedisBlackList, *RedisVersioner)

Types

type BlackListStorage

type BlackListStorage interface {
	IsBlackListed(token string) bool
	AddToBlackList(token string, ttl time.Duration) error
}

type JWT

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

func NewJWT

func NewJWT(jwtService *JWTService, accessTTL, refreshTTL time.Duration, signingKey string) *JWT

func (*JWT) GenerateToken

func (j *JWT) GenerateToken(userID uint, tokenType TokenType) (string, error)

func (*JWT) Logout

func (j *JWT) Logout(refreshToken string) error

func (*JWT) Refresh

func (j *JWT) Refresh(refreshToken string) (*Tokens, error)

func (*JWT) VerifyToken

func (j *JWT) VerifyToken(tokenString string) (*JWTData, error)

type JWTData

type JWTData struct {
	UserId  uint  `json:"user_id"`
	Exp     int64 `json:"exp"`
	Version uint  `json:"version"`
}

type JWTInterface

type JWTInterface interface {
	GenerateToken(userID uint, tokenType TokenType) (string, error)
	VerifyToken(tokenString string) (*JWTData, error)
	Refresh(refreshToken string) (*Tokens, error)
	Logout(refreshToken string) error
}

type JWTService

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

type RedisBlackList

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

func (*RedisBlackList) AddToBlackList

func (r *RedisBlackList) AddToBlackList(token string, ttl time.Duration) error

func (*RedisBlackList) IsBlackListed

func (r *RedisBlackList) IsBlackListed(token string) bool

type RedisVersioner

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

func (*RedisVersioner) GetVersion

func (r *RedisVersioner) GetVersion(userID uint) (uint, error)

func (*RedisVersioner) IncrementVersion

func (r *RedisVersioner) IncrementVersion(userID uint) error

type TokenType

type TokenType int
const (
	Access TokenType = iota
	Refresh
)

type TokenVersionStorage

type TokenVersionStorage interface {
	IncrementVersion(userID uint) error
	GetVersion(userID uint) (uint, error)
}

type Tokens

type Tokens struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

Directories

Path Synopsis
Package mock_jwt is a generated GoMock package.
Package mock_jwt is a generated GoMock package.

Jump to

Keyboard shortcuts

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