Skip to content

Commit

Permalink
display profile page if referer is same as base_url #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 24, 2020
1 parent 82e0f36 commit 1a96139
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions lib/auth_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ defmodule AuthWeb.AuthController do
|> IO.inspect(label: "email")

# check if valid state (HTTP referer) is defined:
case not is_nil(state) do
# redirect
true ->
conn
|> redirect(external: add_jwt_url_param(person, state))

false ->
base_url = AuthPlug.Helpers.get_baseurl_from_conn(conn)
IO.inspect(state, label: "state")
IO.inspect(base_url, label: "base_url")
case state =~ base_url do
true -> # display welcome page
conn
|> put_view(AuthWeb.PageView)
|> render(:welcome, person: person)

false -> # redirect
conn
|> redirect(external: add_jwt_url_param(person, state))

end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/auth_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ defmodule AuthWeb.PageController do
Map.get(query, "referer")
|> IO.inspect(label: "url referer")

false -> # no referer, redirect back to this app. TODO:
false -> # no referer, redirect back to this app.
IO.inspect("false: no referer")
ElixirAuthGoogle.get_baseurl_from_conn(conn)
AuthPlug.Helpers.get_baseurl_from_conn(conn)
end
end
|> URI.encode |> IO.inspect(label: "referer")
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Auth.Mixfile do
# https://github.com/dwyl/elixir-auth-google
{:elixir_auth_google, "~> 1.2.0"},
# https://github.com/dwyl/auth_plug
{:auth_plug, "~> 0.7.0"},
{:auth_plug, "~> 0.8.0"},

# Field Validation and Encryption: github.com/dwyl/fields
{:fields, "~> 2.4.0"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"argon2_elixir": {:hex, :argon2_elixir, "2.3.0", "e251bdafd69308e8c1263e111600e6d68bd44f23d2cccbe43fcb1a417a76bc8e", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "28ccb63bff213aecec1f7f3dde9648418b031f822499973281d8f494b9d5a3b3"},
"auth_plug": {:hex, :auth_plug, "0.7.0", "ce8001402b2c2dbabe743c86c030d28d276f6ce138beac112323a342d1d44e15", [:mix], [{:joken, "~> 2.2.0", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "1c96440dd73bb323cca32c838ead5aea44e16ed6e221ed5b248c7f02c498aef9"},
"auth_plug": {:hex, :auth_plug, "0.8.0", "1200a5dfc979b4f82efd803dd0042b8a54171e7947964fdd87ea52f14580106a", [:mix], [{:joken, "~> 2.2.0", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "652df6e403554718f59405ca4a3d21f5130399429ae8b0357eb50b5c2a8c7a5e"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"},
"comeonin": {:hex, :comeonin, "5.3.1", "7fe612b739c78c9c1a75186ef2d322ce4d25032d119823269d0aa1e2f1e20025", [:mix], [], "hexpm", "d6222483060c17f0977fad1b7401ef0c5863c985a64352755f366aee3799c245"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},
Expand Down
4 changes: 2 additions & 2 deletions test/auth_web/controllers/auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ defmodule AuthWeb.AuthControllerTest do
assert html_response(conn, 302) =~ "http://localhost"
end

test "google_handler/2 nil state", %{conn: conn} do
test "google_handler/2 show welcome page", %{conn: conn} do
conn = get(conn, "/auth/google/callback",
%{code: "234", state: nil})
%{code: "234", state: AuthPlug.Helpers.get_baseurl_from_conn(conn)})

assert html_response(conn, 200) =~ "[email protected]"
# assert html_response(conn, 302) =~ "redirected"
Expand Down

0 comments on commit 1a96139

Please sign in to comment.