jwtauth

package
v0.0.0-...-1bcc78e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSigningKey = "centaur"

Variables

View Source
var DefaultOptions = jwtoptions{
	// contains filtered or unexported fields
}

Functions

This section is empty.

Types

type JWTAuth

type JWTAuth struct {
	// contains filtered or unexported fields
}
var JWTentity *JWTAuth

func NewJWTAuth

func NewJWTAuth(s Storer, opts ...Option) *JWTAuth

func (*JWTAuth) DestroyToken

func (auth *JWTAuth) DestroyToken(token string) error

DestroyToken 销毁令牌

func (*JWTAuth) GenerateToken

func (auth *JWTAuth) GenerateToken(userID string) (*TokenInfo, error)

GenerateToken 为生成令牌

func (*JWTAuth) ParseToken

func (auth *JWTAuth) ParseToken(token string) (*jwt.StandardClaims, error)

解析令牌

type Option

type Option func(*jwtoptions)

func SetExpireTime

func SetExpireTime(expire int) Option

SetExpireTime 设定token过期时间(秒),默认3600s

func SetKeyfunc

func SetKeyfunc(f jwt.Keyfunc) Option

SetKeyfunc 设定验证secretkey的回调函数

func SetSigningKey

func SetSigningKey(key string) Option

SetSigningKey 设定签名secretkey

func SetSigningMethod

func SetSigningMethod(method jwt.SigningMethod) Option

SetSigningMethod 设定签名方法

type RedisConfig

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

RedisConfig redis配置参数

type RedisStore

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

func NewStore

func NewStore(cfg *RedisConfig) *RedisStore

func (*RedisStore) Close

func (s *RedisStore) Close()

func (*RedisStore) Set

func (s *RedisStore) Set(token string, expire time.Duration) error

func (*RedisStore) Verify

func (s *RedisStore) Verify(token string) (bool, error)

type Storer

type Storer interface {
	//放入token并设置过期时间
	Set(token string, expire time.Duration) error
	//验证token是否存在
	Verify(token string) (bool, error)
	//关闭存储
	Close()
}

type TokenInfo

type TokenInfo struct {
	Token     string
	TokenType string
	ExpiredAt int64
}

Jump to

Keyboard shortcuts

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