auth

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

Auth

集成JWTCasbin

micro plugin 集成

  • auth插件注册casbinadapter
    • auth.RegisterAdapter("default", a)
    • 注册key--casbin_adapter参数保持一致,默认default可以省略参数
  • --auth_pub_key--casbin_model均有默认路径,可以根据自己的目录进行配置
  • --casbin_watcher可选
    • auth.RegisterWatcher("default", w)
    • 同样使用default可以省略参数
  • 自定义tokenaccess control验证失败时的响应
    • auth.AuthResponse = auth.DefaultResponseHandler
  • --casbin_public_userpublic接口指定user,默认为public,设置为空则无public接口

// micro plugin示例

func init() {
	// adapter
	// xorm
	// a, _ := xormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/")
	// file
	a := fileadapter.NewAdapter("./conf/casbin_policy.csv")
	auth.RegisterAdapter("default", a)

	// watcher
	// https://casbin.org/docs/zh-CN/watchers
	// w, _ := rediswatcher.NewWatcher("127.0.0.1:6379")
	// auth.RegisterWatcher("default", w)

	// 自定义Response
	auth.AuthResponse = auth.DefaultResponseHandler

	api.Register(auth.NewPlugin())
}
--auth_pub_key value        Auth public key file (default: "./conf/auth_key.pub")
--casbin_model value        Casbin model config file (default: "./conf/casbin_model.conf")
--casbin_adapter value      Casbin registed adapter {default} (default: "default")
--casbin_watcher value      Casbin registed watcher {} (default: "default")
--casbin_public_user value  Casbin public user (default: "public")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultResponseHandler

func DefaultResponseHandler(w http.ResponseWriter, r *http.Request, err error)

func NewPlugin

func NewPlugin() plugin.Plugin

func RegisterAdapter

func RegisterAdapter(key string, a persist.Adapter)

func RegisterWatcher

func RegisterWatcher(key string, w persist.Watcher)

Types

type Auth

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

type ResponseHandler

type ResponseHandler func(w http.ResponseWriter, r *http.Request, err error)
var AuthResponse ResponseHandler

Jump to

Keyboard shortcuts

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