authz

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

CleverGo Authorization Middleware

Build Status Coverage Status Go.Dev reference Go Report Card Release

Usage

import (
    "clevergo.tech/authz"
    "clevergo.tech/clevergo"
)
enforcer, _ := casbin.NewEnforcer("casbin_model.conf", "casbin_policy.csv")
userFunc := func(c *clevergo.Context) (id string, err error) {
    // returns the authenticated user ID.
    return
}
app := clevergo.New()
app.Use(authz.New(enforcer, userFunc))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = clevergo.NewError(http.StatusUnauthorized, errors.New(http.StatusText(http.StatusUnauthorized)))
	ErrForbidden    = clevergo.NewError(http.StatusForbidden, errors.New("you are not allowed to access this page"))
)

Errors

Functions

func New

func New(enforcer *casbin.Enforcer, userFunc UserFunc, opts ...Option) clevergo.MiddlewareFunc

New returns a middleware with the given enforcer, user function and optional options.

Types

type Option

type Option func(*authorization)

Option is a function that apply on authorization middleware.

func WithSkipper

func WithSkipper(skipper clevergo.Skipper) Option

WithSkipper is an option that set authorization's skipper.

type UserFunc

type UserFunc func(c *clevergo.Context) (id string, err error)

UserFunc is a function that returns a string which represents the authenticated user.

Jump to

Keyboard shortcuts

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