auth

package
v1.10.12 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 5 Imported by: 8

Documentation

Index

Constants

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

Variables

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

Functions

func Forbidden401Handler added in v1.10.11

func Forbidden401Handler(option ...ForbiddenFunc) func(iris.Context)

Forbidden401Handler 401处理器

判定为401时返回消息

func GetClientType

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

func GetDept

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

func GetOrg

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

func GetUid

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

func GetUserInfo

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

func JwtBasic added in v1.10.11

func JwtBasic() func(iris.Context)

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

需要启动token验证器

func LoginRedirect added in v1.10.11

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

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

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

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

需要启动token验证器

func SimpleJwtAuth added in v1.10.11

func SimpleJwtAuth(ctx iris.Context)

SimpleJwtAuth 简单验证器

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

需要启动token验证器

Types

type ForbiddenFunc added in v1.10.11

type ForbiddenFunc func() ForbiddenOption

type ForbiddenOption added in v1.10.11

type ForbiddenOption struct {
	Type            ForbiddenType
	Redirect401Page 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"`
}

Jump to

Keyboard shortcuts

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