1

I am using Friend for authentication/authorization in a Clojure Ring application. I am trying to persist session data into a cookie via 'Remember Me' functionality, so that it can survive e.g. server restarts. My handler definition is:

(def secured-routes
  (-> app-routes
      (friend/authenticate friend-param-map)
      (wrap-defaults (-> site-defaults
                         (assoc-in [:security :anti-forgery] false)
                         (assoc :session {:store (cookie-store {:key "16-byte-secret"})
                                          :cookie-name "TestCookie"
                                          :cookie-attrs {:max-age 1800}})
                         (assoc :cookies true)))
      wrap-json-params))

What else do I need to write to make it work? Do I need to create a cookie first in one of the app-routes handlers?

Thanks!

siphiuel
  • 3,480
  • 4
  • 31
  • 34

1 Answers1

1

I guess you are already aware of this issue. Anyway as far as I recall your best chance is to use wrap-session

Something like this should work (sorry not tested)

(def secured-routes
  (-> app-routes
      (friend/authenticate friend-param-map)
      (wrap-session {:cookie-attrs {:max-age 3600} :cookie-name "TestCookie" } )
      (wrap-defaults (-> site-defaults
                         (assoc-in [:security :anti-forgery] false)))
      wrap-json-params))
Jaime Agudo
  • 8,076
  • 4
  • 30
  • 35