identity

package
v0.0.11 Latest Latest
Warning

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

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

Documentation

Overview

Package identity owns internal authn/authz: user accounts plus the features wired at the composition root. The provider surface for other systems lives in modules/federation.

Package identity owns internal authn/authz: user accounts plus the selectable features wired at the composition root. The provider surface for other systems lives in modules/federation.

Index

Constants

View Source
const PendingCookieName = "tango_mfa_pending"

PendingCookieName is the browser cookie carrying the pending-auth token; the raw value lives only in the cookie.

View Source
const PendingCookieTTL = 5 * time.Minute

PendingCookieTTL bounds the pending-auth cookie and row.

Variables

This section is empty.

Functions

func NewID

func NewID[T typeid.Subtype, PT typeid.SubtypePtr[T]]() T

NewID generates a UUIDv7-backed typed ID. Panics only on an invalid prefix, impossible for the prefixes declared in feature packages.

func ParseID

func ParseID[T typeid.Subtype, PT typeid.SubtypePtr[T]](s string) (T, error)

ParseID decodes a typed ID string, rejecting prefix mismatches.

Types

type APIFeature

type APIFeature interface {
	Feature
	APIRoutes(r chi.Router, g RouteGroups)
}

APIFeature mounts endpoints inside the shared /api group.

type AuditEvent

type AuditEvent struct {
	Action string
	Actor  string
	Target string
}

type Feature

type Feature interface {
	Name() string
}

Feature is one mounted unit inside the identity surface: a feature left out of New has no routes.

type MFAPendingIssuer

type MFAPendingIssuer interface {
	// RequiresPending reports whether the account must pass the
	// second factor before a full session.
	RequiresPending(ctx context.Context, userID string) (bool, error)
	// CreatePending mints the short-lived pending bridge and returns
	// its raw token (for the pending cookie only).
	CreatePending(ctx context.Context, userID string) (string, error)
	// ClearPending drops the bridge (sign-out).
	ClearPending(ctx context.Context, userID string) error
}

MFAPendingIssuer is the identity-owned second-factor port between sign-in and full session issuance: a confirmed enrollment turns a successful password sign-in into a pending authentication that only the MFA verification endpoint can upgrade. The user ID is the TypeID wire form.

type MailSender

type MailSender interface {
	EnqueueEmail(ctx context.Context, msg mailer.Message) error
}

MailSender queues transactional email. Implemented by internal/jobs; declared here so identity features stay free of the job package.

type Module

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

Module is the identity surface: the user core plus each explicitly wired feature, mounted in construction order. There is no feature discovery or late registration.

func New

func New(
	core APIFeature,
	account APIFeature,
	sessions APIFeature,
	groups APIFeature,
	claims APIFeature,
	passkeys APIFeature,
	devices APIFeature,
	onetime APIFeature,
	emailv APIFeature,
	signup APIFeature,
	apiaccess APIFeature,
	apikeys APIFeature,
	recovery APIFeature,
	totp APIFeature,
) *Module

New wires the identity surface. The user core is mandatory; a nil one is a wiring bug. Any other feature left out (nil) simply has no routes.

func (*Module) APIRoutes

func (m *Module) APIRoutes(r chi.Router, g RouteGroups)

APIRoutes mounts the user core, then every wired feature's endpoints, in construction order. Unwired features stay unmounted.

type Recorder

type Recorder interface {
	Record(ctx context.Context, event AuditEvent, exec datastore.Executor)
}

Recorder receives audit events. A nil exec writes the audit row standalone (best effort); a non-nil exec joins the caller's transaction so the entry commits or rolls back with the domain write — the durable outbox boundary.

type RouteGroups

type RouteGroups struct {
	Admin  kernel.Guard // session auth + admin requirement
	Self   kernel.Guard // session auth (cookie)
	APIKey kernel.Guard // API-key auth
}

RouteGroups carries the authentication middleware chains a feature applies at mount time; the composition root builds each chain once. A nil group leaves its guarded routes unmounted (fail closed).

Directories

Path Synopsis
Package account covers profile management, credential lifecycle, and account state.
Package account covers profile management, credential lifecycle, and account state.
Package devicelogin implements the QR / cross-device sign-in flow: an anonymous device parks a short-lived request keyed by a short user code; a signed-in user approves or denies it; the waiting device long-polls the exchange until approved.
Package devicelogin implements the QR / cross-device sign-in flow: an anonymous device parks a short-lived request keyed by a short user code; a signed-in user approves or denies it; the waiting device long-polls the exchange until approved.
Package emailverification verifies a user's email address via a single-use token (auth_tokens, purpose = email_verification).
Package emailverification verifies a user's email address via a single-use token (auth_tokens, purpose = email_verification).
Package onetimeaccess issues single-use sign-in tokens delivered by email: admins mint them per user; unauthenticated users may request one for their own address when the app policy allows.
Package onetimeaccess issues single-use sign-in tokens delivered by email: admins mint them per user; unauthenticated users may request one for their own address when the app policy allows.
Package password owns credential hashing and verification: one argon2id/scrypt hash per user (PHC format via pkg/crypto), plus the identity lookup used by the sign-in flow.
Package password owns credential hashing and verification: one argon2id/scrypt hash per user (PHC format via pkg/crypto), plus the identity lookup used by the sign-in flow.
Package session manages sign-in sessions: issue (cookie-backed opaque tokens), validate (sliding expiry), list, and revoke.
Package session manages sign-in sessions: issue (cookie-backed opaque tokens), validate (sliding expiry), list, and revoke.
Package signup implements application-based self-service sign-up flows (create + approve) with rate-limited endpoints.
Package signup implements application-based self-service sign-up flows (create + approve) with rate-limited endpoints.
Package token owns the shared one-shot token store (public.auth_tokens): rows keyed by (user_id, purpose), SHA-256 hash at rest, single-use consumption with an expiry check.
Package token owns the shared one-shot token store (public.auth_tokens): rows keyed by (user_id, purpose), SHA-256 hash at rest, single-use consumption with an expiry check.
Package user is the mandatory accounts core: user entities, their CRUD surface, and persistence.
Package user is the mandatory accounts core: user entities, their CRUD surface, and persistence.
Package usergroup groups users so OIDC client access can be granted in bulk.
Package usergroup groups users so OIDC client access can be granted in bulk.
Package webauthn implements passkey sign-in: registration and assertion ceremonies via go-webauthn, credential storage, and the admin credential CRUD.
Package webauthn implements passkey sign-in: registration and assertion ceremonies via go-webauthn, credential storage, and the admin credential CRUD.

Jump to

Keyboard shortcuts

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