【问题标题】:Clojure - OpenID - Luminus - Steam IntegrationClojure - OpenID - Luminus - Steam 集成
【发布时间】:2015-07-24 14:06:42
【问题描述】:

我是 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)]}))

【问题讨论】:

    标签: clojure openid steam luminus


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 2013-12-27
      • 2019-05-03
      • 2014-03-29
      • 1970-01-01
      相关资源
      最近更新 更多