Advertisement
Guest User

Untitled

a guest
Apr 12th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. (ns egoago-profile.middleware
  2. (:require [compojure.core :refer :all]
  3. [egoago-profile.handler :refer :all]
  4. [ring.util.http-response :refer :all]
  5. [ring.middleware.format :refer [wrap-restful-format]]
  6. [buddy.auth.middleware :refer [wrap-authentication]]
  7. [buddy.auth :refer [authenticated? throw-unauthorized]]
  8. [buddy.auth.backends.token :refer [jwe-backend]]
  9. [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
  10. [compojure.api.middleware :refer [api-middleware]]
  11. [taoensso.timbre :as timbre :refer [log trace debug info]]))
  12.  
  13. (def backend (jwe-backend {:secret (secret)}))
  14.  
  15. (defn wrap-core [routes]
  16. (-> routes
  17. (api-middleware)))
  18.  
  19. (defn wrap-required-authentication [handler]
  20. (fn [request]
  21. (if (authenticated? request)
  22. (handler request)
  23. (unauthorized))))
  24.  
  25. (defn wrap-secure [routes]
  26. (-> routes
  27. (wrap-required-authentication)
  28. (wrap-authentication backend)))
  29.  
  30. (defn build-routes [profile]
  31. (debug "Building the routes.")
  32. (wrap-core
  33. (routes
  34. (unsecured-routes profile)
  35. (wrap-secure (secured-routes profile)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement