I'm trying to understand when the ring anti-forgery token is generated or inserted in an HTML page. I'm using Compojure / ring / hiccup but I take it my question is really about ring. I don't have any problem per se: I just want to know when and how the anti-forgery token is "injected".
The anti-forgery-field function from ring.util.anti-forgery is implemented like this:
(html (hidden-field "__anti-forgery-token" *anti-forgery-token*)
If I call this function at a REPL I get:
REPL> (println (anti-forgery-field))
<input id="__anti-forgery-token" name="__anti-forgery-token" type="hidden" value="Unbound: #'ring.middleware.anti-forgery/*anti-forgery-token*" />
Still at the REPL, if I try to get this var I get the same "unbound" variable:
> ring.middleware.anti-forgery/*anti-forgery-token*
=> #object[clojure.lang.Var$Unbound 0x1eae055 "Unbound: #'ring.middleware.anti-forgery/*anti-forgery-token*"]
What I don't understand is what that "Unbound" value is nor when it is transformed (by ring?) into an actual token delivered. And I especially don't understand how several users connecting to the website do get, each, a different token (per session).
Is that variable always "unbound"? When/how does it become "bound" (if it does?)?
Also, if I've got the ring session ID (say "ring-session=310678be-9ef6-41a7-a12a-b2417de4a79f"), how can I see, at the Clojure REPL (on the server side), the corresponding anti-forgery token's value?