jwt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAccessTokenExpire   = time.Hour * 24
	DefaultRegisterTokenExpire = time.Minute * 60
	DefaultRefreshTokenExpire  = time.Hour * 24 * 7

	ErrNeedTokenProvider = TokenError("cannot sign token without token provider")
	ErrInvalidToken      = TokenError("invalid token")
	ErrTokenParsing      = TokenError("token parsing error")
)

Variables

This section is empty.

Functions

func DecodeToken

func DecodeToken(key, tokenString string) (map[string]any, error)

DecodeToken decodes a JWT token into its claims.

func GenerateAccessToken

func GenerateAccessToken(key, jti string, payload map[string]any, subject ...string) (string, error)

GenerateAccessToken generates an access token with a default expiration of 24 hours.

func GenerateRefreshToken

func GenerateRefreshToken(key, jti string, payload map[string]any, subject ...string) (string, error)

GenerateRefreshToken generates a refresh token with a default expiration of 7 days.

func GenerateRegisterToken

func GenerateRegisterToken(key, jti string, payload map[string]any, subject ...string) (string, error)

GenerateRegisterToken generates a register token with a default expiration of 60 minutes.

func ValidateToken

func ValidateToken(key, tokenString string) (*jwtstd.Token, error)

ValidateToken validates a JWT token.

Types

type Token

type Token struct {
	JTI     string         `json:"jti"`
	Payload map[string]any `json:"payload"`
	Subject string         `json:"sub"`
	Expire  int64          `json:"exp"`
}

Token represents the token body.

type TokenError

type TokenError string

func (TokenError) Error

func (e TokenError) Error() string

Jump to

Keyboard shortcuts

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