Skip to content

Commit a6c636c

Browse files
committed
compose routes to add authentication separately
1 parent 6ddafb6 commit a6c636c

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
;; Internationalization
4646
[com.taoensso/tower "2.0.1"]]
4747

48-
:ring {:handler patronage.handler/app-handler
48+
:ring {:handler patronage.handler/auth-app-handler
4949
:init patronage.handler/init
5050
:destroy patronage.handler/destroy}
5151

src/patronage/handler.clj

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
[compojure.core :refer :all]
55
[compojure.handler :as handler]
66
[compojure.route :as route]
7-
[patronage.auth :refer :all]
7+
[patronage.auth.github :refer :all]
88
[patronage.models.logging :as logging]
99
[patronage.models.migrations :as migrations]
10-
[patronage.routes.api :refer [api-routes]]
10+
[patronage.routes.api :refer [api-v1-routes]]
1111
[ragtime.core :refer [migrate-all]]
1212
[ring.util.response :as response]
1313
[taoensso.timbre :as timbre]))
@@ -40,10 +40,12 @@
4040
[]
4141
(timbre/info "patronage is shutting down..."))
4242

43-
(def app-handler (-> (routes api-routes
44-
auth-routes
43+
(def app-handler (-> (routes api-v1-routes
4544
app-routes)
46-
(friend/requires-scheme-with-proxy :https)
47-
(friend/authenticate {:allow-anon? true
48-
:workflows [github-workflow]})
4945
handler/site))
46+
47+
(def auth-app-handler (-> app-handler
48+
(friend/requires-scheme-with-proxy :https)
49+
(friend/authenticate
50+
{:allow-anon? true
51+
:workflows [github-workflow]})))

src/patronage/repl.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
;; server is forced to re-resolve the symbol in the var rather than
1616
;; having its own copy. When the root binding changes, the server
1717
;; picks it up without having to restart.
18-
(-> #'app-handler
18+
(-> #'auth-app-handler
1919
;; Makes static assets in $PROJECT_DIR/resources/public/ available.
2020
(wrap-file "resources")
2121
;; Content-Type, Content-Length, and Last Modified headers for files in body

src/patronage/routes/api.clj

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757

5858
(defroutes api-routes
5959
(ANY ["/bids/:id" :id #".*"] [id]
60-
(friend/authenticated (bid id)))
60+
(bid id))
6161
(ANY "/bids" []
62-
(friend/authenticated bids)))
62+
bids))
63+
64+
(defroutes api-v1-routes
65+
(context "/api/v1" [] (friend/authorize #{::user} api-routes)))

test/patronage/auth_test.clj test/patronage/auth/github_test.clj

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
(ns patronage.auth-test
2-
(:require [clojure.test :refer [deftest
3-
is
4-
testing]]
5-
[patronage.auth :refer [auth-routes
6-
github-workflow]]
7-
[ring.mock.request :refer [request]]))
1+
(ns patronage.auth.github-test
2+
(:require [clojure.test :refer [deftest
3+
is
4+
testing]]
5+
[patronage.auth.github :refer [auth-routes
6+
github-workflow]]
7+
[ring.mock.request :refer [request]]))
88

99
(deftest test-auth-handler
1010
(let [base-url "https://localhost:3443"]

0 commit comments

Comments
 (0)