auth

package
v0.8.10 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 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 ErrDoNotCache = errors.New("not cacheable")
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 CanCache added in v0.8.10

func CanCache[T TAuthable](a OpAuth, u T, field string, cache string, 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, adminRole 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
	AdminRole() string
}

type IUser

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

type OpAuth

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

type Operant

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

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)
	CacheKey() string
}

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