auth

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 7 Imported by: 8

Documentation

Index

Constants

View Source
const (
	OrgKey      = "org"
	DeptKey     = "dept"
	ClientKey   = "clientType"
	UidKey      = "uid"
	UserInfoKey = "ui"
	ScopeKey    = "auth_scope"
)

Variables

View Source
var (
	ErrNotAllowed = errors.New("401 not allowed")
)
View Source
var TokenStorage token.Storage
View Source
var WithHtmlResp = func(redirect string) func(ForbiddenOption) ForbiddenOption {
	return func(opt ForbiddenOption) ForbiddenOption {
		opt.Type = HtmlForbiddenResponse
		opt.Redirect401Page = redirect
		return opt
	}
}
View Source
var WithJsonResp = func() func(ForbiddenOption) ForbiddenOption {

	return func(opt ForbiddenOption) ForbiddenOption {
		opt.Type = JsonForbiddenResponse
		return opt
	}
}
View Source
var WithScope = func(scope string) func(ForbiddenOption) ForbiddenOption {
	return func(opt ForbiddenOption) ForbiddenOption {
		opt.Scope = scope
		return opt
	}
}

WithScope 设置本程序需要的scope, 一个程序选择一个scope

Functions

func Forbidden401Handler added in v1.10.11

func Forbidden401Handler(option ...func(ForbiddenOption) ForbiddenOption) func(server.Context)

Forbidden401Handler 401处理器

判定为401时返回消息

func GetClientType

func GetClientType(ctx server.Context) (ct string)

func GetDept

func GetDept(ctx server.Context) (dept string)

func GetOrg

func GetOrg(ctx server.Context) (org string)

func GetScope added in v1.11.19

func GetScope(ctx server.Context) (scope string)

func GetUid

func GetUid(ctx server.Context) (uid string)

func GetUserInfo

func GetUserInfo(ctx server.Context) (uid token.JwtPayload, err error)

func HasScope added in v1.11.19

func HasScope(ctx server.Context, expect string) (ok bool)

HasScope 检查是否包含了指定的scope

func JwtBasic added in v1.10.11

func JwtBasic() func(server.Context)

JwtBasic 预处理jwt,解析后存入 UserInfoKey 和相应header

需要启动token验证器

func LoginRedirect added in v1.10.11

func LoginRedirect(redirect string) func(server.Context)

LoginRedirect 如果需要登录,跳转到登录界面

检查 UserInfoKey 是否存在,如果不存在,判定为未登录

redirect: 登录地址,需要全路径

需要启动token验证器

func SimpleJwtAuth added in v1.10.11

func SimpleJwtAuth(ctx server.Context)

SimpleJwtAuth 简单验证器

判定无权限后返回json类型message和http401.如有权限,将数据存入 UserInfoKey 和相应header

需要启动token验证器

Types

type ForbiddenOption added in v1.10.11

type ForbiddenOption struct {
	Type            ForbiddenType
	Redirect401Page string
	Scope           string
}

type ForbiddenType added in v1.10.11

type ForbiddenType string
const (
	JsonForbiddenResponse ForbiddenType = "JSON"
	HtmlForbiddenResponse               = "HTML"
)

type Response

type Response struct {
	Code    interface{} `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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