hooks

command
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 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.

README

hooks

Wires every Config.LifecycleHooks callback to a log line so you can see when each one fires. Password sign-in with a TOTP second factor, in memory.

Run

go run ./examples/hooks

Then drive the API (a cookie jar keeps the session):

curl -c jar -s -XPOST localhost:8080/auth/signup -d '{"email":"a@example.com","password":"twelve-chars-min"}'   # OnSignup
curl -c jar -s -XPOST localhost:8080/auth/signin -d '{"email":"a@example.com","password":"twelve-chars-min"}'   # OnSignin

TOTP enrollment (/auth/totp/enroll/*) fires OnMFAEnabled, and a sign-in held for a second factor fires OnSignin when /auth/totp/verify succeeds.

Notes

  • Hooks run after the action committed, so they are observe-only. A returned error or a panic is logged, passed to OnHookError, and does not fail the request.
  • To refuse a signup or sign-in before it happens, gate it ahead of the library (wrap the route, or check the address first).
  • OnTokenIssued is the one hook that can fail a request, because the token is not yet minted. It is set on the same LifecycleHooks struct and only matters when the authorization server is enabled.

ENCRYPTION_KEY (32 bytes) protects TOTP secrets at rest; the default is for local use only. See docs/hooks.md.

Documentation

Overview

hooks is a runnable demo of Config.LifecycleHooks. It mounts the full /auth/* route set with TOTP enabled and wires every observe-only hook to a structured log line.

POST /auth/signup -> OnSignup(password), OnSignin is not fired POST /auth/signin -> OnSignin POST /auth/totp/enroll/* -> OnMFAEnabled(totp) when enrollment is confirmed POST /auth/totp/verify -> OnSignin (the second factor completes the sign-in)

Passkey login, SAML, magic link and OAuth callback fire OnSignin the same way. Hooks run after the action committed, so they cannot veto it. A returned error is logged and reported to OnHookError, and the request still succeeds. Use OnHookError to alert instead of only logging.

Jump to

Keyboard shortcuts

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