Read the Caddyfile for config file path.
2 files changed
tree: 6f409bb42476b0ecd9b745e4b341299f987cdb28
  1. .gitignore
  2. authz.go
  3. authz_model.conf
  4. authz_policy.csv
  5. authz_test.go
  6. casbin.conf
  7. LICENSE
  8. README.md
README.md

Caddy-authz GoDoc

Caddy-authz is an authorization middleware for Caddy, it's based on https://github.com/casbin/casbin.

Installation

go get github.com/casbin/caddy-authz

Simple Example

package main

import (
	"net/http"

	"github.com/casbin/caddy-authz"
	"github.com/casbin/casbin"
	"github.com/mholt/caddy/caddyhttp/httpserver"
)

func main() {
	// load the casbin model and policy from files, database is also supported.
	e := casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")

	// define your handler, this is just an example to return HTTP 200 for any requests.
	// the access that is denied by authz will return HTTP 403 error.
	handler := authz.Authorizer{
        Next: httpserver.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
            return http.StatusOK, nil
        }),
        Enforcer: e,
    }
}

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.