Authentication 重定向到/登录未经身份验证的用户
我正在尝试对compojure和ring应用程序的auth进行良好处理。如果用户未通过身份验证,我要做的是重定向到Authentication 重定向到/登录未经身份验证的用户,authentication,clojure,compojure,ring,luminus,Authentication,Clojure,Compojure,Ring,Luminus,我正在尝试对compojure和ring应用程序的auth进行良好处理。如果用户未通过身份验证,我要做的是重定向到/login。下面的方法似乎是我想要的 我将wrap restricted处理程序添加到我的#home-routes中,如下所示: (def app-routes (routes (-> #'home-routes (wrap-routes middleware/wrap-restricted) (wrap-routes middlewar
/login
。下面的方法似乎是我想要的
我将wrap restricted
处理程序添加到我的#home-routes
中,如下所示:
(def app-routes
(routes
(-> #'home-routes
(wrap-routes middleware/wrap-restricted)
(wrap-routes middleware/wrap-csrf)
(wrap-routes middleware/wrap-formats)
...))
然后在中间件中,我更改了on error
(在wrap restricted
处理程序中引用)以执行重定向,而不是403响应:
(defn on-error [request response]
;; (error-page
;; {:status 403
;; :title (str "Access to " (:uri request) " is not authorized")})
(redirect (format "/login?next=%s" (:uri request))))
(defn wrap-restricted [handler]
(restrict handler {:handler authenticated?
:on-error on-error}))
我的问题是,这是正确的(推荐的最佳做法)方法吗?您是否尝试过使用身份验证库,如?@Aleph-Aleph-Yes。代码是由buddy附带的luminus生成的。您是否尝试使用身份验证库,如?@Aleph-Aleph-Yes。代码是由luminus生成的,它是buddy附带的。