auth

package
v0.0.0-...-370319b Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKey = "StandardAuth"
)

Variables

This section is empty.

Functions

func GetHttpMiddleware

func GetHttpMiddleware(
	whitePaths,
	loginPaths,
	logoutPaths []string,
	loginByTokenFunc func(ctx context.Context, token string) (*User, error),
	getLoginTokenFunc func(r *ghttp.Request) string,
	cookieExpire time.Duration,
) func(r *ghttp.Request)

GetHttpMiddleware 获取http鉴权中间件

参数说明:
	whitePaths 不需要校验的接口path
	loginPaths 登入的接口path
	logoutPaths 登出的接口path
	loginByTokenFunc 根据token获取鉴权用户信息的方法
	getLoginTokenFunc 从登录类接口响应信息中获取token的方法,如 r.GetHandlerResponse().(*v1.UserLoginRes).Token
	cookieExpire cookie有效期

Types

type ContextValue

type ContextValue struct {
	User *User // 登录用户信息
}

type StandardAuthContext

type StandardAuthContext interface {
	InitRUser(r *ghttp.Request, user *User)
	InitUser(ctx context.Context, user *User) context.Context
	Get(ctx context.Context) *ContextValue
	GetUser(ctx context.Context) *User
	GetUserWithCheck(ctx context.Context) (ret *User, err error)
}

func GetStandardAuth

func GetStandardAuth() StandardAuthContext

type User

type User struct {
	Id         uint32      `json:"id" dc:"ID"`
	Nickname   string      `json:"nickname" dc:"昵称"`
	Token      string      `json:"token" dc:"token"`
	Permission interface{} `json:"permission" dc:"权限数据"`
	Data       interface{} `json:"data" dc:"自定义用户数据"`
}

Jump to

Keyboard shortcuts

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