pass v0.3.0 Pass.Plugs

The Pass.Plugs module is meant to be imported into a Phoenix Router module so that its methods can be used as plugs in the router’s pipelines.

Example

defmodule MyApp.Router do
  use MyApp.Web, :router
  import Pass.Plugs

  pipeline :browser do
    plug :fetch_session

    # Pass.Plugs function
    plug :authenticate_session
  end

  pipeline ::require_auth do
    # Pass.Plugs function
    plug :require_authentication, redirect_to: "/login"
  end
end

Summary

Functions

Extends a valid authentication session or clears that data

Ensures the current session is valid. If not, returns a 401 or redirects to the path specfied to by the :redirect_to option

Functions

authenticate_session(conn, ops)

Extends a valid authentication session or clears that data.

require_authentication(conn, opts)

Ensures the current session is valid. If not, returns a 401 or redirects to the path specfied to by the :redirect_to option.

If the session is valid, the current user will be retrieved and stored in the connection struct. If this is not desirable, the :skip_user_lookup option can be set to true. BE CAREFUL when doing this as then it doesn’t ensure that the user hasn’t been deleted