webauth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webauth implements OIDC web login (authorization code + PKCE) and DB-backed sessions.

Index

Constants

View Source
const CookieName = "__Host-braid_session"

CookieName is the session cookie.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

Auth serves the /auth/* routes and the session middleware.

func New

func New(ctx context.Context, cfg config.Config, d *db.DB, now func() time.Time) (*Auth, error)

New runs OIDC discovery.

func (*Auth) Check

func (a *Auth) Check(r *http.Request) (Principal, bool, error)

Check validates the session cookie without side effects (no sliding expiry); see lookup for ok and err.

func (*Auth) Register

func (a *Auth) Register(mux *http.ServeMux)

Register mounts /auth/login, /auth/callback and /auth/logout.

func (*Auth) Require

func (a *Auth) Require(next http.Handler) http.Handler

Require authenticates the request or answers 401 (API) / redirects to login.

func (*Auth) RequireAdmin

func (a *Auth) RequireAdmin(next http.Handler) http.Handler

RequireAdmin must be used behind Require.

type Principal

type Principal struct {
	UserID  string
	IsAdmin bool
}

Principal is the authenticated web user.

func PrincipalFrom

func PrincipalFrom(ctx context.Context) (Principal, bool)

PrincipalFrom returns the principal set by Require.

Directories

Path Synopsis
Package oidctest is a minimal in-process OIDC provider for tests.
Package oidctest is a minimal in-process OIDC provider for tests.

Jump to

Keyboard shortcuts

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