iris

package
v0.0.1-alpha1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(src []byte) ([]byte, error)

Base64Decode decodes "src" to jwt base64 url format. We could use the base64.RawURLEncoding but the below is a bit faster.

func Base64Encode

func Base64Encode(src []byte) []byte

func FromHeader

func FromHeader(ctx *context.Context) string

FromHeader is a token extractor. It reads the token from the Authorization request header of form: Authorization: "Bearer {token}".

func FromQuery

func FromQuery(ctx *context.Context) string

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 GetAuthorityId

func GetAuthorityId(ctx *context.Context) []string

GetAuthorityId 角色id

func GetAuthorityType

func GetAuthorityType(ctx *context.Context) int

GetAuthorityType 角色类型

func GetCreationDate

func GetCreationDate(ctx *context.Context) int64

GetCreationDate 登录时间

func GetExpiresIn

func GetExpiresIn(ctx *context.Context) int64

GetExpiresIn 有效期

func GetTenancyId

func GetTenancyId(ctx *context.Context) uint

GetTenancyId 商户id

func GetTenancyName

func GetTenancyName(ctx *context.Context) string

GetTenancyName 商户名称

func GetToken

func GetToken() (string, error)

func GetUserId

func GetUserId(ctx *context.Context) uint

GetUserId 用户id

func GetUsername

func GetUsername(ctx *context.Context) string

GetUsername 用户名

func GetVerifiedToken

func GetVerifiedToken(ctx *context.Context) []byte

func InitDriver

func InitDriver(c *multi.Config) error

InitDriver 认证驱动 redis 需要设置redis local 使用本地内存

func IsAdmin

func IsAdmin(ctx *context.Context) bool

func IsGeneral

func IsGeneral(ctx *context.Context) bool

func IsTenancy

func IsTenancy(ctx *context.Context) bool

Types

type LocalAuth

type LocalAuth struct {
	Cache *cache.Cache
}

func NewLocalAuth

func NewLocalAuth() *LocalAuth

func (*LocalAuth) CleanUserTokenCache

func (la *LocalAuth) CleanUserTokenCache(authorityType int, userId string) error

CleanUserTokenCache 清空token缓存

func (*LocalAuth) Close

func (la *LocalAuth) Close()

兼容 redis

func (*LocalAuth) DelUserTokenCache

func (la *LocalAuth) DelUserTokenCache(token string) error

func (*LocalAuth) GenerateToken

func (la *LocalAuth) GenerateToken(claims *multi.CustomClaims) (string, int64, error)

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) IsAdmin

func (la *LocalAuth) IsAdmin(token string) (bool, error)

IsAdmin

func (*LocalAuth) IsGeneral

func (la *LocalAuth) IsGeneral(token string) (bool, error)

IsGeneral

func (*LocalAuth) IsTenancy

func (la *LocalAuth) IsTenancy(token string) (bool, error)

IsTenancy

func (*LocalAuth) SetUserTokenMaxCount

func (la *LocalAuth) SetUserTokenMaxCount(tokenMaxCount int64) error

SetUserTokenMaxCount 最大登录限制

func (*LocalAuth) UpdateUserTokenCacheExpire

func (la *LocalAuth) UpdateUserTokenCacheExpire(token string) error

type RedisAuth

type RedisAuth struct {
	Client redis.UniversalClient
}

RedisAuth

func NewRedisAuth

func NewRedisAuth(client redis.UniversalClient) (*RedisAuth, error)

NewRedisAuth

func (*RedisAuth) CleanUserTokenCache

func (ra *RedisAuth) CleanUserTokenCache(authorityType int, userId string) error

CleanUserTokenCache 清空token缓存

func (*RedisAuth) Close

func (ra *RedisAuth) Close()

Close

func (*RedisAuth) DelUserTokenCache

func (ra *RedisAuth) DelUserTokenCache(token string) error

DelUserTokenCache 删除token缓存

func (*RedisAuth) GenerateToken

func (ra *RedisAuth) GenerateToken(claims *multi.CustomClaims) (string, int64, error)

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) IsAdmin

func (ra *RedisAuth) IsAdmin(token string) (bool, error)

IsAdmin

func (*RedisAuth) IsGeneral

func (ra *RedisAuth) IsGeneral(token string) (bool, error)

IsGeneral

func (*RedisAuth) IsTenancy

func (ra *RedisAuth) IsTenancy(token string) (bool, error)

IsTenancy

func (*RedisAuth) SetUserTokenMaxCount

func (ra *RedisAuth) SetUserTokenMaxCount(tokenMaxCount int64) error

SetUserTokenMaxCount 最大登录限制

func (*RedisAuth) UpdateUserTokenCacheExpire

func (ra *RedisAuth) UpdateUserTokenCacheExpire(token string) error

UpdateUserTokenCacheExpire 更新过期时间

type TokenExtractor

type TokenExtractor func(*context.Context) string

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

func (v *Verifier) RequestToken(ctx *context.Context) (token string)

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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