# `AshAuthentication.Strategy`
[🔗](https://github.com/team-alembic/ash_authentication/blob/main/lib/ash_authentication/strategy.ex#L5)

The protocol used for interacting with authentication strategies.

Any new Authentication strategy must implement this protocol.

# `action`

```elixir
@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.

# `http_method`

```elixir
@type http_method() ::
  :get | :head | :post | :put | :delete | :connect | :options | :trace | :patch
```

# `path`

```elixir
@type path() :: String.t()
```

A path to match in web requests

# `phase`

```elixir
@type phase() :: atom()
```

The "phase" of the request.

Usually `:request` or `:callback` but can be any atom.

# `route`

```elixir
@type route() :: {path(), phase()}
```

An individual route.

Eg: `{"/user/password/sign_in", :sign_in}`

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `action`

```elixir
@spec action(t(), action(), params :: map(), options :: keyword()) ::
  :ok | {:ok, Ash.Resource.record()} | {:ok, boolean()} | {: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.

# `actions`

```elixir
@spec actions(t()) :: [action()]
```

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]

# `method_for_phase`

```elixir
@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

# `name`

```elixir
@spec name(t()) :: atom()
```

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.

# `phases`

```elixir
@spec phases(t()) :: [phase()]
```

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]

# `plug`

```elixir
@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.

# `routes`

```elixir
@spec routes(t()) :: [route()]
```

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}
    ]

# `tokens_required?`

```elixir
@spec tokens_required?(t()) :: boolean()
```

Indicates that the strategy creates or consumes tokens.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
