Documentation
¶
Overview ¶
Package guard provides Celerity's authorisation model.
A guard is a layer that returns a decision rather than a result, so a denial is a 401 or a 403 the framework writes rather than an error every handler has to remember to shape the same way.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Decision ¶
type Decision struct {
// Allowed reports whether the event may reach the handler.
Allowed bool
// Reason is reported to the caller when the event is refused, and should say
// what is missing without saying what would satisfy it.
Reason string
// Identity is the authenticated principal, reached from a handler through
// [IdentityFrom]. Nil when the guard authorises without identifying.
Identity any
// Claims are the verified token claims, when the guard verified a token.
Claims map[string]any
}
Decision is a guard's answer.
type Guard ¶
Guard decides whether an event may reach its handler.
Returning an error means the decision could not be made, which is a 500, as distinct from a decision to refuse, which is a 401 or 403.
type Request ¶
type Request struct {
Kind handler.Kind
Method string
Route string
Headers handler.Params
Query handler.Params
// ConnectionID is set for WebSocket events.
ConnectionID string
SourceIP string
RequestID string
}
Request is what a guard decides about.
It carries the parts of an event that authorisation is decided from, so one guard can protect handlers of different kinds.
Click to show internal directories.
Click to hide internal directories.