auth

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTenantNotResolved = errors.New("approval: cannot resolve caller tenant from principal")

ErrTenantNotResolved indicates the resolver received a principal whose Details shape doesn't expose a tenant_id / tenantId / TenantID key. The resource layer surfaces this as an authentication failure so a misconfigured host can't accidentally serve cross-tenant data through a zero-value CallerContext.

Module provides identity-resolution defaults (tenant resolver, instance globals resolver). Hosts override a resolver via fx.Replace — the tenant resolver when their principal carries tenant info in a typed struct instead of a generic map, the globals resolver when their flows route on host-defined global variables.

Functions

func NewDefaultInstanceGlobalsResolver added in v0.35.0

func NewDefaultInstanceGlobalsResolver() approval.InstanceGlobalsResolver

NewDefaultInstanceGlobalsResolver constructs the default resolver.

func NewDefaultPrincipalTenantResolver

func NewDefaultPrincipalTenantResolver() approval.PrincipalTenantResolver

NewDefaultPrincipalTenantResolver constructs the default resolver.

Types

type DefaultInstanceGlobalsResolver added in v0.35.0

type DefaultInstanceGlobalsResolver struct{}

DefaultInstanceGlobalsResolver resolves no globals: flows route on form data and the built-in applicant subjects only. Hosts whose flows reference global variables (tenant attributes, applicant roles, business limits, …) replace it via fx.Replace with a resolver that derives them server-side from their own principal / business context.

func (*DefaultInstanceGlobalsResolver) Resolve added in v0.35.0

Resolve returns no globals.

type DefaultPrincipalTenantResolver

type DefaultPrincipalTenantResolver struct{}

DefaultPrincipalTenantResolver extracts the tenant id from Principal.Details. It handles two common shapes:

  • map[string]any (JWT claims deserialized without a typed model) — looks up the candidate keys in order.
  • typed struct or pointer to struct — looks up the candidate field names in order via reflection.

Anonymous and system principals (Details == nil) are explicitly recognized: they return an empty tenant without an error so the resource layer can treat them as needing an explicit fallback (e.g. the system caller marker). Authenticated principals whose Details does not expose a tenant return ErrTenantNotResolved — fail-closed.

func (*DefaultPrincipalTenantResolver) Resolve

Resolve probes Principal.Details for the first non-empty tenant field. See type docstring for the resolution policy.

Jump to

Keyboard shortcuts

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