This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-18
Channels
- # aws-lambda (3)
- # beginners (57)
- # boot (3)
- # bristol-clojurians (1)
- # cider (38)
- # cljs-dev (23)
- # clojure (35)
- # clojure-italy (32)
- # clojure-nl (6)
- # clojure-spec (35)
- # clojure-uk (132)
- # clojurescript (34)
- # cursive (22)
- # data-science (1)
- # datomic (54)
- # devcards (1)
- # duct (5)
- # editors (7)
- # euroclojure (4)
- # fulcro (40)
- # graphql (1)
- # hoplon (6)
- # immutant (5)
- # jobs (1)
- # off-topic (22)
- # om (1)
- # planck (17)
- # portkey (1)
- # protorepl (12)
- # re-frame (97)
- # reagent (67)
- # reitit (16)
- # ring-swagger (1)
- # shadow-cljs (98)
- # spacemacs (8)
- # sql (20)
- # tools-deps (60)
I'm trying to add authentication to a sample site in duct. I'm using the buddy middleware. I have tried using the buddy.auth.accessrules/restrict function as @weavejester suggested in https://github.com/duct-framework/module.ataraxy/issues/6.
It kind of works, I'm able to login with credentials and restrict pages but I have not found a way to add a custom unauthorized page. Adding a handler to :on-error
in the restrict function does not seem to work, (I still see the unauthorized exception page).
I have added the following middleware:
clojure
(defmethod ig/init-key ::restrict
[_ _]
(fn [handler]
(-> handler
(restrict {:handler authenticated? :on-error (ig/ref :otherblog.handler.login/denied)}))))
where the :otherblog.handler.login/denied
handler is:
clojure
(defmethod ig/init-key ::denied [_ options]
(fn [{[_] :ataraxy/result}]
[::response/bad-request (io/resource "otherblog/handler/login/denied.html")]))
I have included them in the config file as well:
:otherblog.middleware/restrict {}
;; ...
;; middleware
:duct.router/ataraxy
{:middleware {:session-auth #ig/ref :duct.middleware.buddy/authentication}}
;; routes
:duct.module/ataraxy
{[:get "/example"]
^:restrict ^:session-auth
[:example/example]
;; handlers
:otherblog.handler.example/example
{:db #ig/ref :duct.database/sql}
:otherblog.handler.login/login
{:db #ig/ref :duct.database/sql}
:otherblog.handler.login/denied
{:db #ig/ref :duct.database/sql}
@nyor.tr You can’t add refs to init-key
, since that method is called after references are resolved.
The latest Integrant alpha version adds prep-key
for this purpose.
You could also add the ref for :on-error
via the configuration