auth

package
v0.0.0-...-074ee30 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserSessionTimeout = time.Hour * 24 * 10 // 10 days

)

Variables

View Source
var (
	ErrAuthentication         = errors.New("auth.user.authenticationError")
	ErrUserRetrieval          = errors.New("auth.user.retrievalError")
	ErrToken                  = errors.New("auth.user.authTokenError")
	ErrInsufficientPrivileges = errors.New("auth.user.insufficient.privs")
)
View Source
var ValidRoles = []Role{
	Normal,
	Admin,
	Super,
}

Functions

func GetJWTKey

func GetJWTKey() []byte

GetJWTKey - gives a unique JWT key

func HasPerms

func HasPerms(u User, permIds ...string) bool

func HasRole

func HasRole(u User, role Role) bool

Types

type AuthData

type AuthData map[string]interface{}

func (AuthData) Decode

func (ad AuthData) Decode(out any) error

type Authenticator

type Authenticator interface {
	Authenticate(gtx context.Context, authData AuthData) error
}

type Group

type Group struct {
	SeqId int    `json:"seqId" db:"seq_id" bson:"seqId"`
	Id    string `json:"id" db:"id" bson:"id"`
	Name  string `json:"name" db:"name" bson:"name"`
}

type PermissionNode

type PermissionNode struct {
	Id         int    `json:"id" db:"id"`
	PermId     string `json:"permId" db:"permId"`
	Name       string `json:"name" db:"name"`
	Predefined bool   `json:"predefined" db:"predefined"`
	// Base       string            `json:"base" db:"base"`
	Children []*PermissionNode `json:"children"`
}

func (*PermissionNode) AddChild

func (pn *PermissionNode) AddChild(child *PermissionNode)

type PermissionSet

type PermissionSet map[string]struct{}

func MergePerms

func MergePerms(permSets []PermissionSet) PermissionSet

func (PermissionSet) HasPerm

func (pm PermissionSet) HasPerm(permId string) bool

type PermissionTree

type PermissionTree struct {
	Permissions []*PermissionNode `json:"permissions"`
}

type Role

type Role string
const (
	None   Role = ""
	Normal Role = "Normal"
	Admin  Role = "Admin"
	Super  Role = "Super"
)

func ToRole

func ToRole(roleStr string) Role

func (Role) EqualOrAbove

func (r Role) EqualOrAbove(another Role) bool

func (Role) IsOneOf

func (r Role) IsOneOf(others ...Role) bool

type User

type User interface {
	Id() int64
	Username() string
	Email() string
	FullName() string
	Role() Role
	GroupIds() []string
	Permissions() PermissionSet
}

func Login

func Login(
	gtx context.Context,
	authr UserAuthenticator,
	data AuthData) (User, string, error)

TODO - remove once idx is operational Login - authenticates the user, get's the user information and generates a JWT token. The user and the token are then returned. And in case of error the error is returned

type UserAndPassword

type UserAndPassword struct {
	Username string `json:"userId"`
	Password string `json:"password"`
}

type UserAuthenticator

type UserAuthenticator interface {
	Authenticator
	UserGetter
}

type UserGetter

type UserGetter interface {
	GetUser(gtx context.Context, authData AuthData) (User, error)
}

type UserRetriever

type UserRetriever interface {
	GetUser(gtx context.Context, userId string) (User, error)
}

Jump to

Keyboard shortcuts

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