auth

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CachePrefixUserToken      = "USER_TOKEN"
	CachePrefixUserPermission = "USER_PERMISSION"
	CachePrefixUserTokenArray = "USER_TOKEN_ARRAY"
)
View Source
const (
	CacheModeRedis  = "REDIS"
	CacheModeMemory = "MEMORY"
)
View Source
const (
	OR      = "OR"
	AND     = "AND"
	EXCLUDE = "EXCLUDE"
)
View Source
const CtxUserId = "CtxUserId"

Variables

View Source
var (
	IllegalPermissionError = apiError(40000, "非法权限")
	IllegalTokensError     = apiError(40001, "非法token")
	UrlPrefixError         = apiError(40002, "路由前缀错误")
	PlatformError          = apiError(40003, "平台名称错误")
)

Functions

func ClearUserTokenInMemory

func ClearUserTokenInMemory(ctx context.Context, userId int64) error

func ClearUserTokenInRedis

func ClearUserTokenInRedis(ctx context.Context, userId int64) error

func GenerateTokenToMemory

func GenerateTokenToMemory(ctx context.Context, userId int64) (string, error)

func GenerateTokenToRedis

func GenerateTokenToRedis(ctx context.Context, userId int64) (string, error)

func GetCacheExpireDt

func GetCacheExpireDt() int64

func GetCacheExpireDtDuration

func GetCacheExpireDtDuration() time.Duration

func GetCacheMode

func GetCacheMode() string

func GetIssuer

func GetIssuer() string

func GetRedisName

func GetRedisName() string

func InitAuthRule

func InitAuthRule()

func Login

func Login(ctx context.Context, userId int64) (string, error)

func Logout

func Logout(ctx context.Context, userId int64) (string, error)

func ReInitAuthRule

func ReInitAuthRule()

func RequiredPermission added in v0.0.4

func RequiredPermission(r *ghttp.Request)

func RequiredToken added in v0.0.4

func RequiredToken(r *ghttp.Request)

func SetGetGroupCodesFunc

func SetGetGroupCodesFunc(f func(ctx context.Context, userId int64) ([]string, error))

func SetGetPermissionCodes

func SetGetPermissionCodes(f func(ctx context.Context, userId int64) ([]string, error))

func SetGetPlatformFunc

func SetGetPlatformFunc(f func(ctx context.Context) string)

Types

type CurrentUser

type CurrentUser struct {
	UserId int64
}

type DefaultHandlerResponse

type DefaultHandlerResponse struct {
	Code     int         `json:"code"    dc:"Error code"`
	Message  string      `json:"message" dc:"Error message"`
	Platform string      `json:"platform" dc:"Error Platform" `
	Data     interface{} `json:"data"    dc:"Result data for certain request according API definition"`
}

type Rule

type Rule struct {
	sync.RWMutex
	Path       string           `json:"path" v:"required" dc:"路由"`
	Permission []RulePermission `json:"permission" dc:"权限内容"`
}

type RuleConfig

type RuleConfig struct {
	sync.RWMutex
	RedisName string `json:"redisName" dc:"redis名称"`
	Issuer    string `json:"issuer" v:"required" dc:"Token签发者"`
	CacheMode string `json:"cacheMode" v:"required|in:redis,memory" d:"no" dc:"token是否使用缓存以及缓存的方式"`
	ExpireDt  int64  `json:"expireDt" v:"required-unless:cacheMode" dc:"缓存有效时间"`
	Rule      []Rule `json:"rule" dc:"权限路由集合"`
}

type RulePermission

type RulePermission struct {
	Group     []string `json:"group" dc:"角色限制"`
	GroupMode string   `` /* 145-byte string literal not displayed */
	Code      []string `json:"code"`
	CodeMode  string   `json:"codeMode" v:"required-with:code|in:or,and,exclude,OR,AND,EXCLUDE" d:"or" dc:"权限以OR还是AND的方式校验"`
}

func GetRule

func GetRule(path string) []RulePermission

type SimpleTokenContent

type SimpleTokenContent struct {
	UserId   int64     `json:"userId" v:"required" dc:"用户ID"`
	ExpireDt int64     `json:"expireDt"  v:"required" dc:"有效期"`
	IssuedDt time.Time `json:"issuedDt"  v:"required" dc:"签发时间"`
	Issuer   string    `json:"issuer"  v:"required" dc:"签发者"`
}

SimpleTokenContent jwt token原始内容

func NewSimpleTokenContent

func NewSimpleTokenContent(userId int64) *SimpleTokenContent

NewSimpleTokenContent 快速创建token内容

func (*SimpleTokenContent) IsValidate

func (j *SimpleTokenContent) IsValidate() bool

Jump to

Keyboard shortcuts

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