The minimal complete setup: in-memory users, a delegating password encoder (bcrypt-backed, verifies any {id}-tagged hash), and middleware.BasicAuth protecting a couple of routes behind a middleware.Chain.

Full source

Trying it out

There’s no login endpoint — credentials go on every request via the standard Authorization: Basic header (curl -u):

What you get for free

  • X-Content-Type-Options: nosniff, X-Frame-Options: DENY, and the other SecurityHeaders() defaults on every response
  • RFC 7617 HTTP Basic challenge (WWW-Authenticate: Basic) whenever a present-but-invalid Authorization header is rejected
  • 401-vs-403 separation: anonymous requests get 401, authenticated-but- insufficiently-privileged requests get 403
  • A delegating password encoder, so any {id}-tagged hash already in your {bcrypt}... column verifies unchanged