authj

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authorizer

func Authorizer(e casbin.IEnforcer, opts ...Option) gin.HandlerFunc

Authorizer returns the authorizer uses a Casbin enforcer, and Subject as subject.

func ContextWithSubject

func ContextWithSubject(c *gin.Context, subject string)

ContextWithSubject return a copy of parent in which the value associated with subjectCtxKey is subject.

func Subject

func Subject(c *gin.Context) string

Subject returns the value associated with this context for subjectCtxKey,

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config for Authorizer

type Option

type Option func(*Config)

Option config option

func WithErrorFallback

func WithErrorFallback(fn func(*gin.Context, error)) Option

WithErrorFallback set the fallback handler when request are error happened. default: the 500 server error to the client

func WithForbiddenFallback

func WithForbiddenFallback(fn func(*gin.Context)) Option

WithForbiddenFallback set the fallback handler when request are not allow. default: the 403 Forbidden to the client

func WithSkipAuthentication

func WithSkipAuthentication(fn func(*gin.Context) bool) Option

WithSkipAuthentication set the skip approve when it is return true. Default: always false

func WithSubject

func WithSubject(fn func(*gin.Context) string) Option

WithSubject set the subject extractor of the requests. default: Subject

Jump to

Keyboard shortcuts

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