AshAuthentication.Phoenix.Plug (ash_authentication_phoenix v3.0.0-rc.6)

View Source

Helper plugs mixed in to your router.

When you use AshAuthentication.Phoenix.Router this module is included, so that you can use these plugs in your pipelines.

Summary

Functions

Attempt to retrieve actors from the Authorization header(s).

Attempt to retrieve all actors from the connections' session.

Revoke all token(s) in the Authorization header(s).

Revoke all token(s) in the session.

Set the actor from the connection's assigns.

Attempts to sign in the user with the remember me token if the user is not already signed in.

Store the actor in the connections' session.

Functions

load_from_bearer(conn, opts)

@spec load_from_bearer(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

Attempt to retrieve actors from the Authorization header(s).

A wrapper around AshAuthentication.Plug.Helpers.retrieve_from_bearer/2 with the otp_app as extracted from the endpoint.

load_from_session(conn, opts)

@spec load_from_session(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

Attempt to retrieve all actors from the connections' session.

A wrapper around AshAuthentication.Plug.Helpers.retrieve_from_session/2 with the otp_app as extracted from the endpoint.

revoke_bearer_tokens(conn, opts)

@spec revoke_bearer_tokens(Plug.Conn.t(), any()) :: Plug.Conn.t()

Revoke all token(s) in the Authorization header(s).

A wrapper around AshAuthentication.Plug.Helpers.revoke_bearer_tokens/2 with the otp_app as extracted from the endpoint.

revoke_session_tokens(conn, opts)

@spec revoke_session_tokens(Plug.Conn.t(), any()) :: Plug.Conn.t()

Revoke all token(s) in the session.

A wrapper around AshAuthentication.Plug.Helpers.revoke_session_tokens/2 with the otp_app as extracted from the endpoint.

set_actor(conn, subject_name)

@spec set_actor(Plug.Conn.t(), atom()) :: Plug.Conn.t()

Set the actor from the connection's assigns.

This plug takes the user from conn.assigns.current_<subject_name> (set by load_from_session/2) and sets it as the Ash actor via Ash.PlugHelpers.set_actor/2.

This is required for authentication strategies that need to access the current user via Ash.PlugHelpers.get_actor/1.

Example

pipeline :browser do
  plug :load_from_session
  plug :set_actor, :user
end

sign_in_with_remember_me(conn, opts)

@spec sign_in_with_remember_me(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

Attempts to sign in the user with the remember me token if the user is not already signed in.

A wrapper around AshAuthentication.Plug.Helpers.sign_in_with_remember_me/2 with the otp_app as extracted from the endpoint.

store_in_session(conn, actor)

@spec store_in_session(Plug.Conn.t(), Ash.Resource.record()) :: Plug.Conn.t()

Store the actor in the connections' session.