mirror of
https://github.com/team-alembic/ash_authentication.git
synced 2024-09-20 05:13:10 +12:00
1c8f138c67
Highlights: * Replaced `AshAuthentication.Provider` with the much more flexible `AshAuthentication.Strategy`. * Moved strategies to within the `authentication` DSL using entities and removed excess extensions. * Added a lot more documentation and test coverage.
28 lines
856 B
Elixir
28 lines
856 B
Elixir
defmodule AshAuthentication.SecretFunction do
|
|
@moduledoc """
|
|
Implements `AshAuthentication.Secret` for functions that are provided to the
|
|
DSL instead of modules.
|
|
"""
|
|
|
|
use AshAuthentication.Secret
|
|
alias Ash.Resource
|
|
|
|
@doc false
|
|
@impl true
|
|
@spec secret_for(secret_name :: [atom], Resource.t(), keyword) :: {:ok, String.t()} | :error
|
|
def secret_for(secret_name, resource, opts) do
|
|
case Keyword.pop(opts, :fun) do
|
|
{fun, _opts} when is_function(fun, 2) ->
|
|
fun.(secret_name, resource)
|
|
|
|
{fun, opts} when is_function(fun, 3) ->
|
|
fun.(secret_name, resource, opts)
|
|
|
|
{{m, f, a}, _opts} when is_atom(m) and is_atom(f) and is_list(a) ->
|
|
apply(m, f, [secret_name, resource | a])
|
|
|
|
{nil, opts} ->
|
|
raise "Invalid options given to `secret_for/3` callback: `#{inspect(opts)}`."
|
|
end
|
|
end
|
|
end
|