【问题标题】:Add custom session entries after successful authentication with Friend, Compojure, Ring在 Friend、Compojure、Ring 成功认证后添加自定义会话条目
【发布时间】:2014-01-10 08:11:02
【问题描述】:

我正在尝试将我的第一个 Web 应用程序与 Compojure 放在一起,并使用 Friend 进行身份验证/授权。我遇到的问题是我想使用交互式表单工作流,但也让它在用户成功登录后设置自定义会话值。我认为我应该创建自己的工作流程,但包装交互式表单工作流程,但不确定如何以及是否是正确的方法。

【问题讨论】:

    标签: session authentication clojure compojure ring


    【解决方案1】:

    答案其实很简单,如果身份验证成功,Friend 会自动将您的凭据哈希(减去密码槽)添加到会话中。

    【讨论】:

      【解决方案2】:

      没错,如果您想更进一步并在此处添加自定义 cookie,您有一个使用示例:

       (defn friend-middleware
        "Returns a middleware that enables authentication via Friend."
        [handler]
        (let [auth-config {
                           :credential-fn (partial creds/bcrypt-credential-fn db/load-credentials)
                           :redirect-on-auth? false
                           :logout-uri "/logout"
                           :signup-uri "/registration"
                           :workflows
                        [;; Note that ordering matters here. Basic first.
                         (workflows/interactive-form)
                         ]}]
          (-> handler
              (friend/authenticate auth-config)
              (wrap-session {:cookie-attrs {:max-age 3600} :cookie-name "my-site.com" } )
              )))
      

      https://gist.github.com/jaimeagudo/8931879

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 2014-11-25
        • 2011-04-21
        • 2014-05-25
        • 2016-07-30
        • 1970-01-01
        • 2021-10-21
        • 2013-07-16
        • 2017-10-25
        • 2013-07-18
        相关资源
        最近更新 更多