jwt

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Jwt_Alg        = "HS256"
	Jwt_Type       = "JWT"
	Jwt_Admin      = "JWT_API_ADMIN_KOVEY"
	Jwt_Alg_Sha256 = "sha256"
)

Variables

View Source
var Err_Token_Expired = errors.New("token expired")
View Source
var Err_Token_Format_Invalid = errors.New("token format error")
View Source
var Err_Token_Iat_Invalid = errors.New("token iat invalid")
View Source
var Err_Token_Sign_Invalid = errors.New("token sign error")

Functions

func Decrypt

func Decrypt(key, data string) (string, error)

func Encrypt

func Encrypt(key string, data string) (string, error)

func HmacSha256

func HmacSha256(data string, key string) string

func Sha256

func Sha256(data string) string

Types

type Header map[string]string

func (Header) Add

func (h Header) Add(key, val string)

func (Header) Get

func (h Header) Get(key string) string

func (Header) Has

func (h Header) Has(key string) bool

type Jwt

type Jwt[T any] struct {
	Expired   int32
	Header    Header
	Key       string
	AlgConfig Header
}

func NewJwt

func NewJwt[T any](key string, expired int32) *Jwt[T]

func (*Jwt[T]) Decode

func (j *Jwt[T]) Decode(token string) (T, error)

func (*Jwt[T]) Encode

func (j *Jwt[T]) Encode(ext T) (string, error)

type Paylaod

type Paylaod[T any] struct {
	Iss string `json:"iss"`
	Iat int64  `json:"Iat"`
	Exp int64  `json:"Exp"`
	Jti string `json:"jti"`
	Ext T      `json:"ext"`
}

func NewPlayload

func NewPlayload[T any]() *Paylaod[T]

func (*Paylaod[T]) Decode

func (p *Paylaod[T]) Decode(data string) error

func (*Paylaod[T]) Encode

func (p *Paylaod[T]) Encode() string

func (*Paylaod[T]) IsExpired

func (p *Paylaod[T]) IsExpired() bool

func (*Paylaod[T]) IsValid

func (p *Paylaod[T]) IsValid() bool

Jump to

Keyboard shortcuts

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