jwt

package
v0.0.0-...-52e5b9a Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTokenMissing     = "禁止访问"
	ErrorTokenMalformed   = "令牌错误"
	ErrorTokenNotValidYet = "令牌不存在"
	ErrorTokenExpired     = "令牌过期"
	ErrorTokenInvalid     = "令牌无效"
)
View Source
const (
	TokenKey       = "__JWT_TOKEN"
	ContextUserKey = "__CONTEXT_USER"
)

Variables

This section is empty.

Functions

func SetGlobalCryptoKey

func SetGlobalCryptoKey(key string)

Types

type ItfTokenStore

type ItfTokenStore interface {
	SetToken(key string, t *Token)
	GetToken(key string) (t *Token, has bool)
	DelToken(key string)
	ClearExpiredToken()
}

type JWT

type JWT struct {
	Expire int64
	Store  ItfTokenStore
	// contains filtered or unexported fields
}

JWT is middleware for the RPC web framework that provides JWT authentication.

func DefaultJWT

func DefaultJWT() *JWT

func NewJWTWithStore

func NewJWTWithStore(store ItfTokenStore) *JWT

func (*JWT) AfterLogin

func (j *JWT) AfterLogin(id string) (t *Token)

AfterLogin ...

func (*JWT) Logout

func (j *JWT) Logout(id string)

Logout ...

func (*JWT) New

func (j *JWT) New() *JWT

New ...

func (*JWT) User

func (*JWT) User(ctx iris.Context) interface{}

func (*JWT) Verify

func (j *JWT) Verify(c iris.Context, call func(id string) (user interface{}, err error)) (err error)

Verify verifies the token and returns the user ID if the token is valid.

type RedisTokenStore

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

func NewRedisTokenStore

func NewRedisTokenStore(c *redis.Client) *RedisTokenStore

func (*RedisTokenStore) ClearExpiredToken

func (r *RedisTokenStore) ClearExpiredToken()

func (*RedisTokenStore) DelToken

func (r *RedisTokenStore) DelToken(key string)

func (*RedisTokenStore) GetToken

func (r *RedisTokenStore) GetToken(key string) (t *Token, has bool)

func (*RedisTokenStore) SetToken

func (r *RedisTokenStore) SetToken(key string, t *Token)

type Token

type Token struct {
	ID        string `json:"id,omitempty"`
	ExpiresAt int64  `json:"expires_at,omitempty"`
	Token     string `json:"token,omitempty"`
}

Jump to

Keyboard shortcuts

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