Clojure 朋友使用基本身份验证导致重定向循环

Clojure friend causes redirect loop with basic auth

我正在使用 ringcompojurefriend 来实现玩具应用程序中的基本密码验证。现在我试图实现一个示例,我的环形服务器在每个浏览器中导致重定向循环。

这是我的代码:

(ns kassenclo.handlers
  (:use [ring.util.response]
        [ring.middleware.resource]
        [ring.middleware.params])
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.session :refer [wrap-session]]
            [ring.middleware.keyword-params :refer [wrap-keyword-params]]
            [kassenclo.views :as views]
            [cemerick.friend :as friend]
            [cemerick.friend.workflows :refer [make-auth]]))

(defroutes app
  (GET "/" [] views/tally-view)
  (GET "/inventory" [] (friend/authorize #{::user} views/inventory-view))
  (route/not-found (html [:h1 "This page could not be found, please go back."])))

(defn auth-workflow [request]
  (let [speak (get-in request [:params :speak])
        credential-fn (get-in request [::friend/auth-config :credential-fn])]
    (make-auth (credential-fn speak))))

(defn auth-credential [password]
  (if (= password "pass")
    {:identity password :roles #{::user}}))

(def handler
  (-> app
      (friend/authenticate {:workflows [auth-workflow]
                            :credential-fn auth-credential})
      (wrap-keyword-params)
      (wrap-params)
      (wrap-session)
      (wrap-resource "public")))

简单的调试显示服务器在 auth-workflowauth-credential 之间交替几次,然后才停止。谁能指出我遗漏了什么?

// 编辑: 奇怪的是,这个重定向循环发生在每条路由上,甚至在 / 上,其中 defroutes 命令中没有使用 friend

我发现 make-auth 函数,它包装了 authentication-map 以使其具有正确的形式,必须应用于 auth-credential [=13= 的 return 值]在 return之前。如果它像我原来的那样后来发生 post 朋友拒绝它,我们就会得到一个身份验证循环。