Back to godoc.org

Package casbin

v0.6.1-0...-f4ded4a
Latest Go to latest

The latest major version is .

Published: Oct 15, 2019 | License: MIT | Module: github.com/3CLogicInc/echo-contrib

Index

Variables

var (
	// DefaultConfig is the default CasbinAuth middleware config.
	DefaultConfig = Config{
		Skipper: middleware.DefaultSkipper,
	}
)

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()`.

type AuthenticationType

type AuthenticationType int

AuthenticationType ...

const (
	//BasicAuth refers to basic authentication
	//default option
	BasicAuth AuthenticationType = iota
	//JwtAuth refers to JWT token auth in 'Authorization` header
	JwtAuth
)

type Config

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

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

	//AuthType ...
	AuthType AuthenticationType
}

Config defines the config for CasbinAuth middleware.

func (*Config) CheckPermission

func (a *Config) CheckPermission(c echo.Context) (bool, error)

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

func (*Config) GetUserName

func (a *Config) GetUserName(c echo.Context) string

GetUserName gets the user name from the request. Currently, only HTTP basic authentication is supported

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier