improvement: set context in addition to tenant

This commit is contained in:
Zach Daniel 2024-08-09 09:28:32 -04:00
parent 3562aea431
commit b75097dd3e
4 changed files with 12 additions and 9 deletions

View file

@ -86,11 +86,13 @@ defmodule AshAuthentication.Plug.Helpers do
"jti" => jti, "jti" => jti,
"purpose" => "user" "purpose" => "user"
}, },
tenant: Ash.PlugHelpers.get_tenant(conn) tenant: Ash.PlugHelpers.get_tenant(conn),
context: Ash.PlugHelpers.get_context(conn)
), ),
{:ok, user} <- {:ok, user} <-
AshAuthentication.subject_to_user(subject, resource, AshAuthentication.subject_to_user(subject, resource,
tenant: Ash.PlugHelpers.get_tenant(conn) tenant: Ash.PlugHelpers.get_tenant(conn),
context: Ash.PlugHelpers.get_context(conn)
) do ) do
Conn.assign(conn, current_subject_name, user) Conn.assign(conn, current_subject_name, user)
else else
@ -138,7 +140,8 @@ defmodule AshAuthentication.Plug.Helpers do
validate_token(resource, jti), validate_token(resource, jti),
{:ok, user} <- {:ok, user} <-
AshAuthentication.subject_to_user(subject, resource, AshAuthentication.subject_to_user(subject, resource,
tenant: Ash.PlugHelpers.get_tenant(conn) tenant: Ash.PlugHelpers.get_tenant(conn),
context: Ash.PlugHelpers.get_context(conn)
), ),
{:ok, subject_name} <- Info.authentication_subject_name(resource), {:ok, subject_name} <- Info.authentication_subject_name(resource),
current_subject_name <- current_subject_name(subject_name) do current_subject_name <- current_subject_name(subject_name) do

View file

@ -7,7 +7,7 @@ defmodule AshAuthentication.Strategy.MagicLink.Plug do
alias AshAuthentication.{Info, Strategy, Strategy.MagicLink} alias AshAuthentication.{Info, Strategy, Strategy.MagicLink}
alias Plug.Conn alias Plug.Conn
import Ash.PlugHelpers, only: [get_actor: 1, get_tenant: 1] import Ash.PlugHelpers, only: [get_actor: 1, get_tenant: 1, get_context: 1]
import AshAuthentication.Plug.Helpers, only: [store_authentication_result: 2] import AshAuthentication.Plug.Helpers, only: [store_authentication_result: 2]
@doc """ @doc """
@ -55,7 +55,7 @@ defmodule AshAuthentication.Strategy.MagicLink.Plug do
end end
defp opts(conn) do defp opts(conn) do
[actor: get_actor(conn), tenant: get_tenant(conn)] [actor: get_actor(conn), tenant: get_tenant(conn), context: get_context(conn)]
|> Enum.reject(&is_nil(elem(&1, 1))) |> Enum.reject(&is_nil(elem(&1, 1)))
end end
end end

View file

@ -7,7 +7,7 @@ defmodule AshAuthentication.Strategy.OAuth2.Plug do
alias AshAuthentication.{Errors, Info, Strategy, Strategy.OAuth2} alias AshAuthentication.{Errors, Info, Strategy, Strategy.OAuth2}
alias Assent.{Config, HTTPAdapter.Finch} alias Assent.{Config, HTTPAdapter.Finch}
alias Plug.Conn alias Plug.Conn
import Ash.PlugHelpers, only: [get_actor: 1, get_tenant: 1] import Ash.PlugHelpers, only: [get_actor: 1, get_tenant: 1, get_context: 1]
import AshAuthentication.Plug.Helpers, only: [store_authentication_result: 2] import AshAuthentication.Plug.Helpers, only: [store_authentication_result: 2]
import Plug.Conn import Plug.Conn
@ -74,7 +74,7 @@ defmodule AshAuthentication.Strategy.OAuth2.Plug do
end end
defp action_opts(conn) do defp action_opts(conn) do
[actor: get_actor(conn), tenant: get_tenant(conn)] [actor: get_actor(conn), tenant: get_tenant(conn), get_context(conn)]
|> Enum.reject(&is_nil(elem(&1, 1))) |> Enum.reject(&is_nil(elem(&1, 1)))
end end

View file

@ -7,7 +7,7 @@ defmodule AshAuthentication.Strategy.Password.Plug do
alias AshAuthentication.{Info, Strategy, Strategy.Password} alias AshAuthentication.{Info, Strategy, Strategy.Password}
alias Plug.Conn alias Plug.Conn
import Ash.PlugHelpers, only: [get_actor: 1, get_tenant: 1] import Ash.PlugHelpers, only: [get_actor: 1, get_tenant: 1, get_context: 1]
import AshAuthentication.Plug.Helpers, only: [store_authentication_result: 2] import AshAuthentication.Plug.Helpers, only: [store_authentication_result: 2]
@doc "Handle a registration request" @doc "Handle a registration request"
@ -65,7 +65,7 @@ defmodule AshAuthentication.Strategy.Password.Plug do
end end
defp opts(conn) do defp opts(conn) do
[actor: get_actor(conn), tenant: get_tenant(conn)] [actor: get_actor(conn), tenant: get_tenant(conn), context: get_context(conn)]
|> Enum.reject(&is_nil(elem(&1, 1))) |> Enum.reject(&is_nil(elem(&1, 1)))
end end
end end