jwttoken

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultAccessTokenDuration  = time.Hour * 24
	DefaultRefreshTokenDuration = time.Hour * 24 * 30
)

Variables

View Source
var (
	ErrParsingClaims            = errors.New("failed to parse Claims")
	ErrUnsupportedSigningMethod = errors.New("unsupported signing method")
	ErrTokenInvalid             = errors.New("the token has an invalid")

	ErrTokenInvalidUID   = errors.New("token has invalid UID")
	ErrTokenInvalidEmail = errors.New("token has invalid email")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	JwtSecretKey     string `env:"JWT_SECRET_KEY"`
	JwtSigningMethod string `env:"JWT_SIGNING_METHOD" envDefault:"HS512"`

	// default: 15 minutes
	JwtAccessTokenDurationInSeconds  TokenDuration `env:"JWT_ACCESS_TOKEN_DURATION" envDefault:"86400"`
	JwtRefreshTokenDurationInSeconds TokenDuration `env:"JWT_REFRESH_TOKEN_DURATION" envDefault:"2592000"`
}

type JwtToken

type JwtToken interface {
	SetSecretKey(secretKey []byte, signMethod jwt.SigningMethod)

	CreateAccessToken(context.Context, model.SessionUser) (string, *time.Time, error)
	CreateRefreshToken(context.Context, model.SessionUser) (string, *time.Time, error)
	CreateTokenCustomDuration(context.Context, model.SessionUser, time.Duration) (string, *time.Time, error)

	Parse(ctx context.Context, tokenString string) (*model.SessionUser, error)
}

type SessionUserClaims

type SessionUserClaims struct {
	UID   uuid.UUID `json:"uid,omitempty"`
	Email string    `json:"email,omitempty"`

	jwt.RegisteredClaims
}

type TokenDuration

type TokenDuration time.Duration

func (*TokenDuration) UnmarshalText

func (receiver *TokenDuration) UnmarshalText(text []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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