Bodyguard v2.1.2 Bodyguard.Plug.Authorize

Perform authorization in a Plug pipeline.

Options

  • policy required - the policy (or context) module
  • action required - the action to authorize
  • user - a 1-arity function which accepts the connection and returns a user. If omitted, defaults user to nil
  • params - params to pass to the authorization callbacks
  • fallback - a fallback controller or plug to handle authorization failure. If specified, the plug is called and then the pipeline is halted. If not specified, then Bodyguard.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

Functions

call(conn, opts)

Callback implementation for Plug.call/2.

init(opts \\ [])

Callback implementation for Plug.init/1.