Documentation
¶
Overview ¶
Package roles adds a host-defined role hierarchy to Auth-All.
The host names the roles from the lowest to the highest. A check compares the rank of the effective role with the rank of a minimum role, so a route asks for "at least operator" and not for a list of permissions.
r := roles.New(roles.Hierarchy("viewer", "operator", "editor", "admin"),
roles.Default("viewer"))
auth, err := authall.New(authall.WithStore(s), authall.WithPlugins(r))
mux.Handle("/deploy", r.Require("operator", deployHandler))
Index ¶
Constants ¶
const ID = "roles"
ID is the stable plugin identifier.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Plugin)
Option configures the plugin.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is the roles plugin.
func New ¶
New returns the roles plugin. Registration fails when the hierarchy is empty, holds a duplicate, or does not hold the default role.
func (*Plugin) Require ¶
Require protects a handler with a minimum role.
A request with no principal gets 401 UNAUTHORIZED. A principal whose role ranks below min gets 403 INSUFFICIENT_ROLE. Require panics when min is not a configured role, because a route with an unknown minimum can never pass.
func (*Plugin) RequireFunc ¶
RequireFunc is the http.HandlerFunc form of Require.