auth

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2019 License: Apache-2.0 Imports: 22 Imported by: 114

Documentation

Index

Constants

View Source
const DefaultCookieKey = "go_admin_session"

Variables

View Source
var (
	// TokenHelper helps check the token.
	TokenHelper = new(CSRFToken)

	// CsrfTokenLock is the a lock of checking.
	CsrfTokenLock sync.Mutex
)
View Source
var Middleware = DefaultInvoker().Middleware()

Middleware is the default auth middleware of plugins.

Functions

func Auth added in v1.0.0

func Auth(ctx *context.Context) models.UserModel

Auth get the user model from Context.

func Check

func Check(password string, username string) (user models.UserModel, ok bool)

Check check the password and username and return the user model.

func CheckPermissions

func CheckPermissions(user models.UserModel, path string, method string) bool

CheckPermissions check the permission of the user.

func DelCookie

func DelCookie(ctx *context.Context) bool

DelCookie delete the cookie from Context.

func EncodePassword

func EncodePassword(pwd []byte) string

EncodePassword encode the password.

func Filter

func Filter(ctx *context.Context) (models.UserModel, bool, bool)

Filter retrieve the user model from Context and check the permission at the same time.

func GetCurUser added in v1.0.9

func GetCurUser(sesKey string) (user models.UserModel, ok bool)

GetCurUser return the user model.

func GetCurUserByID added in v1.0.8

func GetCurUserByID(id int64) (user models.UserModel, ok bool)

GetCurUserByID return the user model of given user id.

func GetSessionByKey added in v1.0.9

func GetSessionByKey(sesKey, key string) interface{}

GetSessionByKey get the session value by key.

func GetUserID added in v1.0.9

func GetUserID(sesKey string) int64

GetUserID return the user id from the session.

func SetCookie

func SetCookie(ctx *context.Context, user models.UserModel) bool

SetCookie set the cookie.

Types

type CSRFToken

type CSRFToken []string

CSRFToken is type of a csrf token list.

func (*CSRFToken) AddToken

func (csrf *CSRFToken) AddToken() string

AddToken add the token to the CSRFToken.

func (*CSRFToken) CheckToken

func (csrf *CSRFToken) CheckToken(toCheckToken string) bool

CheckToken check the given token with tokens in the CSRFToken, if exist return true.

type Config

type Config struct {
	Expires time.Duration
	Cookie  string
}

Config wraps the Session info.

type DBDriver added in v1.0.8

type DBDriver struct{}

DBDriver is a driver which uses database as a persistence tool.

var Driver DBDriver

Driver is the default PersistenceDriver.

func (*DBDriver) Load added in v1.0.8

func (driver *DBDriver) Load(sid string) map[string]interface{}

Load implements the PersistenceDriver.Load.

func (*DBDriver) Update added in v1.0.8

func (driver *DBDriver) Update(sid string, values map[string]interface{})

Update implements the PersistenceDriver.Update.

type Invoker

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

Invoker contains the callback functions which are used in the route middleware.

func DefaultInvoker added in v1.0.0

func DefaultInvoker() *Invoker

DefaultInvoker return a default Invoker.

func SetPrefix

func SetPrefix(prefix string) *Invoker

SetPrefix return the default Invoker with the given prefix.

func (*Invoker) Middleware

func (invoker *Invoker) Middleware() context.Handler

Middleware get the auth middleware from Invoker.

func (*Invoker) SetAuthFailCallback

func (invoker *Invoker) SetAuthFailCallback(callback MiddlewareCallback) *Invoker

SetAuthFailCallback set the authFailCallback of Invoker.

func (*Invoker) SetPermissionDenyCallback

func (invoker *Invoker) SetPermissionDenyCallback(callback MiddlewareCallback) *Invoker

SetPermissionDenyCallback set the permissionDenyCallback of Invoker.

type MiddlewareCallback

type MiddlewareCallback func(ctx *context.Context)

MiddlewareCallback is type of callback function.

type PersistenceDriver

type PersistenceDriver interface {
	Load(string) map[string]interface{}
	Update(sid string, values map[string]interface{})
}

PersistenceDriver is a driver of storing and getting the session info.

type Session

type Session struct {
	Expires time.Duration
	Cookie  string
	Values  map[string]interface{}
	Driver  PersistenceDriver
	Sid     string
	Context *context.Context
}

Session contains info of session.

func InitSession

func InitSession(ctx *context.Context) *Session

InitSession return the default Session.

func (*Session) Add added in v1.0.8

func (ses *Session) Add(key string, value interface{})

Add add the session value of key.

func (*Session) Clear

func (ses *Session) Clear()

Clear clear a Session.

func (*Session) Get

func (ses *Session) Get(key string) interface{}

Get get the session value.

func (*Session) StartCtx

func (ses *Session) StartCtx(ctx *context.Context) *Session

StartCtx return a Session from the given Context.

func (*Session) UpdateConfig

func (ses *Session) UpdateConfig(config Config)

UpdateConfig update the Expires and Cookie of Session.

func (*Session) UseDriver added in v1.0.8

func (ses *Session) UseDriver(driver PersistenceDriver)

UseDriver set the driver of the Session.

Jump to

Keyboard shortcuts

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