bouncer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrForbidden - requester does not have sufficient permission to perform request -
	// non of the rules have not returned non nil response
	ErrForbidden = errors.New("forbidden")
	//ErrNotAllowed - token is malformed, expired or not present
	ErrNotAllowed = errors.New("not allowed")
)

Functions

func GenerateJWT

func GenerateJWT(cfg Config, vault secret.Vault, log *logan.Entry)

func RequestMiddleware

func RequestMiddleware(log *logan.Entry, bouncer Bouncer, next http.HandlerFunc) http.HandlerFunc

Types

type Admin

type Admin struct {
	Authorized bool
}

func (Admin) IsAuthorized

func (a Admin) IsAuthorized(claims Claims) bool

type Bouncer

type Bouncer interface {
	Check(r *http.Request, rules ...Rule) (*Claims, error)
	Config() Config
}

func New

func New(opts Config) Bouncer

type Bouncerer

type Bouncerer interface {
	Bouncer() Bouncer
}

func NewBouncerer

func NewBouncerer(getter kv.Getter) Bouncerer

type Claims

type Claims struct {
	Authorized bool `json:"authorized"`
	jwt.RegisteredClaims
}

func ParseClaims

func ParseClaims(r *http.Request) (*Claims, error)

ParseClaims - parses claims without signature verification and token validation. Returns ErrNotAllowed if token is malformed or not present

type Config

type Config struct {
	// SkipChecks make any request with valid or missing token pass
	SkipChecks bool
	TTL        time.Duration
}

type Rule

type Rule interface {
	IsAuthorized(Claims) bool
}

type RuleFunc

type RuleFunc func(Claims) bool

The RuleFunc type is an adapter to allow the use of ordinary functions as Rule

func (RuleFunc) IsAuthorized

func (r RuleFunc) IsAuthorized(claims Claims) bool

Jump to

Keyboard shortcuts

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