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?
How to implement user authentication using clojure-liberator?
2.7k Views Asked by zcaudate At
2
There are 2 best solutions below
4

The idiomatic way is to implement the :authorized?
decision point. However there is currently no support for the handling of basic or digest authentication. A practical approach is to use ring-basic-authentication
for authentication and handle only authorization in the resource. The following example uses ring-basic-authentication and sets the token to a users's role. This role is then checked by liberator in authorized?
(defresource admin-only
:handle-ok "secrect"
:handle-unauthorized "for admins only"
:authorized? (fn [{{token :token} :request}]
(= "admin" token)))
;; token returned encodes role
(defn authenticated? [name pass]
(cond (and (= name "scott")
(= pass "tiger")) "admin")
(and (= name "jack")
(= pass "jill")) "user)))
(def app (wrap-basic-authentication admin-only authenticated?))
from the readme"
so you can then wrap it in ring-basic-authentication