Skip to content

Commit

Permalink
improvement: set context in addition to tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Aug 9, 2024
1 parent 3562aea commit b75097d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/ash_authentication/plug/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ash_authentication/strategies/magic_link/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/ash_authentication/strategies/oauth2/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/ash_authentication/strategies/password/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

0 comments on commit b75097d

Please sign in to comment.