gate

package
v0.71.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package gate builds ContentKit's route gates from the host's auth. It asks the auth.Authenticator who a request is, at most once, builds the access.Actor from the Verified, enforces the route's tier (httpapi.Tier) and answers every refusal with the status and challenge helpers/auth's Refuse gives, in ContentKit's error body.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Actor

func Actor(ctx context.Context) access.Actor

Actor is the actor the gate bound to ctx; anonymous when none was.

func Can

func Can(ctx context.Context, a auth.Authenticator, actor access.Actor, perm string) (bool, error)

Can reports whether actor holds perm, an access.Permission's name, as staff: the root:<resource>:<action> permission in the Authenticator's root scope. It is the one place a staff permission is checked; a tenant that corresponded to a group would also admit that group's merchant: form here. An error never grants.

func Check

func Check(a auth.Authenticator, perms ...access.Permission) error

Check refuses a missing Authenticator, typed nil pointers included. A module with staff routes passes their permissions: the Authenticator must name its root scope (auth.Root), where they are held, and know each one when it can say (auth.PermissionCatalog), so a host whose roles lack one fails at start instead of refusing every request.

func RootScope

func RootScope(ctx context.Context, a auth.Authenticator) (s auth.Scope, err error)

RootScope is where a's root permissions are held, asked per check. An Authenticator without auth.Root, an error or a zero scope is unresolved: an error matching auth.ErrUnavailable, which never grants.

Types

type Gate

type Gate struct {
	Auth auth.Authenticator
	// Then wraps each route inside the gate, after the actor is bound.
	Then func(http.Handler) http.Handler
	Log  *slog.Logger
}

Gate guards one module's routes.

func (*Gate) Guard

func (g *Gate) Guard(s httpapi.Spec, next http.Handler) http.Handler

Guard is an httpapi.Guard: it binds the request's actor and admits it by s's tier before next serves it.

Jump to

Keyboard shortcuts

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