Skip to content

Commit

Permalink
Merge pull request #74 from danschultzer/get-plug
Browse files Browse the repository at this point in the history
Use `Pow.Plug.get_plug/1`
  • Loading branch information
danschultzer committed Jun 4, 2019
2 parents 10866e0 + 63076ca commit 71eb7dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* `PowAssent.Ecto.UserIdentities.Context.upsert/3`
* `PowAssent.Ecto.UserIdentities.Context.create_user/4`
* Fixed bug where invited user was not signed in after succesful authorization
* Use `Pow.Plug.get_plug/1` instead of pulling `:mod` from the config

## v0.3.0 (2019-05-19)

Expand Down
13 changes: 6 additions & 7 deletions lib/pow_assent/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule PowAssent.Plug do
"""
alias Plug.Conn
alias PowAssent.{Config, Operations}
alias Pow.Plug

@doc """
Calls the authorize_url method for the provider strategy.
Expand All @@ -35,7 +36,7 @@ defmodule PowAssent.Plug do
end

defp maybe_put_session_params({:ok, %{url: url, session_params: params}}, conn) do
{:ok, url, Plug.Conn.put_private(conn, :pow_assent_session_params, params)}
{:ok, url, Conn.put_private(conn, :pow_assent_session_params, params)}
end
defp maybe_put_session_params({:ok, %{url: url}}, conn), do: {:ok, url, conn}
defp maybe_put_session_params({:error, error}, conn), do: {:error, error, conn}
Expand Down Expand Up @@ -96,7 +97,7 @@ defmodule PowAssent.Plug do
|> Operations.get_user_by_provider_uid(uid, config)
|> case do
nil -> {:error, conn}
user -> {:ok, get_mod(config).do_create(conn, user, config)}
user -> {:ok, Plug.get_plug(config).do_create(conn, user, config)}
end
end

Expand All @@ -119,7 +120,7 @@ defmodule PowAssent.Plug do
user
|> Operations.upsert(user_identity_params, config)
|> case do
{:ok, user_identity} -> {:ok, user_identity, get_mod(config).do_create(conn, user, config)}
{:ok, user_identity} -> {:ok, user_identity, Plug.get_plug(config).do_create(conn, user, config)}
{:error, error} -> {:error, error, conn}
end
end
Expand All @@ -136,7 +137,7 @@ defmodule PowAssent.Plug do
user_identity_params
|> Operations.create_user(user_params, user_id_params, config)
|> case do
{:ok, user} -> {:ok, user, get_mod(config).do_create(conn, user, config)}
{:ok, user} -> {:ok, user, Plug.get_plug(config).do_create(conn, user, config)}
{:error, error} -> {:error, error, conn}
end
end
Expand Down Expand Up @@ -192,7 +193,7 @@ defmodule PowAssent.Plug do
config = Pow.Plug.fetch_config(conn)

config
|> Keyword.take([:otp_app, :mod, :repo, :user])
|> Keyword.take([:otp_app, :plug, :repo, :user])
|> Keyword.merge(Keyword.get(config, :pow_assent, []))
end

Expand All @@ -209,6 +210,4 @@ defmodule PowAssent.Plug do

{strategy, provider_config}
end

defp get_mod(config), do: config[:mod]
end
2 changes: 1 addition & 1 deletion test/pow_assent/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule PowAssent.PlugTest do
import PowAssent.Test.TestProvider, only: [expect_oauth2_flow: 1, put_oauth2_env: 1]

@default_config [
mod: Pow.Plug.Session,
plug: Pow.Plug.Session,
user: User,
otp_app: :pow_assent,
pow_assent: [
Expand Down

0 comments on commit 71eb7dd

Please sign in to comment.