Help us shape the future of Go! Take the 2026 Go Developer Survey

loopback

package
v0.1.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package loopback is the HTTPS loopback host shared by the browser examples that drive the TypeScript packages against the real Go server: core credentials with verification and reset mail, the magic-link plugin, the OAuth plugin bound to a built-in mock OIDC provider, and a development mail preview, served under a throwaway certificate on a loopback address. Each example adds its own pages. It exists so the client's and the React bindings' journeys can run in CI (AUTH-029, AUTH-030). It binds only to loopback, mints a certificate per run, exposes development proofs in its mail preview and raises abuse budgets for repeated journeys; none of this is a deployment pattern.

Index

Constants

View Source
const (
	MockClientID     = "sigil-client-example"
	MockClientSecret = "sigil-client-example-secret"
	MockSubject      = "mock-subject-1"
)

Fixed mock credentials and identity; tests assert on the subject.

Variables

This section is empty.

Functions

func Certificate

func Certificate(host string) (tls.Certificate, []byte, error)

Certificate is a throwaway self-signed leaf for the loopback origin, never written to disk by this package. Browsers accept it explicitly (Playwright: ignoreHTTPSErrors); a helper process receives the PEM from Host.

func LocalKey

func LocalKey(path string) ([]byte, error)

LocalKey reads the persistent 32-byte key, creating it with mode 0600 on first use.

func MailPreview

func MailPreview(origin string, delivery *sigil.MailDelivery, sink *sigil.LocalMailSink) http.HandlerFunc

MailPreview is a host-owned sensitive mutation (dispatch and drain), protected independently of the library's middleware by exact Origin + JSON.

func Origin

func Origin(host, addr string) (string, error)

Origin validates the listen address and host name and returns the HTTPS origin.

func Policy

func Policy(host string, next http.Handler) http.Handler

Policy applies the host check and browser headers every response needs. The page loads only its own assets; callback queries never leave as referrers.

func RenderLink(origin, flow, subject string) func(context.Context, string, sigil.Secret) (sigil.Mail, error)

RenderLink renders an emailed proof as a fragment link on the origin's landing page, so opening the mail never sends the proof to the server.

func Run

func Run(ctx context.Context, cfg Config) error

Run serves until ctx is done or the server fails.

Types

type Config

type Config struct {
	// Addr is the numeric loopback listen address; Host the DNS name the
	// certificate carries and the browser must use.
	Addr, Host string
	// DSN, Schema and KeyFile select the PostgreSQL schema and the persistent
	// local key; Migrate creates the schema and applies core and plugin migrations.
	DSN, Schema, KeyFile string
	Migrate              bool
	// ReturnURLs are OAuth return destinations beyond Origin + "/".
	ReturnURLs []string
	// Routes registers the example's pages on mux after the API
	// (/api/auth/), the mock provider (/mock-provider/) and the mail preview
	// (POST /dev/mail). It may start helper processes; the returned cleanup,
	// if any, runs at shutdown.
	Routes func(ctx context.Context, h *Host, mux *http.ServeMux) (cleanup func(), err error)
}

Config selects the origin, the database and the example's own routes.

type Host

type Host struct {
	// Origin is the HTTPS origin, for example https://localhost:8443.
	Origin string
	Auth   *sigil.Auth
	// CertificatePEM is the throwaway leaf, for a helper process that must
	// trust exactly this origin.
	CertificatePEM []byte
	Provider       *MockProvider
}

Host is what Routes receives.

type MockProvider

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

MockProvider is a minimal OIDC authorization server for this origin. It approves every authorization request for one fixed subject, enforces the client credentials, single-use codes, the registered callback and S256 PKCE at the token endpoint, and signs RS256 ID tokens. It never represents a real provider; the Google and GitHub adapters have their own tests.

func NewMockProvider

func NewMockProvider(origin string) (*MockProvider, error)

func (*MockProvider) ServeHTTP

func (m *MockProvider) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MockProvider) Spec

func (m *MockProvider) Spec() oauth.Provider

Spec is the provider as the OAuth engine sees it; the callback is /callback/mock on the origin.

Jump to

Keyboard shortcuts

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