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
- func Certificate(host string) (tls.Certificate, []byte, error)
- func LocalKey(path string) ([]byte, error)
- func MailPreview(origin string, delivery *sigil.MailDelivery, sink *sigil.LocalMailSink) http.HandlerFunc
- func Origin(host, addr string) (string, error)
- func Policy(host string, next http.Handler) http.Handler
- func RenderLink(origin, flow, subject string) func(context.Context, string, sigil.Secret) (sigil.Mail, error)
- func Run(ctx context.Context, cfg Config) error
- type Config
- type Host
- type MockProvider
Constants ¶
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 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 Policy ¶
Policy applies the host check and browser headers every response needs. The page loads only its own assets; callback queries never leave as referrers.
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.