cassette_plug v1.1.0 Cassette.Plug.AuthenticationHandler behaviour
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.
Summary
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
Functions
Callbacks
Specs
init(args :: term) :: term
Initializes this handler with the given options.
They will be forwarded to the other functions.
Specs
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.
Specs
service(conn :: Plug.Conn.t, options :: term) :: Plug.Conn.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
Specs
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.
Specs
user_authenticated(conn :: Plug.Conn.t, user :: Cassette.User.t, options :: term) :: Plug.Conn.t
Called when successfully authenticated the user on conn
Specs
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