Documentation ¶
Index ¶
- func Base64Decode(src []byte) ([]byte, error)
- func Base64Encode(src []byte) []byte
- func FromHeader(ctx *context.Context) string
- func FromQuery(ctx *context.Context) string
- func Get(ctx *context.Context) *multi.CustomClaims
- func GetAuthorityId(ctx *context.Context) []string
- func GetAuthorityType(ctx *context.Context) int
- func GetCreationDate(ctx *context.Context) int64
- func GetExpiresIn(ctx *context.Context) int64
- func GetTenancyId(ctx *context.Context) uint
- func GetTenancyName(ctx *context.Context) string
- func GetToken() (string, error)
- func GetUserId(ctx *context.Context) uint
- func GetUsername(ctx *context.Context) string
- func GetVerifiedToken(ctx *context.Context) []byte
- func InitDriver(c *multi.Config) error
- func IsAdmin(ctx *context.Context) bool
- func IsGeneral(ctx *context.Context) bool
- func IsTenancy(ctx *context.Context) bool
- type LocalAuth
- func (la *LocalAuth) CleanUserTokenCache(authorityType int, userId string) error
- func (la *LocalAuth) Close()
- func (la *LocalAuth) DelUserTokenCache(token string) error
- func (la *LocalAuth) GenerateToken(claims *multi.CustomClaims) (string, int64, error)
- func (la *LocalAuth) GetCustomClaims(token string) (*multi.CustomClaims, error)
- func (la *LocalAuth) GetTokenByClaims(cla *multi.CustomClaims) (string, error)
- func (la *LocalAuth) IsAdmin(token string) (bool, error)
- func (la *LocalAuth) IsGeneral(token string) (bool, error)
- func (la *LocalAuth) IsTenancy(token string) (bool, error)
- func (la *LocalAuth) SetUserTokenMaxCount(tokenMaxCount int64) error
- func (la *LocalAuth) UpdateUserTokenCacheExpire(token string) error
- type RedisAuth
- func (ra *RedisAuth) CleanUserTokenCache(authorityType int, userId string) error
- func (ra *RedisAuth) Close()
- func (ra *RedisAuth) DelUserTokenCache(token string) error
- func (ra *RedisAuth) GenerateToken(claims *multi.CustomClaims) (string, int64, error)
- func (ra *RedisAuth) GetCustomClaims(token string) (*multi.CustomClaims, error)
- func (ra *RedisAuth) GetTokenByClaims(cla *multi.CustomClaims) (string, error)
- func (ra *RedisAuth) IsAdmin(token string) (bool, error)
- func (ra *RedisAuth) IsGeneral(token string) (bool, error)
- func (ra *RedisAuth) IsTenancy(token string) (bool, error)
- func (ra *RedisAuth) SetUserTokenMaxCount(tokenMaxCount int64) error
- func (ra *RedisAuth) UpdateUserTokenCacheExpire(token string) error
- type TokenExtractor
- type Verifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64Decode ¶
Base64Decode decodes "src" to jwt base64 url format. We could use the base64.RawURLEncoding but the below is a bit faster.
func Base64Encode ¶
func FromHeader ¶
FromHeader is a token extractor. It reads the token from the Authorization request header of form: Authorization: "Bearer {token}".
func FromQuery ¶
FromQuery is a token extractor. It reads the token from the "token" url query parameter.
func Get ¶
func Get(ctx *context.Context) *multi.CustomClaims
Get returns the claims decoded by a verifier.
func GetVerifiedToken ¶
func InitDriver ¶
InitDriver 认证驱动 redis 需要设置redis local 使用本地内存
Types ¶
type LocalAuth ¶
type LocalAuth struct {
Cache *cache.Cache
}
func NewLocalAuth ¶
func NewLocalAuth() *LocalAuth
func (*LocalAuth) CleanUserTokenCache ¶
CleanUserTokenCache 清空token缓存
func (*LocalAuth) DelUserTokenCache ¶
func (*LocalAuth) GenerateToken ¶
GenerateToken
func (*LocalAuth) GetCustomClaims ¶
func (la *LocalAuth) GetCustomClaims(token string) (*multi.CustomClaims, error)
func (*LocalAuth) GetTokenByClaims ¶
func (la *LocalAuth) GetTokenByClaims(cla *multi.CustomClaims) (string, error)
GetTokenByClaims 获取用户信息
func (*LocalAuth) SetUserTokenMaxCount ¶
SetUserTokenMaxCount 最大登录限制
func (*LocalAuth) UpdateUserTokenCacheExpire ¶
type RedisAuth ¶
type RedisAuth struct {
Client redis.UniversalClient
}
RedisAuth
func NewRedisAuth ¶
NewRedisAuth
func (*RedisAuth) CleanUserTokenCache ¶
CleanUserTokenCache 清空token缓存
func (*RedisAuth) DelUserTokenCache ¶
DelUserTokenCache 删除token缓存
func (*RedisAuth) GenerateToken ¶
GenerateToken
func (*RedisAuth) GetCustomClaims ¶
func (ra *RedisAuth) GetCustomClaims(token string) (*multi.CustomClaims, error)
GetCustomClaims 获取用户信息
func (*RedisAuth) GetTokenByClaims ¶
func (ra *RedisAuth) GetTokenByClaims(cla *multi.CustomClaims) (string, error)
GetTokenByClaims 获取用户信息
func (*RedisAuth) SetUserTokenMaxCount ¶
SetUserTokenMaxCount 最大登录限制
func (*RedisAuth) UpdateUserTokenCacheExpire ¶
UpdateUserTokenCacheExpire 更新过期时间
type TokenExtractor ¶
TokenExtractor is a function that takes a context as input and returns a token. An empty string should be returned if no token found without additional information.
func FromJSON ¶
func FromJSON(jsonKey string) TokenExtractor
FromJSON is a token extractor. Reads a json request body and extracts the json based on the given field. The request content-type should contain the: application/json header value, otherwise this method will not try to read and consume the body.
type Verifier ¶
type Verifier struct { Extractors []TokenExtractor Validators []multi.TokenValidator ErrorHandler func(ctx *context.Context, err error) }
func NewVerifier ¶
func NewVerifier(validators ...multi.TokenValidator) *Verifier
func (*Verifier) RequestToken ¶
RequestToken extracts the token from the
func (*Verifier) Verify ¶
func (v *Verifier) Verify(validators ...multi.TokenValidator) context.Handler
func (*Verifier) VerifyToken ¶
func (v *Verifier) VerifyToken(token []byte, validators ...multi.TokenValidator) ([]byte, *multi.CustomClaims, error)