質問

I'm trying to put together my first web app with Compojure and am using Friend for the authentication/authorization. The problem I'm having is I want to use the interactive-form workflow but also have it set a custom session value once the user logs in successfully. I think I should be creating my own workflow but wrapping the interactive-form workflow but not sure how and if that's the correct approach.

役に立ちましたか?

解決

That's correct, if you want to go further and add a custom cookie here you have an usage example:

 (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

hope it helps

他のヒント

Answer is quite simple actually, Friend will automatically add your credentials hash (minus the password slot) to the session if authentication was a success.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top