security

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorsParseTokenFail   string = "解析token失败"
	ErrorsTokenBaseInfo    string = "token最基本的格式错误,请提供一个有效的token!"
	ErrorsNoAuthorization  string = "token鉴权未通过,请通过token授权接口重新获取token,"
	ErrorsRefreshTokenFail string = "token不符合刷新条件,请通过登陆接口重新获取token!"

	ValidatorParamsCheckFailCode int    = -400300
	ValidatorParamsCheckFailMsg  string = "参数校验失败"
)

Variables

View Source
var (
	// DefaultConfig is the default middleware config.
	DefaultConfig = HandlerConfig{
		ErrorHandleFunc: func(ctx *gin.Context, err error) {

			if err != nil {
				logger.Error("Internal Server Error: ", err.Error())
			} else {
				logger.Error("Internal Server Error: ", "unknown")
			}
		},
		TokenKey: "token",
		Skipper: func(_ *gin.Context) bool {
			return false
		},
	}
)

Functions

func CheckTokenVerify

func CheckTokenVerify(conf ...HandlerConfig) gin.HandlerFunc

CheckTokenVerify Verify the access token of the middleware 如果有用户信息,则设置用户信息,没有则设置为空,允许公开访问

func CheckUserPermissions

func CheckUserPermissions() gin.HandlerFunc

casbin检查用户对应的角色权限是否允许访问接口

func ErrorTokenAuthFail

func ErrorTokenAuthFail(c *gin.Context)

token 权限校验失败

func ErrorTokenBaseInfo

func ErrorTokenBaseInfo(c *gin.Context)

token 基本的格式错误

func ErrorTokenRefreshFail

func ErrorTokenRefreshFail(c *gin.Context)

token 不符合刷新条件

func HandleTokenVerify

func HandleTokenVerify(conf ...HandlerConfig) gin.HandlerFunc

HandleTokenVerify Verify the access token of the middleware 只有登录获取授权后才可以访问

func NeedAdmin

func NeedAdmin() gin.HandlerFunc

管理员可以访问

func NeedSystemUser

func NeedSystemUser() gin.HandlerFunc

系统用户可以访问

func RefreshTokenConditionCheck

func RefreshTokenConditionCheck() gin.HandlerFunc

RefreshTokenConditionCheck 刷新token条件检查中间件,针对已经过期的token,要求是token格式以及携带的信息满足配置参数即可

func TokenErrorParam

func TokenErrorParam(c *gin.Context)

token 参数校验错误

Types

type ErrorHandleFunc

type ErrorHandleFunc func(*gin.Context, error)

ErrorHandleFunc error handling function

type HandlerConfig

type HandlerConfig struct {
	// error handling when starting the session
	ErrorHandleFunc ErrorHandleFunc
	// keys stored in the context
	TokenKey string
	// defines a function to skip middleware.Returning true skips processing
	// the middleware.
	Skipper func(*gin.Context) bool
}

Config defines the config for Session middleware

Directories

Path Synopsis
jwt

Jump to

Keyboard shortcuts

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