Bodyguard v2.0.0 Bodyguard.Plug.Authorize
Perform authorization in a Plug pipeline.
Options
policy
required - the policy (or context) moduleaction
required - the action to authorizeuser
- a 1-arity function which accepts the connection and returns a user. If omitted, detaultsuser
tonil
params
- params to pass to the authorization callbacksfallback
- a fallback controller or plug to handle authorization failure. If specified, the plug is called and then the pipeline ishalt
ed. If not specified, thenBodyguard.NotAuthorizedError
raises directly to the router.
Examples
# Raise on failure
plug Bodyguard.Plug.Authorize, policy: MyApp.Blog, action: :update_posts,
user: &get_current_user/1
# Fallback on failure
plug Bodyguard.Plug.Authorize, policy: MyApp.Blog, action: :update_posts,
user: &get_current_user/1, fallback: MyApp.FallbackController
Summary
Functions
Callback implementation for Plug.call/2
.
Callback implementation for Plug.init/1
.