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,
"purpose" => "user"
},
tenant: Ash.PlugHelpers.get_tenant(conn)
tenant: Ash.PlugHelpers.get_tenant(conn),
context: Ash.PlugHelpers.get_context(conn)
),
{:ok, user} <-
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
Conn.assign(conn, current_subject_name, user)
else
@ -138,7 +140,8 @@ defmodule AshAuthentication.Plug.Helpers do
validate_token(resource, jti),
{:ok, user} <-
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),
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 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]
@doc """
@ -55,7 +55,7 @@ defmodule AshAuthentication.Strategy.MagicLink.Plug do
end
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)))
end
end

View file

@ -7,7 +7,7 @@ defmodule AshAuthentication.Strategy.OAuth2.Plug do
alias AshAuthentication.{Errors, Info, Strategy, Strategy.OAuth2}
alias Assent.{Config, HTTPAdapter.Finch}
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 Plug.Conn
@ -74,7 +74,7 @@ defmodule AshAuthentication.Strategy.OAuth2.Plug do
end
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)))
end

View file

@ -7,7 +7,7 @@ defmodule AshAuthentication.Strategy.Password.Plug do
alias AshAuthentication.{Info, Strategy, Strategy.Password}
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]
@doc "Handle a registration request"
@ -65,7 +65,7 @@ defmodule AshAuthentication.Strategy.Password.Plug do
end
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)))
end
end