token_go

package module
v0.0.0-...-54428ee Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultAdapter

func NewDefaultAdapter() persist.Adapter

func NewHttpContext

func NewHttpContext(req *http.Request, writer http.ResponseWriter) ctx.Context

Types

type Enforcer

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

func InitWithConfig

func InitWithConfig(tokenConfig *config.TokenConfig, adapter persist.Adapter) (*Enforcer, error)

func InitWithDefaultConfig

func InitWithDefaultConfig(adapter persist.Adapter) (*Enforcer, error)

func InitWithFile

func InitWithFile(conf string, adapter persist.Adapter) (*Enforcer, error)

func NewEnforcer

func NewEnforcer(adapter persist.Adapter, args ...interface{}) (*Enforcer, error)

func (*Enforcer) AddTokenGenerateFun

func (e *Enforcer) AddTokenGenerateFun(tokenStyle string, f model.GenerateFunc) error

AddTokenGenerateFun add token generate strategy

func (*Enforcer) Banned

func (e *Enforcer) Banned(id string, service string) error

func (*Enforcer) CheckLogin

func (e *Enforcer) CheckLogin(ctx ctx.Context) error

func (*Enforcer) CheckPermission

func (e *Enforcer) CheckPermission(ctx ctx.Context, permission string) error

func (*Enforcer) CheckRole

func (e *Enforcer) CheckRole(ctx ctx.Context, role string) error

func (*Enforcer) EnableLog

func (e *Enforcer) EnableLog()

func (*Enforcer) GetAdapter

func (e *Enforcer) GetAdapter() persist.Adapter

func (*Enforcer) GetLoginCount

func (e *Enforcer) GetLoginCount(id string) int

func (*Enforcer) GetLoginId

func (e *Enforcer) GetLoginId(ctx ctx.Context) (string, error)

func (*Enforcer) GetRequestToken

func (e *Enforcer) GetRequestToken(ctx ctx.Context) string

GetRequestToken read token from requestHeader | cookie | requestBody

func (*Enforcer) GetSession

func (e *Enforcer) GetSession(id string) *model.Session

func (*Enforcer) GetType

func (e *Enforcer) GetType() string

func (*Enforcer) IsLogEnable

func (e *Enforcer) IsLogEnable() bool

func (*Enforcer) IsLogin

func (e *Enforcer) IsLogin(ctx ctx.Context) (bool, error)

IsLogin check if user logged in by token.

func (*Enforcer) IsLoginById

func (e *Enforcer) IsLoginById(id string) (bool, error)

IsLoginById check if user logged in by loginId. check all tokenValue and if one is validated return true

func (*Enforcer) Kickout

func (e *Enforcer) Kickout(id string, device string) error

Kickout kickout user

func (*Enforcer) Login

func (e *Enforcer) Login(id string, ctx ctx.Context) (string, error)

Login login by id and default loginModel, return tokenValue and error

func (*Enforcer) LoginByModel

func (e *Enforcer) LoginByModel(id string, loginModel *model.Login, ctx ctx.Context) (string, error)

LoginByModel login by id and loginModel, return tokenValue and error

func (*Enforcer) Logout

func (e *Enforcer) Logout(ctx ctx.Context) error

Logout user logout

func (*Enforcer) Replaced

func (e *Enforcer) Replaced(id string, device string) error

Replaced replace other user

func (*Enforcer) SetAdapter

func (e *Enforcer) SetAdapter(adapter persist.Adapter)

func (*Enforcer) SetAuth

func (e *Enforcer) SetAuth(manager interface{})

func (*Enforcer) SetLogger

func (e *Enforcer) SetLogger(logger log.Logger)

func (*Enforcer) SetSession

func (e *Enforcer) SetSession(id string, session *model.Session, timeout int64) error

func (*Enforcer) SetType

func (e *Enforcer) SetType(t string)

func (*Enforcer) SetWatcher

func (e *Enforcer) SetWatcher(watcher persist.Watcher)

type IEnforcer

type IEnforcer interface {
	Login(id string, ctx ctx.Context) (string, error)
	LoginByModel(id string, loginModel *model.Login, ctx ctx.Context) (string, error)
	Logout(ctx ctx.Context) error
	IsLogin(ctx ctx.Context) (bool, error)
	IsLoginById(id string) (bool, error)
	GetLoginId(ctx ctx.Context) (string, error)
	GetLoginCount(id string) int

	Replaced(id string, device string) error
	// Banned TODO
	Banned(id string, service string) error
	Kickout(id string, device string) error

	GetRequestToken(ctx ctx.Context) string
	AddTokenGenerateFun(tokenStyle string, f model.GenerateFunc) error

	CheckLogin(ctx ctx.Context) error

	SetAuth(manager interface{})
	CheckRole(ctx ctx.Context, role string) error
	CheckPermission(ctx ctx.Context, permission string) error

	SetType(t string)
	GetType() string
	GetAdapter() persist.Adapter
	SetAdapter(adapter persist.Adapter)
	SetWatcher(watcher persist.Watcher)
	SetLogger(logger log.Logger)
	EnableLog()
	IsLogEnable() bool
	GetSession(id string) *model.Session
	SetSession(id string, session *model.Session, timeout int64) error
}

Directories

Path Synopsis
ctx

Jump to

Keyboard shortcuts

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