Documentation ¶
Index ¶
- Constants
- Variables
- func Forbidden401Handler(option ...ForbiddenFunc) func(iris.Context)
- func GetClientType(ctx iris.Context) (ct string)
- func GetDept(ctx iris.Context) (dept string)
- func GetOrg(ctx iris.Context) (org string)
- func GetUid(ctx iris.Context) (uid string)
- func GetUserInfo(ctx iris.Context) (uid token.JwtPayload, err error)
- func JwtBasic() func(iris.Context)
- func LoginRedirect(redirect string) func(iris.Context)
- func SimpleJwtAuth(ctx iris.Context)
- type ForbiddenFunc
- type ForbiddenOption
- type ForbiddenType
- type Response
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 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" )
Click to show internal directories.
Click to hide internal directories.