Fix plug issue (#86)

This commit is contained in:
Dan Schultzer 2020-04-11 16:47:23 -07:00 committed by GitHub
parent 4e67bc8256
commit 36cbdff953
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,18 +44,12 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
|> Keyword.merge(opts) |> Keyword.merge(opts)
end end
def call(conn, type) do def call(conn, :load) do
conn
|> Plug.put_config(otp_app: @otp_app)
|> do_call(type)
end
defp do_call(conn, :load) do
Enum.reduce(conn.private[:invalidated_session_opts], conn, fn opts, conn -> Enum.reduce(conn.private[:invalidated_session_opts], conn, fn opts, conn ->
maybe_load_from_cache(conn, Plug.current_user(conn), opts) maybe_load_from_cache(conn, Plug.current_user(conn), opts)
end) end)
end end
defp do_call(conn, opts) do def call(conn, opts) do
fetch_fn = Keyword.fetch!(opts, :fetch_token) fetch_fn = Keyword.fetch!(opts, :fetch_token)
token = fetch_fn.(conn) token = fetch_fn.(conn)
@ -113,7 +107,10 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
@doc false @doc false
def client_store_fetch_session(conn) do def client_store_fetch_session(conn) do
conn = Conn.fetch_session(conn) conn =
conn
|> Plug.put_config(otp_app: @otp_app)
|> Conn.fetch_session()
with session_id when is_binary(session_id) <- Conn.get_session(conn, @session_key), with session_id when is_binary(session_id) <- Conn.get_session(conn, @session_key),
{:ok, session_id} <- Plug.verify_token(conn, @session_signing_salt, session_id) do {:ok, session_id} <- Plug.verify_token(conn, @session_signing_salt, session_id) do
@ -125,7 +122,10 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
@doc false @doc false
def client_store_fetch_persistent_cookie(conn) do def client_store_fetch_persistent_cookie(conn) do
conn = Conn.fetch_cookies(conn) conn =
conn
|> Plug.put_config(otp_app: @otp_app)
|> Conn.fetch_cookies()
with token when is_binary(token) <- conn.cookies[@persistent_cookie_key], with token when is_binary(token) <- conn.cookies[@persistent_cookie_key],
{:ok, token} <- Plug.verify_token(conn, @persistent_cookie_signing_salt, token) do {:ok, token} <- Plug.verify_token(conn, @persistent_cookie_signing_salt, token) do