console

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package console serves the organization console (ADR-018): organization administration on the SystemAuth host, signed in with the SystemAuth login session. It mounts existing handlers, such as the connections API, under /console/api with a session authenticator, describes the session under /console/bff in the format @plexusone/host reads, and serves the console's built pages under /console/.

The console delegates nothing, so OAuth scopes do not apply to it; every request is authorized by the person's organization role and grants, as any caller's is. State-changing requests must be same-origin.

Index

Constants

View Source
const (
	// Prefix is where the console is served.
	Prefix = "/console"
	// APIPrefix is the console's API.
	APIPrefix = Prefix + "/api"
	// ReturnToPath checks a return address from an application's link.
	ReturnToPath = APIPrefix + "/v1/return-to"
	// BFFPrefix serves the session routes a @plexusone/host SessionClient
	// reads: GET session, GET auth/login and auth/{provider}, POST
	// auth/logout.
	BFFPrefix = Prefix + "/bff"
	// SessionPath describes the signed-in person and their organizations.
	SessionPath = BFFPrefix + "/session"
	// AppID is the console's application ID in the session's memberships:
	// each organization grants the person their organization role in it.
	AppID = "console"
)

Paths.

Variables

View Source
var ErrNoSession = errors.New("console: no login session")

ErrNoSession is returned by Options.Principal when the request carries no valid login session.

Functions

This section is empty.

Types

type App

type App struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	URL   string `json:"url"`
	Icon  string `json:"icon,omitempty"`
	Order int    `json:"order,omitempty"`
}

App is an application in the deployment's catalog.

type Console

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

Console is the organization console's handler.

func New

func New(o Options) (*Console, error)

New returns a console for o.

func (*Console) Close

func (c *Console) Close() error

Close releases the built pages' directory. A console without WebDir has nothing to release. The console must not serve requests afterwards.

func (*Console) ServeHTTP

func (c *Console) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type Options

type Options struct {
	// Principal returns the person signed in on r, or an error wrapping
	// ErrNoSession. Required.
	Principal func(r *http.Request) (uuid.UUID, error)
	// Organizations lists the person's organizations, personal first.
	// Required.
	Organizations func(ctx context.Context, principal uuid.UUID) ([]Organization, error)
	// ReturnTo validates a return address, returning the URL to use or an
	// error. Required.
	ReturnTo func(raw string) (string, error)
	// SignOut ends the login session on r. Required.
	SignOut func(w http.ResponseWriter, r *http.Request) error
	// Apps lists the deployment's application catalog, for the console's
	// product switcher. Nil lists none.
	Apps func(ctx context.Context) ([]App, error)
	// Connections, if set, serves the connections section.
	Connections *connections.Connections
	// WebDir holds the built console pages. Empty serves only the API.
	WebDir string
	// LoginPath is where a page load without a session is sent, with the
	// page as return_to. Default "/login".
	LoginPath string
	Logger    *slog.Logger
}

Options configures a console.

type Organization

type Organization struct {
	ID   string `json:"id"`
	Slug string `json:"slug,omitempty"`
	Name string `json:"name,omitempty"`
	// Type is personal, team or enterprise.
	Type string `json:"type,omitempty"`
	// Role is the person's organization role: owner, admin, member or
	// collaborator.
	Role string `json:"role"`
	// Apps maps each application the person may open in the organization
	// to their role in it, so the console's product switcher can list them.
	Apps map[string]string `json:"apps,omitempty"`
}

Organization is an organization the signed-in person belongs to.

Jump to

Keyboard shortcuts

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