clojureliberator

How to implement user authentication using clojure-liberator?


I'm not really understanding https://github.com/clojure-liberator/liberator and the list of decision points that it provides to the developer. How would one implement a basic auth/auth service using/alongside/on-top-of the library?


Solution

  • from the readme"

    Resources are compatible with Ring and can be wrapped in Ring middleware. When evaluated, a resource returns a function which takes a Ring request and returns a Ring response.

    so you can then wrap it in ring-basic-authentication

    (use 'ring.middleware.basic-authentication)
    (defn authenticated? [name pass] (and (= name "foo") (= pass "bar")))
    (def app (-> routes .. (wrap-basic-authentication authenticated?))