author

package module
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: AGPL-3.0 Imports: 10 Imported by: 7

Documentation

Index

Constants

View Source
const (
	UsernameParam = "username"
	PasswordParam = "password"
	SessionParam  = "session"

	RedirectPathParam = "redirectPath"
)
View Source
const (
	UsernamePasswordProperty = "username-password"
	UsernameRoleProperty     = "username-role"
	UsernameSessionProperty  = "username-session"
	SessionCreatedProperty   = "session-created"
)
View Source
const CookieKeySession = "Session"

Variables

View Source
var (
	ErrUsernameExists           = errors.New("username already exists")
	ErrUsernameNotFound         = errors.New("username not found")
	ErrUsernamePasswordMissing  = errors.New("username is missing a password")
	ErrUsernamePasswordMismatch = errors.New("username password mismatch")
	ErrSessionExpired           = errors.New("session expired")
	ErrSessionNotValid          = errors.New("session is not valid")
	ErrInsufficientPermissions  = errors.New("insufficient permissions")
)

Functions

func AllProperties

func AllProperties() []string

func AuthSessionToken added in v0.1.12

func AuthSessionToken(sb *SessionBouncer, next http.Handler, requiredPermissions ...Permission) http.Handler

func IsNotAuthenticated

func IsNotAuthenticated(err error) bool

Types

type Authenticator

type Authenticator interface {
	HasUser(username string) (bool, error)
	CreateUser(username, password string) error
	CutUser(username, password string) error
	UpdatePassword(username, currentPassword, newPassword string) error
	SetRole(username, password, role string) error
	GetUserRoles() (map[string][]string, error)
	AuthenticateUser(username, password string) error

	CreateSession(username, password string) (string, error)
	SessionExpires(session string) (time.Time, error)
	AuthenticateSession(session string) error
	CutSession(session string) error
	CutUserSessions(username string) error
	GetSessionPermissions(session string) ([]Permission, error)
	MustHaveSessionPermissions(session string, requiredPermissions ...Permission) error
}

func NewAuthenticator

func NewAuthenticator(dir string, rolePermissions map[string][]Permission) (Authenticator, error)

type Permission

type Permission int

type SessionBouncer added in v0.1.9

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

func NewSessionBouncer added in v0.1.9

func NewSessionBouncer(dir string, rolePermissions map[string][]Permission, loginPath string) (*SessionBouncer, error)

func (*SessionBouncer) AuthApiSession added in v0.1.12

func (sb *SessionBouncer) AuthApiSession(w http.ResponseWriter, r *http.Request)

func (*SessionBouncer) AuthApiUsernamePassword added in v0.1.13

func (sb *SessionBouncer) AuthApiUsernamePassword(w http.ResponseWriter, r *http.Request)

func (*SessionBouncer) AuthBrowserUsernamePassword added in v0.1.13

func (sb *SessionBouncer) AuthBrowserUsernamePassword(w http.ResponseWriter, r *http.Request)

func (*SessionBouncer) DeauthSession added in v0.1.17

func (sb *SessionBouncer) DeauthSession(w http.ResponseWriter, r *http.Request)

func (*SessionBouncer) GetPermissions added in v0.1.20

func (sb *SessionBouncer) GetPermissions(r *http.Request) ([]Permission, error)

type SessionTokenExpires added in v0.1.12

type SessionTokenExpires struct {
	Token   string    `json:"token"`
	Expires time.Time `json:"expires"`
}

Jump to

Keyboard shortcuts

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