-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.clj
32 lines (28 loc) · 1.05 KB
/
admin.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns andrewslai.clj.routes.admin
(:require [buddy.auth.accessrules :refer [restrict]]
[compojure.api.sweet :refer [context defroutes GET]]
[ring.util.http-response :refer [ok]]
[taoensso.timbre :as log]))
(defn is-authenticated? [req]
(try
(log/info "Is authenticated?" (not (empty? (:identity req))))
(not (empty? (:identity req)))
(catch Throwable t
nil)))
(defn access-error [request value]
(log/info "Not authorized for endpoint")
{:status 401
:headers {}
:body {:reason "Not authorized"}})
(defroutes admin-get
(GET "/" []
:swagger {:summary "An Echo route to see if a user is authenticated"
:produces #{"application/json"}
:responses {200 {:description "A collection of all articles"}}}
(do (log/info "User Authorized for /admin/ route")
(ok {:message "Got to the admin-route!"}))))
(defroutes admin-routes
(context "/admin" []
:tags ["admin"]
(restrict admin-get {:handler is-authenticated?
:on-error access-error})))