casbin

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

PaySuper Echo Casbin Middleware

License contributions welcome Build Status Go Report Card

PaySuper Echo Casbin Middleware uses PaySuper Casbin Server go-micro server with a single policy model.


Table of Contents

Contributing, Feature Requests and Support

If you like this project then you can put a ⭐ on it. It means a lot to us.

If you have an idea of how to improve PaySuper (or any of the product parts) or have general feedback, you're welcome to submit a feature request.

Chances are, you like what we have already but you may require a custom integration, a special license or something else big and specific to your needs. We're generally open to such conversations.

If you have a question and can't find the answer yourself, you can raise an issue and describe what exactly you're trying to do. We'll do our best to reply in a meaningful time.

We feel that a welcoming community is important and we ask that you follow PaySuper's Open Source Code of Conduct in all interactions with the community.

PaySuper welcomes contributions from anyone and everyone. Please refer to our contribution guide to learn more.

License

The project is available as open source under the terms of the Apache-2.0 License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLogger = &logger.Zap{}
	// DefaultConfig is the default CasbinAuth middleware config.
	DefaultConfig = Config{
		Skipper: middleware.DefaultSkipper,
		Mode:    EnforceModeEnforcing,
		Logger:  DefaultLogger,
	}
)

Functions

func Middleware

func Middleware(c client.Client, mode EnforceMode) 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(c client.Client, 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
	// Enforce mode
	Mode EnforceMode
	// Logger
	Logger logger.Logger
	// CtxUserExtractor
	CtxUserExtractor CtxUserExtractor

	// Service Name
	ServiceName string
	// contains filtered or unexported fields
}

Config defines the config for CasbinAuth middleware.

func (*Config) CheckPermission

func (cfg *Config) CheckPermission(c echo.Context) bool

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

type CtxUserExtractor

type CtxUserExtractor func(c echo.Context) string

type EnforceMode

type EnforceMode int
const (
	EnforceModeUnknown EnforceMode = iota
	EnforceModePermissive
	EnforceModeEnforcing
	EnforceModeDisabled
)

Jump to

Keyboard shortcuts

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