cassette_plug v1.1.6 Cassette.Plug.AuthenticationHandler behaviour View Source

Behaviour and macro module to define callbacks for the authentication handlers the plug uses.

Most of this works out-of-the-box, but it might be interesting to override Cassette.Plug.AuthenticationHandler.invalid_authentication/2 and present a more friendy error page


defmodule MyErrorHandler do
  use Cassette.Plug.AuthenticationHandler

  def invalid_authentication(conn, _options) do
    render(conn, "error")
  end
end

And while plugging in your router:


plug Cassette.Plug, handler: MyErrorHandler

Check Cassette.Plug.DefaultHandler for the default behaviour.

Link to this section Summary

Functions

Returns the default implementation for this behaviour

Callbacks

Initializes this handler with the given options

Called when authentication is provided but fails (i.e., ticket is no longer valid or is invalid)

Called to compute the service that must be authenticated against

Called when there is no authentication in the request (i.e., no ticket in the query string)

Called when successfully authenticated the user on conn

Called to extract the current authenticated user and/or the authentication token from conn

Link to this section Types

Link to this section Functions

Returns the default implementation for this behaviour

Link to this section Callbacks

Link to this callback init(args) View Source
init(args :: term()) :: term()

Initializes this handler with the given options.

They will be forwarded to the other functions.

Link to this callback invalid_authentication(conn, options) View Source
invalid_authentication(conn :: Plug.Conn.t(), options :: term()) :: Plug.Conn.t()

Called when authentication is provided but fails (i.e., ticket is no longer valid or is invalid).

This might be your Forbidden page.

Link to this callback service(conn, options) View Source
service(conn :: Plug.Conn.t(), options :: term()) :: String.t()

Called to compute the service that must be authenticated against.

Usually this is the URL of the page the user is trying to access and may be computed using values in conn

Link to this callback unauthenticated(conn, options) View Source
unauthenticated(conn :: Plug.Conn.t(), options :: term()) :: Plug.Conn.t()

Called when there is no authentication in the request (i.e., no ticket in the query string).

The usual implementation is to redirect to CAS.

Link to this callback user_authenticated(conn, user, options) View Source
user_authenticated(conn :: Plug.Conn.t(), user :: Cassette.User.t(), options :: term()) :: Plug.Conn.t()

Called when successfully authenticated the user on conn

Link to this callback user_or_token(conn, options) View Source
user_or_token(conn :: Plug.Conn.t(), options :: term()) :: {Cassette.User.t() | nil, {:ok, String.t()} | :error}

Called to extract the current authenticated user and/or the authentication token from conn