Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default CasbinAuth middleware config.
	DefaultConfig = CasbinConfig{
		Skipper: middleware.DefaultSkipper,
	}
)
View Source
var RedirectParam string = "return_url"

Functions

func AllowPathPrefixSkipper

func AllowPathPrefixSkipper(prefixes ...string) func(c echo.Context) bool

func AuthFailedResp

func AuthFailedResp(c echo.Context, msg, obj, act string) error

func CasbinAppMW

func CasbinAppMW(parserFn AppEnvParser, action string) echo.MiddlewareFunc

func CasbinMiddleware

func CasbinMiddleware(config CasbinConfig) echo.MiddlewareFunc

MiddlewareWithConfig returns a CasbinAuth middleware with config. See `CasbinMiddleware()`.

func GrafanaAuthMW

func GrafanaAuthMW(next echo.HandlerFunc) echo.HandlerFunc

func OpenAuth

func OpenAuth(next echo.HandlerFunc) echo.HandlerFunc

func ParseAppEnvFromConfigID

func ParseAppEnvFromConfigID(c echo.Context) (appName, env string, err error)

ParseAppEnvFromConfigID 从

func ParseAppEnvFromContext

func ParseAppEnvFromContext(c echo.Context) (appName, env string, err error)

ParseAppEnvFromContext 从Query/Body参数中获取应用环境信息

func ProxyAuth

func ProxyAuth(next echo.HandlerFunc) echo.HandlerFunc

func ProxyGatewayMW

func ProxyGatewayMW(next echo.HandlerFunc) echo.HandlerFunc

Types

type AppEnvParser

type AppEnvParser func(c echo.Context) (appName, env string, err error)

从 echo context 中获取 app 和 env 参数的函数

type Auth

type Auth struct {
	Authenticator func(echo.Context) error
	Unauthorized  func(echo.Context) error
}

func LoginAuth

func LoginAuth(loginURL string, redirectType RedirectType) *Auth

func (Auth) Func

func (a Auth) Func() echo.MiddlewareFunc

type CasbinConfig

type CasbinConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper middleware.Skipper

	// Enforcer CasbinAuth main rule.
	// Required.
	Enforcer *casbin.SyncedEnforcer
}

CasbinConfig defines the config for CasbinAuth middleware.

func (*CasbinConfig) CheckPermission

func (a *CasbinConfig) CheckPermission(user *db.User, path, method string) (bool, error)

CheckUserPermission checks the user/method/path combination from the request. Returns true (permission granted) or false (permission forbidden)

type OpenAuthCommonPayload

type OpenAuthCommonPayload struct {
	AppID     string `json:"app_id" query:"app_id" validate:"required"`
	Timestamp int64  `json:"timestamp" query:"timestamp" validate:"required"`
	NonceStr  string `json:"nonce_str" query:"nonce_str" validate:"required"`
	Sign      string `json:"sign" query:"sign" validate:"required"`
}

type RedirectType

type RedirectType string
const (
	RedirectTypeHttp RedirectType = "http_redirect"
	RedirectTypeJson RedirectType = "json_redirect"
)