auth

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Interfaces = iota
	Controllers
	Doors
	Cards
	Groups
	Events
	Logs
	Users
)

Variables

View Source
var ErrUnauthorised = errors.New("not authorised")
View Source
var GRULES embed.FS

Functions

func CanAdd added in v0.8.3

func CanAdd[T TAuthable](a OpAuth, u T, rulesets ...RuleSet) error

func CanDelete added in v0.8.3

func CanDelete[T TAuthable](a OpAuth, u T, rulesets ...RuleSet) error

func CanUpdate added in v0.8.3

func CanUpdate[T TAuthable](a OpAuth, u T, field string, value any, rulesets ...RuleSet) error

func CanView added in v0.8.3

func CanView[T TAuthable](a OpAuth, u T, field string, value any, rulesets ...RuleSet) error

func Init

func Init(rules map[RuleSet]string) error

func UID

func UID(a *Authorizator) string

Types

type Authorizator

type Authorizator struct {
	OpAuth
	// contains filtered or unexported fields
}

func NewAuthorizator

func NewAuthorizator(uid, role string) *Authorizator

type IAuthenticate

type IAuthenticate interface {
	Preauthenticate() (string, error)
	Authenticate(uid, pwd string) (string, error)
	Validate(uid, pwd string) error
	Verify(tokenType TokenType, token string) error
	Authenticated(token string) (string, string, string, error)
	Invalidate(tokenType TokenType, token string) error
	Options(uid, role string) Options
}

type IUser

type IUser interface {
	Password() ([]byte, string)
	OTPKey() string
	Role() string
	Locked() bool
}

type OpAuth

type OpAuth interface {
	CanView(o Operant, field string, value interface{}, rulesets ...RuleSet) error
	CanAdd(o Operant, rulesets ...RuleSet) error
	CanUpdate(o Operant, field string, value interface{}, rulesets ...RuleSet) error
	CanDelete(o Operant, rulesets ...RuleSet) error
}

type Operant

type Operant interface {
	AsRuleEntity() (string, interface{})
}

type Options added in v0.8.3

type Options struct {
	OTP struct {
		Allowed bool
		Enabled bool
	}
}

type RuleSet

type RuleSet int

func (RuleSet) String

func (r RuleSet) String() string

type TAuthable added in v0.8.3

type TAuthable interface {
	AsRuleEntity() (string, any)
}

type TokenType

type TokenType int
const (
	Login   TokenType = iota // 0
	Session                  // 1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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