diff --git a/documentation/dsls/DSL:-AshAuthentication.md b/documentation/dsls/DSL:-AshAuthentication.md index e16ecb7..4dda71e 100644 --- a/documentation/dsls/DSL:-AshAuthentication.md +++ b/documentation/dsls/DSL:-AshAuthentication.md @@ -68,6 +68,18 @@ Currently supported strategies: 3. `AshAuthentication.Strategy.MagicLink` - authenticate by sending a single-use link to the user. +### HTTP client settings + +Most of the authentication strategies based on `OAuth2` wrap the [`assent`](https://hex.pm/packages/assent) package. + +If you needs to customize the behavior of the http client used by `assent`, define a custom `http_adapter` in the +application settings: + +`config :ash_authentication, :http_adapter, {Assent.HTTPAdapter.Finch, supervisor: MyApp.CustomFinch}` + +See [`assent's documentation`](https://hexdocs.pm/assent/README.html#http-client) for more details on the supported +http clients and their configuration. + ## Add-ons Add-ons are like strategies, except that they don't actually provide diff --git a/lib/ash_authentication/plug/helpers.ex b/lib/ash_authentication/plug/helpers.ex index c317407..2bc0fdf 100644 --- a/lib/ash_authentication/plug/helpers.ex +++ b/lib/ash_authentication/plug/helpers.ex @@ -87,12 +87,12 @@ defmodule AshAuthentication.Plug.Helpers do "purpose" => "user" }, tenant: Ash.PlugHelpers.get_tenant(conn), - context: Ash.PlugHelpers.get_context(conn) + context: Ash.PlugHelpers.get_context(conn) || %{} ), {:ok, user} <- AshAuthentication.subject_to_user(subject, resource, tenant: Ash.PlugHelpers.get_tenant(conn), - context: Ash.PlugHelpers.get_context(conn) + context: Ash.PlugHelpers.get_context(conn) || %{} ) do Conn.assign(conn, current_subject_name, user) else @@ -141,7 +141,7 @@ defmodule AshAuthentication.Plug.Helpers do {:ok, user} <- AshAuthentication.subject_to_user(subject, resource, tenant: Ash.PlugHelpers.get_tenant(conn), - context: Ash.PlugHelpers.get_context(conn) + context: Ash.PlugHelpers.get_context(conn) || %{} ), {:ok, subject_name} <- Info.authentication_subject_name(resource), current_subject_name <- current_subject_name(subject_name) do diff --git a/lib/ash_authentication/strategies/magic_link/plug.ex b/lib/ash_authentication/strategies/magic_link/plug.ex index 011a83d..32c11fb 100644 --- a/lib/ash_authentication/strategies/magic_link/plug.ex +++ b/lib/ash_authentication/strategies/magic_link/plug.ex @@ -55,7 +55,7 @@ defmodule AshAuthentication.Strategy.MagicLink.Plug do end defp opts(conn) do - [actor: get_actor(conn), tenant: get_tenant(conn), context: get_context(conn)] + [actor: get_actor(conn), tenant: get_tenant(conn), context: get_context(conn) || %{}] |> Enum.reject(&is_nil(elem(&1, 1))) end end diff --git a/lib/ash_authentication/strategies/oauth2/plug.ex b/lib/ash_authentication/strategies/oauth2/plug.ex index 71320a2..a74770e 100644 --- a/lib/ash_authentication/strategies/oauth2/plug.ex +++ b/lib/ash_authentication/strategies/oauth2/plug.ex @@ -74,7 +74,7 @@ defmodule AshAuthentication.Strategy.OAuth2.Plug do end defp action_opts(conn) do - [actor: get_actor(conn), tenant: get_tenant(conn), get_context(conn)] + [actor: get_actor(conn), tenant: get_tenant(conn), context: get_context(conn) || %{}] |> Enum.reject(&is_nil(elem(&1, 1))) end diff --git a/test/ash_authentication/token_resource/actions_test.exs b/test/ash_authentication/token_resource/actions_test.exs index 869ae39..3c2265a 100644 --- a/test/ash_authentication/token_resource/actions_test.exs +++ b/test/ash_authentication/token_resource/actions_test.exs @@ -46,7 +46,7 @@ defmodule AshAuthentication.TokenResource.ActionsTest do DateTime.utc_now() |> DateTime.to_unix() - 10..1 + 10..1//-1 |> Enum.each(fn i -> {:ok, token, _} = Jwt.token_for_user(user, %{"exp" => now - i}) :ok = Actions.revoke(Example.Token, token)