casbin

package
v0.0.0-...-c96edae Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default CasbinAuth middleware config.
	DefaultConfig = Config{
		Skipper: middleware.DefaultSkipper,
		UserGetter: func(c echo.Context) (string, error) {
			username, _, _ := c.Request().BasicAuth()
			return username, nil
		},
		ErrorHandler: func(c echo.Context, internal error, proposedStatus int) error {
			err := echo.NewHTTPError(proposedStatus, internal.Error())
			err.Internal = internal
			return err
		},
	}
)

Functions

func Middleware

func Middleware(ce *casbin.Enforcer) echo.MiddlewareFunc

Middleware returns a CasbinAuth middleware.

For valid credentials it calls the next handler. For missing or invalid credentials, it sends "401 - Unauthorized" response.

func MiddlewareWithConfig

func MiddlewareWithConfig(config Config) echo.MiddlewareFunc

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

Types

type Config

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

	// Enforcer CasbinAuth main rule.
	// One of Enforcer or EnforceHandler fields is required.
	Enforcer *casbin.Enforcer

	// EnforceHandler is custom callback to handle enforcing.
	// One of Enforcer or EnforceHandler fields is required.
	EnforceHandler func(c echo.Context, user string) (bool, error)

	// Method to get the username - defaults to using basic auth
	UserGetter func(c echo.Context) (string, error)

	// Method to handle errors
	ErrorHandler func(c echo.Context, internal error, proposedStatus int) error
}

Config defines the config for CasbinAuth middleware.

Jump to

Keyboard shortcuts

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