Help us shape the future of Go! Take the 2026 Go Developer Survey

identity

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0, MIT Imports: 8 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). remember carries
	// the sign-in duration request across the second factor, so the
	// session issued after verification keeps the requested lifetime.
	CreatePending(ctx context.Context, userID string, remember bool) (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 Feature,
	sessions APIFeature,
	groups Feature,
	claims Feature,
	passkeys APIFeature,
	devices APIFeature,
	onetime Feature,
	emailv Feature,
	signup Feature,
	apiaccess Feature,
	apikeys Feature,
	recovery APIFeature,
	totp Feature,
) *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) APIAccessRPCService added in v0.0.12

func (m *Module) APIAccessRPCService() (string, http.Handler)

APIAccessRPCService returns the API registry Connect registration, or the not-found stub when the feature is unwired.

func (*Module) APIKeyRPCService added in v0.0.12

func (m *Module) APIKeyRPCService() (string, http.Handler)

APIKeyRPCService returns the API key Connect registration, or the not-found stub when the feature is unwired.

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. Claims and API access serve ConnectRPC exclusively; the REST surfaces left are the user core, sessions, passkeys, device login, and the retained email-link/protocol routes.

func (*Module) AccountRPCService added in v0.0.12

func (m *Module) AccountRPCService() (string, http.Handler)

AccountRPCService returns the self-service account Connect registration.

func (*Module) CustomClaimRPCService added in v0.0.12

func (m *Module) CustomClaimRPCService() (string, http.Handler)

CustomClaimRPCService returns the custom claim Connect registration, or the not-found stub when the feature is unwired.

func (*Module) DeviceApprovalRPCService added in v0.0.12

func (m *Module) DeviceApprovalRPCService() (string, http.Handler)

DeviceApprovalRPCService returns the device approval Connect registration, or the not-found stub when the feature is unwired.

func (*Module) EmailVerificationRPCService added in v0.0.12

func (m *Module) EmailVerificationRPCService() (string, http.Handler)

EmailVerificationRPCService returns the email verification Connect registration; every procedure is self-service.

func (*Module) GroupRPCService added in v0.0.12

func (m *Module) GroupRPCService() (string, http.Handler)

GroupRPCService returns the group Connect registration.

func (*Module) MfaRPCService added in v0.0.12

func (m *Module) MfaRPCService() (string, http.Handler)

MfaRPCService returns the MFA Connect registration; the service mixes the anonymous pending verification with self procedures.

func (*Module) OneTimeAccessRPCService added in v0.0.12

func (m *Module) OneTimeAccessRPCService() (string, http.Handler)

OneTimeAccessRPCService returns the one-time access Connect registration; the admin procedures guard themselves.

func (*Module) SignupRPCService added in v0.0.12

func (m *Module) SignupRPCService() (string, http.Handler)

SignupRPCService returns the signup Connect registration; the composition root authenticates the mount and the service guards its admin procedures per procedure.

func (*Module) UserRPCService added in v0.0.12

func (m *Module) UserRPCService(auth kernel.AccessAuthenticator) (string, http.Handler)

UserRPCService returns the user-core Connect registration.

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 // X-API-KEY machine 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). APIKey is the machine-credential chain: it resolves an X-API-KEY header into a principal for the admin RPC surface and passes requests without the header through to the bearer path.

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