guardian_backdoor v1.0.0 Guardian.Plug.Backdoor

This plug allows you to bypass authentication in acceptance tests by passing the token needed to load the current resource directly to your Guardian module via a query string parameter.

Installation

Add the following to your Phoenix router before other Guardian plugs.

if Mix.env() == :test do
  plug Guardian.Plug.Backdoor, module: MyApp.Guardian
end
plug Guardian.Plug.VerifySession

NOTE: This plug is designed for acceptance testing and should never be added to a production environment.

Usage

Now that Guardian.Plug.Backdoor is installed, it’s time to sign in.

{:ok, token, _claims} = MyApp.Guardian.encode_and_sign(resource)

conn = get(conn, "/?token=#{token}")

resource = MyApp.Guardian.Plug.current_resource(conn)

When the Guardian.Plug.Backdoor plug runs, it looks up the resource from the token passed in and signs in.

Options

:module - Your app’s Guardian implementation module. Required.