Packages
potionx
0.2.17
0.8.15
0.8.14
0.8.13
0.8.12
0.8.11
0.8.10
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.3
0.5.2
0.5.1
0.5.0
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.18
0.2.17
0.2.16
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.1.1
0.1.0
Potionx is a set of generators and functions that speeds up the process of setting up and deploying a full-stack application that uses Elixir with GraphQL for the server-side component and Vue for the frontend component.
Current section
Files
Jump to
Current section
Files
lib/potionx/controllers/authorization_controller.ex
defmodule Potionx.AuthorizationController do
defmacro __using__(_) do
quote do
import Plug.Conn
alias Plug.Conn
import Ecto.Query
def callback(conn, %{"provider" => provider} = params) do
session_params = %{state: Map.fetch!(params, "state")}
params = Map.drop(params, ["provider"])
config = Pow.Plug.fetch_config(conn)
conn
|> Potionx.Plug.PowAssent.init_session
# |> load_session_params
|> Conn.put_private(:pow_assent_session_params, session_params)
|> Conn.put_private(:pow_assent_registration, false) # disable registration
|> Potionx.Plug.PowAssent.callback_upsert(
provider,
params,
redirect_uri(conn)
)
|> case do
{:ok, conn} ->
conn
|> Potionx.Plug.ApiAuth.handle_cookies(
%{
access_token: conn.private[:api_access_token],
renewal_token: conn.private[:api_renewal_token]
},
config
)
|> Phoenix.Controller.put_layout(false)
|> render(
"refresh.html",
url:
URI.parse(Conn.request_url(conn))
|> Map.put(:query, nil)
|> Map.put(:path, "/")
|> to_string
)
{:error, conn} ->
conn
|> redirect(
to: "/login/error"
)
end
end
defp load_session_params(%{private: %{pow_assent_session: %{session_params: params}}} = conn) do
conn
|> Conn.put_private(:pow_assent_session_params, params)
|> Potionx.Plug.PowAssent.delete_session(:session_params)
end
defp load_session_params(conn), do: conn
defp maybe_store_session_params(%{private: %{pow_assent_session_params: params}} = conn),
do: Potionx.Plug.PowAssent.put_session(conn, :session_params, params)
defp maybe_store_session_params(conn), do: conn
@spec new(Conn.t(), map()) :: Conn.t()
def new(conn, %{"provider" => provider}) do
conn
|> Potionx.Plug.PowAssent.init_session
|> Potionx.Plug.PowAssent.authorize_url(provider, redirect_uri(conn))
|> case do
{:ok, url, conn} ->
conn
|> maybe_store_session_params
|> json(%{data: %{url: url, session_params: conn.private[:pow_assent_session_params]}})
{:error, _error, conn} ->
conn
|> put_status(500)
|> json(%{error: %{status: 500, message: "An unexpected error occurred"}})
end
end
defoverridable [callback: 2, new: 2]
end
end
end