jwtauth

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package jwtauth Date: 2024/3/27 15:02 Author: Amu Description:

Package jwtauth Date: 2024/3/27 15:07 Author: Amu Description:

Package jwtauth Date: 2024/3/27 15:03 Author: Amu Description:

Package jwtauth Date: 2024/3/27 15:03 Author: Amu Description:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWTAuth

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

func New

func New(store Storer, db *database.DB, opts ...Option) *JWTAuth

func (*JWTAuth) DestroyToken

func (a *JWTAuth) DestroyToken(tokenString string) error

DestroyToken 销毁令牌

func (*JWTAuth) GenerateToken

func (a *JWTAuth) GenerateToken(userID string, username string, isAdmin string) (auth.TokenInfo, error)

GenerateToken 生成令牌

func (*JWTAuth) ParseToken

func (a *JWTAuth) ParseToken(tokenString string, tokenType string) (string, string, string, error)

ParseToken 解析用户 ID, username

func (*JWTAuth) RecordAudit

func (a *JWTAuth) RecordAudit(username string, operate string)

func (*JWTAuth) Release

func (a *JWTAuth) Release() error

Release 释放资源

type Option

type Option func(*options)

func SetExpired

func SetExpired(expired int) Option

func SetKeyfunc

func SetKeyfunc(keyFunc jwt.Keyfunc) Option

func SetRefreshExpired

func SetRefreshExpired(expired int) Option

func SetSigningKey

func SetSigningKey(key interface{}) Option

func SetSigningMethod

func SetSigningMethod(method jwt.SigningMethod) Option

type Store

type Store struct {
	Storage *cache.Cache
	Prefix  string
}

func (*Store) Check

func (s *Store) Check(key string) (bool, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) Set

func (s *Store) Set(tokenString string, expiration time.Duration) error

type Storer

type Storer interface {
	// Set 存储令牌数据,并指定过期时间
	Set(tokenString string, expiration time.Duration) error
	// Check 检查令牌是否存在
	Check(tokenString string) (bool, error)
	// Close 关闭存储
	Close() error
}

Jump to

Keyboard shortcuts

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