Documentation
¶
Overview ¶
Package security defines transport-independent, typed authentication and authorization contracts. Applications own credentials, identities, principals, resources and the meaning of their fields. Implementations shared through DI must be safe for concurrent use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Current ¶
Current retrieves P or returns ErrUnauthenticated. A different type, nil context, or a masked/absent principal never causes a type assertion panic. A zero-valued P deliberately published by WithPrincipal is still present.
func WithPrincipal ¶
WithPrincipal propagates a trusted principal. Only authentication boundaries or trusted application code should call it. P must be the same instantiated type used by Current. Principals (including slices/maps/pointers) must be treated as immutable after publication; no copy or validation is performed.
func WithoutPrincipal ¶
WithoutPrincipal masks an upstream principal of P while preserving other context values and cancellation. Anonymous authentication uses this to avoid accidentally retaining an upstream identity of the same type.
Types ¶
type Authenticator ¶
Authenticator verifies credentials before producing an identity. Credential rejection should wrap ErrInvalidCredentials; infrastructure errors must remain distinguishable. I carries only data from the verified identity source.
type Authorizer ¶
Authorizer evaluates an action on a typed resource for an explicit principal. Policies should deny unsupported actions with ErrForbidden. Operational errors must not be converted into access denials.
type PrincipalResolver ¶
PrincipalResolver builds an application principal from a verified identity. It may load application data or use the identity directly. A principal is accepted only on a nil error; its shape and validity belong to the application.