Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns egoago-profile.middleware
- (:require [compojure.core :refer :all]
- [egoago-profile.handler :refer :all]
- [ring.util.http-response :refer :all]
- [ring.middleware.format :refer [wrap-restful-format]]
- [buddy.auth.middleware :refer [wrap-authentication]]
- [buddy.auth :refer [authenticated? throw-unauthorized]]
- [buddy.auth.backends.token :refer [jwe-backend]]
- [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
- [compojure.api.middleware :refer [api-middleware]]
- [taoensso.timbre :as timbre :refer [log trace debug info]]))
- (def backend (jwe-backend {:secret (secret)}))
- (defn wrap-core [routes]
- (-> routes
- (api-middleware)))
- (defn wrap-required-authentication [handler]
- (fn [request]
- (if (authenticated? request)
- (handler request)
- (unauthorized))))
- (defn wrap-secure [routes]
- (-> routes
- (wrap-required-authentication)
- (wrap-authentication backend)))
- (defn build-routes [profile]
- (debug "Building the routes.")
- (wrap-core
- (routes
- (unsecured-routes profile)
- (wrap-secure (secured-routes profile)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement