package
0.0.4
Repository: https://github.com/micro-in-cn/x-gateway.git
Documentation: pkg.go.dev

# 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")

# Functions

NewPlugin for auth.
RegisterAdapter of auth.
RegisterWatcher of auth.
WithResponseHandler of auth.
WithSkipperFunc of auth.

# Structs

Auth for micro.
Options of auth.

# Type aliases

Option of auth.