Fork me on GitHub

Hello guys, I am trying to add buddy middleware to authenticate users for a sample site.

 {:duct.core/project-ns sot
  {:backend :jwe
   :realm   "Example"
   :authfn  #ig/ref :sot.handler.test/basic-auth}
  :sot.handler.test/basic-auth {}
  {:middleware {:protected #ig/ref :duct.middleware.buddy/authentication}
   :routes {[:get "/"]
             ^:protected [:sot.handler/index]
            "/add-test" {:get ^:protected [:sot.handler.test/view]
                         [:post {add-form :form-params}] [:sot.handler.test/create add-form]}}}
where my authfn is
(defmethod ig/init-key ::basic-auth [_ _]
  (println "Authenticated")
  (fn [request token]
    (println request)
    (println token)
    [::response/bad-request (vi/error-page)]))
I get the "Authenticated" log when i run my app but it is not calling the auth-fn function content at any point. Is there something I am missing ?


I’m not familiar with buddy, but I noticed several things. 1. The (println "Authenticated") line is called when the integrant key is initiated, not authentication. 2. The arity of the authfn does not match the example provided by duct.middleware.buddy


@U0HLHE6JE yes indeed for both points but still that does not explain why I am not having any output with the authfn whatever I change it to. I changed my function arity, but that did not matter. Anyway I ended up plugging my own authentication process without the use of the buddy middleware , thank you


Perhaps any error thrown when invoking the authfn (e.g. arity mis-match) is interpreted as unauthenticated?


no errors nothing i just use the site normally


(Again, I’m not familiar with buddy) Maybe you could pass an on-error handler to :duct.middleware.buddy/authentication? Looks like the default implementation swallows any error thrown from the auth-fn.