1

我是 Clojure 的新手并使用 Luminus 构建网站,我一直在尝试将 OpenID 集成到我的网站,但我失败了。我有这个代码示例:

https://github.com/cemerick/friend-demo/blob/master/src/clj/cemerick/friend_demo/openid.clj

演示: http: //friend-demo.herokuapp.com/openid/

我正在尝试将它实施到我的网站,但我不断收到错误,最后我只是想准确地复制它以查看它是否在我的本地主机上工作。所以我的 home.clj 中有这段代码

但这不起作用,每当我单击登录按钮时,我都会在 localhost:3000/login 获得“未找到”

这是否意味着我需要处理 /login 一些?但它没有记录在上面的示例代码中。

(def providers [{:name "Steam" :url "http://steamcommunity.com/openid"}
{:name "Yahoo" :url "http://me.yahoo.com/"}])

(defroutes home-routes
(GET "/" req
(h/html5
  pretty-head
  (pretty-body
   ; (github-link req)
   [:h2 "Authenticating with various services using OpenID"]
   [:h3 "Current Status " [:small "(this will change when you log in/out)"]]
   (if-let [auth (friend/current-authentication req)]
    [:p "Some information delivered by your OpenID provider:"
    [:ul (for [[k v] auth
      :let [[k v] (if (= :identity k)
        ["Your OpenID identity" (str (subs v 0 (* (count v) 2/3)) "…")]
        [k v])]]
      [:li [:strong (str (name k) ": ")] v])]]
    [:div
    [:h3 "Login with…"]
    (for [{:keys [name url]} providers
     :let [base-login-url (context-uri req (str "/login?identifier=" url))
     dom-id (str (gensym))]]
     [:form {:method "POST" :action (context-uri req "login")
     :onsubmit (when (.contains ^String url "username")
       (format "var input = document.getElementById(%s); input.value = input.value.replace('username', prompt('What is your %s username?')); return true;"
         (str \' dom-id \') name))}
     [:input {:type "hidden" :name "identifier" :value url :id dom-id}]
     [:input {:type "submit" :class "button" :value name}]])
    [:p "…or, with a user-provided OpenID URL:"]
    [:form {:method "POST" :action (context-uri req "login")}
    [:input {:type "text" :name "identifier" :style "width:250px;"}]
    [:input {:type "submit" :class "button" :value "Login"}]]])
   [:h3 "Logging out"]
   [:p [:a {:href (context-uri req "logout")} "Click here to log out"] "."])))
(GET "/logout" req 
(friend/logout* (resp/redirect (str (:context req) "/")))))

(def page (friend/authenticate
home-routes
{:allow-anon? true
:default-landing-uri "/"
:workflows [(openid/workflow
:openid-uri "/login"
:credential-fn identity)]}))
4

1 回答 1

0

/login回调由它处理,它openid-workflow本质上成为您的home-routes. 当您应该使用时,您可能会home-routes用作您的请求处理程序page

于 2015-07-27T11:06:24.263 回答