Skip to content

Instantly share code, notes, and snippets.

@cgag
Created October 12, 2013 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgag/6944435 to your computer and use it in GitHub Desktop.
Save cgag/6944435 to your computer and use it in GitHub Desktop.
...
(defroutes basic-routes
(GET "/" [] (str "<a href=\"/test\">test</a>"))
(GET "/test" [] (friend/authenticated (home/index))))
(defroutes all-routes
basic-routes
<other routes>)
(def users
(def users {"root" {:username "root"
:password (creds/hash-bcrypt "admin_password")
:roles #{::admin}}
"jane" {:username "jane"
:password (creds/hash-bcrypt "user_password")
:roles #{::user}}}))
(def secured-app
(friend/authenticate
all-routes
{:allow-anon? true
:unauthenticated-handler (fn [e] {:status 200 :body (str e)})
:workflows [(workflows/http-basic
:credential-fn (partial creds/bcrypt-credential-fn users))]}))
(def app (handler/site #'secured-app))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment