Documentation ¶
Index ¶
- Constants
- Variables
- func Forbidden401Handler(option ...func(ForbiddenOption) ForbiddenOption) func(server.Context)
- func GetClientType(ctx server.Context) (ct string)
- func GetDept(ctx server.Context) (dept string)
- func GetOrg(ctx server.Context) (org string)
- func GetScope(ctx server.Context) (scope string)
- func GetUid(ctx server.Context) (uid string)
- func GetUserInfo(ctx server.Context) (uid token.JwtPayload, err error)
- func HasScope(ctx server.Context, expect string) (ok bool)
- func JwtBasic() func(server.Context)
- func LoginRedirect(redirect string) func(server.Context)
- func SimpleJwtAuth(ctx server.Context)
- type ForbiddenOption
- type ForbiddenType
- type Response
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 GetUserInfo ¶
func GetUserInfo(ctx server.Context) (uid token.JwtPayload, err error)
func LoginRedirect ¶ added in v1.10.11
LoginRedirect 如果需要登录,跳转到登录界面
检查 UserInfoKey 是否存在,如果不存在,判定为未登录
redirect: 登录地址,需要全路径
需要启动token验证器
func SimpleJwtAuth ¶ added in v1.10.11
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" )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.