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

Define your own custom authentication strategy.

See [the Custom Strategies guide](/documentation/topics/custom-strategy.md)
for more information.

# `entity`

```elixir
@type entity() :: Spark.Dsl.Entity.t()
```

A Strategy DSL Entity.

See `Spark.Dsl.Entity` for more information.

# `strategy`

```elixir
@type strategy() :: %{
  :__struct__ =&gt; module(),
  :resource =&gt; module(),
  optional(:strategy_module) =&gt; module(),
  optional(atom()) =&gt; any()
}
```

This is the DSL target for your entity and the struct for which you will
implement the `AshAuthentication.Strategy` protocol.

The only required field is `resource` which will contain the resource module
that the strategy has been added to.

Optionally, you can include a `strategy_module` field if you're reusing
another strategy's entity, and thus the `__struct__` key can't be used to
introspect the location of the `transform/2` and `verify/2` callbacks.

# `transform`

```elixir
@callback transform(strategy(), Spark.Dsl.t()) ::
  {:ok, strategy()} | {:ok, Spark.Dsl.t()} | {:error, Exception.t()}
```

If your strategy needs to modify either the entity or the parent resource then
you can implement this callback.

This callback can return one of three results:

  - `{:ok, Entity.t}` - an updated DSL entity - useful if you're just changing
    the entity itself and not changing the wider DSL state of the resource.
    If this is the response then the transformer will take care of updating
    the entity in the DSL state.
  - `{:ok, Dsl.t}` - an updated DSL state for the entire resource.
  - `{:error, Exception.t}` - a compilation-stopping problem was found. Any
    exception can be returned, but we strongly advise you to return a
    `Spark.Error.DslError`.

# `verify`

```elixir
@callback verify(strategy(), Spark.Dsl.t()) :: :ok | {:error, Exception.t()}
```

If your strategy needs to verify either the entity or the parent resource then
you can implement this callback.

This is called post-compilation in the `@after_verify` hook - see `Module` for
more information.

This callback can return one of the following results:

  - `:ok` - everything is A-Okay.
  - `{:error, Exception.t}` - a compilation-stopping problem was found. Any
    exception can be returned, but we strongly advise you to return a
    `Spark.Error.DslError`.

# `set_defaults`

Sets default values for a DSL schema based on a set of defaults.

If a given default is in the schema, it can be overriden, so we just set the default
and mark it not required.

If not, then we add it to `auto_set_fields`, and the user cannot override it.

---

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