Authentication carrying the current security state, an
Authority granted to that principal, and a SecurityContext threaded
through context.Context. Interfaces stand in for annotations, and plain
middleware functions replace filter chains.
Authentication
An authentication (core.Authentication) represents the security state of
a request. It is either:
- Unauthenticated — a request token carrying credentials yet to be verified
(e.g.
*core.UsernamePasswordToken) - Authenticated — a result token with a verified principal and granted
authorities (e.g.
*core.AuthenticatedToken)
core.MustAuthentication panics if no authentication is on the context — use
core.AuthenticationFrom for the optional form:
Authority
An authority (core.Authority) is a string value granted to a principal.
Roles are authorities with the ROLE_ prefix:
HasRole authorization rule auto-prefixes with ROLE_:
The Security Context
The authentication lives oncontext.Context, scoped to the request:
Authentication Flow
Manager and Providers
authn.Manager fans out to a list of authn.Provider implementations.
Each provider handles one kind of credential:
Supports(token) == true — first-supporting-provider-wins dispatch.
User
authn.User is the UserDetails equivalent:
User.Check() returns the first account-status error (core.ErrAccountDisabled,
core.ErrAccountLocked, etc.) or nil when the account is usable.
Sentinel Errors
All authentication failures wrap a sentinel fromcore:
Match them with
errors.Is:
