我并不真正理解https://github.com/clojure-liberator/liberator和它提供给开发人员的决策点列表。如何使用库的/旁/上-实现基本的身份验证/身份验证服务?
发布于 2012-12-05 02:08:32
来自自述文件“
资源与Ring兼容,可以封装在Ring中间件中。在计算时,资源返回一个函数,该函数接受Ring请求并返回Ring响应。
因此您可以将其包装在ring-basic-authentication中
(use 'ring.middleware.basic-authentication)
(defn authenticated? [name pass] (and (= name "foo") (= pass "bar")))
(def app (-> routes .. (wrap-basic-authentication authenticated?))发布于 2013-01-07 05:56:00
惯用的方法是实现:authorized?决策点。但是,目前还不支持处理基本或摘要身份验证。一种实用的方法是使用ring-basic-authentication进行身份验证,并且只处理资源中的授权。以下示例使用ring-basic-authentication并将令牌设置为用户的角色。然后由authorized?中的liberator检查此角色
(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?))https://stackoverflow.com/questions/13702003
复制相似问题