View Source AshAuthentication.Strategy protocol (ash_authentication v4.3.2)
The protocol used for interacting with authentication strategies.
Any new Authentication strategy must implement this protocol.
Summary
Types
The name of an individual action supported by the strategy.
A path to match in web requests
The "phase" of the request.
An individual route.
All the types that implement this protocol.
Functions
Perform an named action.
Return a list of actions supported by the strategy.
Return the HTTP method for a phase.
The "short name" of the strategy, used for genererating routes, etc.
Return a list of phases supported by the strategy.
Handle requests routed to the strategy.
Used to build the routing table to route web requests to request phases for each strategy.
Indicates that the strategy creates or consumes tokens.
Types
@type action() :: atom()
The name of an individual action supported by the strategy.
This maybe not be the action name on the underlying resource, which may be generated, but the name that the strategy itself calls the action.
@type http_method() ::
:get | :head | :post | :put | :delete | :connect | :options | :trace | :patch
@type path() :: String.t()
A path to match in web requests
@type phase() :: atom()
The "phase" of the request.
Usually :request
or :callback
but can be any atom.
An individual route.
Eg: {"/user/password/sign_in", :sign_in}
@type t() :: term()
All the types that implement this protocol.
Functions
@spec action(t(), action(), params :: map(), options :: keyword()) :: :ok | {:ok, Ash.Resource.record()} | {:error, any()}
Perform an named action.
Different strategies are likely to implement a number of different actions depending on their configuration. Calling them via this function will ensure that the context is correctly set, etc.
See actions/1
for a list of actions provided by the strategy.
Any options passed to the action will be passed to the underlying Ash.Domain
function.
Return a list of actions supported by the strategy.
Example
iex> strategy = Info.strategy!(Example.User, :password)
...> actions(strategy)
[:sign_in_with_token, :register, :sign_in, :reset_request, :reset]
@spec method_for_phase(t(), phase()) :: http_method()
Return the HTTP method for a phase.
Example
iex> strategy = Info.strategy!(Example.User, :oauth2)
...> method_for_phase(strategy, :request)
:get
The "short name" of the strategy, used for genererating routes, etc.
This is most likely the same value that you use for the entity's name
argument.
Return a list of phases supported by the strategy.
Example
iex> strategy = Info.strategy!(Example.User, :password)
...> phases(strategy)
[:sign_in_with_token, :register, :sign_in, :reset_request, :reset]
@spec plug(t(), phase(), Plug.Conn.t()) :: Plug.Conn.t()
Handle requests routed to the strategy.
Each phase will be an atom (ie the second element in the route tuple).
See phases/1
for a list of phases supported by the strategy.
Used to build the routing table to route web requests to request phases for each strategy.
Example
iex> strategy = Info.strategy!(Example.User, :password)
...> routes(strategy)
[
{"/user/password/sign_in_with_token", :sign_in_with_token},
{"/user/password/register", :register},
{"/user/password/sign_in", :sign_in},
{"/user/password/reset_request", :reset_request},
{"/user/password/reset", :reset}
]
Indicates that the strategy creates or consumes tokens.