auth

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 14 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

Auth

集成JWT与Casbin

micro plugin 集成

  • auth插件注册casbin的adapter
    • auth.RegisterAdapter("default", a)
    • 注册key与--casbin_adapter参数保持一致,默认default可以省略参数
  • --auth_pub_key、--casbin_model均有默认路径,可以根据自己的目录进行配置
  • --casbin_watcher可选
    • auth.RegisterWatcher("default", w)
    • 同样使用default可以省略参数
  • 自定义token或access control验证失败时的响应
    • auth.AuthResponse = auth.DefaultResponseHandler
  • --casbin_public_user为public接口指定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 NewPlugin

func NewPlugin(opts ...Option) plugin.Plugin

NewPlugin for auth

func RegisterAdapter

func RegisterAdapter(key string, a persist.Adapter)

RegisterAdapter of auth

func RegisterWatcher

func RegisterWatcher(key string, w persist.Watcher)

RegisterWatcher of auth

Types

type Auth

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

Auth for micro

type Option

type Option func(o *Options)

Option of auth

func WithResponseHandler

func WithResponseHandler(handler response.Handler) Option

WithResponseHandler of auth

func WithSkipperFunc

func WithSkipperFunc(skipperFunc request.SkipperFunc) Option

WithSkipperFunc of auth

type Options

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

Options of auth

Jump to

Keyboard shortcuts

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