auth

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 6 Imported by: 0

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

func Forbidden401Handler(option ...func(ForbiddenOption) ForbiddenOption) 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 GetScope

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

func GetUid

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

func GetUserInfo

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

func HasScope

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

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

func JwtBasic

func JwtBasic() func(iris.Context)

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

需要启动token验证器

func LoginRedirect

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

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

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

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

需要启动token验证器

func SimpleJwtAuth

func SimpleJwtAuth(ctx iris.Context)

SimpleJwtAuth 简单验证器

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

需要启动token验证器

Types

type ForbiddenOption

type ForbiddenOption struct {
	Type            ForbiddenType
	Redirect401Page string
	Scope           string
}

type ForbiddenType

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