authz

package module
v0.0.0-...-be858f7 Latest Latest
Warning

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

Go to latest
Published: May 19, 2017 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

authz Build Status Coverage Status GoDoc

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

Installation

go get github.com/tango-contrib/authz

Simple Example

package main

import (
	"github.com/casbin/casbin"
	"github.com/lunny/tango"
	"github.com/tango-contrib/authz"
	"github.com/tango-contrib/session"
)

func main() {
	tg := tango.Classic()
	sessions := session.New()

	tg.Use(tango.HandlerFunc(func(ctx *tango.Context) {
		sess := sessions.Session(ctx.Req(), ctx.ResponseWriter)
		sess.Set("casbin_user", "user's name")
		ctx.Next()
	}))

	// load the casbin model and policy from files, database is also supported.
	e := casbin.NewEnforcer("examples/basic_model.conf", "examples/basic_policy.csv")
	tg.Use(authz.Auth(&e, sessions))
	
	// define the routers
	// the access that is denied by authz will return "You have no permission to visit this page"
	tg.Any("*", func() string {
	    // the access is permitted when got here
		return "You have the correct permission"
	})

	tg.Run()
}

Getting Help

License

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultUserSessionKey = "casbin_user"
	DefaultNoPermString   = "You have no permission to visit this page"
	DefaultHasPermString  = "You have the correct permission"
)

Functions

func Auth

func Auth(enforcer *casbin.Enforcer, sessions *session.Sessions) tango.HandlerFunc

Auth return a casbin handler.

Types

This section is empty.

Jump to

Keyboard shortcuts

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