auth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("forbidden")
View Source
var ErrInvalid = errors.New("invalid input")
View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

func Authorize

func Authorize(p Principal, op Operation, ownerKeyID string) error

func ClearSessionCookie

func ClearSessionCookie(allowInsecureHTTP bool) *http.Cookie

func SessionCookie

func SessionCookie(value string, allowInsecureHTTP bool) *http.Cookie

Types

type Key

type Key struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	IssuerID   string `json:"issuer_id"`
	IssuerName string `json:"issuer_name"`
	CreatedAt  string `json:"created_at"`
	ExpiresAt  string `json:"expires_at"`
	Note       string `json:"note"`
	LastUsedAt string `json:"last_used_at"`
	RevokedAt  string `json:"revoked_at"`
	Level      Level  `json:"level"`
}

type Level

type Level string
const (
	Read    Level = "read"
	Propose Level = "propose"
	Write   Level = "write"
)

type Operation

type Operation string
const (
	View          Operation = "view"
	PutContext    Operation = "put_context"
	RecordNote    Operation = "record_note"
	ProposeChange Operation = "propose_change"
	Update        Operation = "update"
	MarkVerified  Operation = "mark_verified"
	CheckVersions Operation = "check_versions"
	Approve       Operation = "approve"
	Reject        Operation = "reject"
	Delete        Operation = "delete"
	ManageKeys    Operation = "manage_keys"
	Restore       Operation = "restore"
)

type Principal

type Principal struct {
	UserID, Login, KeyID, KeyName, IssuerID, IssuerName string
	Level                                               Level
}

func (Principal) IsUser

func (p Principal) IsUser() bool

type Service

type Service struct {
	DB     *sql.DB
	Pepper []byte
}

func (Service) Authenticate

func (s Service) Authenticate(ctx context.Context, bearer string) (Principal, error)

func (Service) BootstrapUser

func (s Service) BootstrapUser(ctx context.Context, login, password string) (string, error)

BootstrapUser is for a local, one-time setup command; it refuses a second account.

func (Service) IssueKey

func (s Service) IssueKey(ctx context.Context, p Principal, name string, level Level, expires *time.Time, note string) (Key, string, error)

func (Service) Keys

func (s Service) Keys(ctx context.Context, p Principal) ([]Key, error)

func (Service) Login

func (s Service) Login(ctx context.Context, login, password string) (session, csrf string, p Principal, err error)

func (Service) Logout

func (s Service) Logout(ctx context.Context, session string) error

func (Service) Revoke

func (s Service) Revoke(ctx context.Context, p Principal, id string) error

func (Service) Session

func (s Service) Session(ctx context.Context, session, csrf string, mutating bool) (Principal, error)

Session verifies the cookie and, for mutating methods, the double-submit CSRF token.

func (Service) SetLevel

func (s Service) SetLevel(ctx context.Context, p Principal, id string, level Level) error

Jump to

Keyboard shortcuts

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