Browse Source

chore(oauth2): Add logic for GitHub prereq.

jackyalcine 2 months ago
parent
commit
d004874c56
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D
6 changed files with 28 additions and 3 deletions
  1. 1
    1
      config/config.exs
  2. 2
    1
      mix.exs
  3. 1
    0
      mix.lock
  4. 14
    1
      web/controllers/oauth2.ex
  5. 7
    0
      web/router.ex
  6. 3
    0
      web/views/oauth2.ex

+ 1
- 1
config/config.exs View File

@@ -40,7 +40,7 @@ config :tesla, adapter: Tesla.Adapter.Hackney
40 40
 config :mnesia, dir: 'priv/mnesia/#{Mix.env()}/#{node()}'
41 41
 
42 42
 config :ueberauth, Ueberauth,
43
-  base_path: "/endpoints/oauth/",
43
+  base_path: "/oauth/",
44 44
   providers: [
45 45
     github: {Ueberauth.Strategy.Github, [default_scope: "read:user"]}
46 46
   ]

+ 2
- 1
mix.exs View File

@@ -75,7 +75,8 @@ defmodule Fortress.Mixfile do
75 75
       {:ueberauth, "~> 0.6.1"},
76 76
       {:indieweb, git: "https://git.jacky.wtf/indieweb/elixir", branch: :develop, override: true},
77 77
       {:ueberauth_indieauth,
78
-       git: "https://git.jacky.wtf/indieweb/ueberauth_indieauth/", branch: :develop}
78
+        git: "https://git.jacky.wtf/indieweb/ueberauth_indieauth/", branch: :develop},
79
+{:ueberauth_github, "~> 0.7"},
79 80
     ]
80 81
   end
81 82
 

+ 1
- 0
mix.lock View File

@@ -63,6 +63,7 @@
63 63
   "timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
64 64
   "tzdata": {:hex, :tzdata, "1.0.2", "6c4242c93332b8590a7979eaf5e11e77d971e579805c44931207e32aa6ad3db1", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
65 65
   "ueberauth": {:hex, :ueberauth, "0.6.2", "25a31111249d60bad8b65438b2306a4dc91f3208faa62f5a8c33e8713989b2e8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
66
+  "ueberauth_github": {:hex, :ueberauth_github, "0.7.0", "637067c5500f7b13c18caca3db66d09eba661524e0d0e9518b54151e99484bad", [:mix], [{:oauth2, "~> 0.9", [hex: :oauth2, repo: "hexpm", optional: false]}, {:ueberauth, "~> 0.4", [hex: :ueberauth, repo: "hexpm", optional: false]}], "hexpm"},
66 67
   "ueberauth_indieauth": {:git, "https://git.jacky.wtf/indieweb/ueberauth_indieauth/", "73359386d5cadb7e7625084f8f520eb3675b5e09", [branch: :develop]},
67 68
   "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
68 69
   "unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm"},

+ 14
- 1
web/controllers/oauth2.ex View File

@@ -1,4 +1,17 @@
1 1
 defmodule Fortress.Web.OAuth2Controller do
2 2
   use Fortress.Web, :controller
3
-  plug Ueberauth, base_path: "/endpoints/oauth"
3
+  plug Ueberauth
4
+
5
+  alias Ueberauth.Strategy.Helpers
6
+
7
+  def callback(%{assigns: %{ueberauth_failure: _fails}} = conn, _params) do
8
+    conn
9
+    |> put_flash(:error, "Failed to authenticate.")
10
+    |> redirect(to: "/")
11
+  end
12
+
13
+  def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
14
+        conn
15
+        |> redirect(to: "/")
16
+  end
4 17
 end

+ 7
- 0
web/router.ex View File

@@ -28,6 +28,13 @@ defmodule Fortress.Web.Router do
28 28
     get("/resolve/via/:platform", ResolverController, :request)
29 29
   end
30 30
 
31
+  scope "/oauth", Fortress.Web do
32
+    pipe_through([:browser])
33
+    get("/:provider", OAuth2Controller, :request, as: :oauth2)
34
+    get("/:provider/callback", OAuth2Controller, :callback, as: :oauth2)
35
+    post("/:provider/callback", OAuth2Controller, :callback, as: :oauth2)
36
+  end
37
+
31 38
   # Meant for the browser, requires pre-auth by the user.
32 39
   # [:browser, :owner, :requires_owner_auth]
33 40
   scope "/endpoints/indieauth", Fortress.Web do

+ 3
- 0
web/views/oauth2.ex View File

@@ -0,0 +1,3 @@
1
+defmodule Fortress.Web.OAuth2View do
2
+  use Fortress.Web, :view
3
+end

Loading…
Cancel
Save