jwtx

package
v1.3.63 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Admin  = UserType("admin")
	Member = UserType("member")
)

Variables

This section is empty.

Functions

func NewToken

func NewToken(data JwtTokenData, secret string, opts ...Option) (string, error)

func NewTokenWithExp

func NewTokenWithExp(data JwtTokenData, key string) (string, error)

func ParseToken

func ParseToken[T any](tokenString string, secret string, target *T) error

func Valid

func Valid(value string, secret string) (bool, error)

Types

type JwtTokenData added in v1.3.20

type JwtTokenData struct {
	UserId      int64    `json:"userId"`
	AccessToken string   `json:"accessToken"`
	TenantId    int64    `json:"tenantId"`
	UserType    UserType `json:"userType"`
}

func NewJwtTokenData added in v1.3.20

func NewJwtTokenData(token string) (*JwtTokenData, error)

type JwtTokenPayload added in v1.3.20

type JwtTokenPayload struct {
	Aud  string       `json:"aud"`
	Exp  int64        `json:"exp"`
	Iss  string       `json:"iss"`
	Sub  string       `json:"sub"`
	Data JwtTokenData `json:"data"`
}

type Option

type Option func(*TokenOption)

func WithAudOption

func WithAudOption(aud string) Option

func WithExpOption

func WithExpOption(expDurationSeconds int64) Option

func WithIssOption

func WithIssOption(iss string) Option

func WithSubOption

func WithSubOption(sub string) Option

type TokenOption

type TokenOption struct {
	Exp *jwt.NumericDate
	Sub string
	Aud string
	Iss string
}

type UserType added in v1.3.20

type UserType string

Jump to

Keyboard shortcuts

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