Module Webs_kit.Authenticated_cookie

Authenticated cookies.

An authenticated cookie lets your service store expirable state on the client with the guarantee that it cannot tamper with it. The data is not encrypted, this is not made to store service secrets on the client.

In order to use this you need a private key in your service. An easy way to handle this is to generate one randomly with Authenticatable.random_key when you start your service. Note however that this invalidates any data currently stored on your clients whenever you restart your service – that may be okay, or not.

val get : private_key:Authenticatable.private_key -> now:Authenticatable.time -> name:string -> Webs.Req.t -> string option

get ~private_key ~now ~name req is the cookie of req named name authenticated and expired by private_key and now (see Authenticatable.decode).

TODO. Any kind of error leads to None.

val set : private_key:Authenticatable.private_key -> expire:Authenticatable.time option -> ?atts:Webs.Http.Cookie.atts -> name:string -> string -> Webs.Resp.t -> Webs.Resp.t

set ~private_key ~expire ~atts ~name data resp sets in resp the cookie name to data authenticated by private_key and expiring at expire (see Authenticatable.encode). atts are the cookie's attribute they default to Webs.Http.Cookie.atts_default.