Plug.Session.COOKIE
Stores the session in a cookie.
This cookie store is based on Plug.Crypto.MessageVerifier
and Plug.Crypto.Message.Encryptor
which encrypts and signs
each cookie to ensure they can’t be read nor tampered with.
Since this store uses crypto features, it requires you to
set the :secret_key_base
field in your connection. This
can be easily achieved with a plug:
plug :put_secret_key_base
def put_secret_key_base(conn, _) do
put_in conn.secret_key_base, "-- LONG STRING WITH AT LEAST 64 BYTES --"
end
Options
:encrypt
- specify whether to encrypt cookies, defaults to true. When this option is false, the cookie is still signed, meaning it can’t be tempered with but its contents can be read:encryption_salt
- a salt used withconn.secret_key_base
to generate a key for encrypting/decrypting a cookie:signing_salt
- a salt used withconn.secret_key_base
to generate a key for signing/verifying a cookie.
Examples
# Use the session plug with the table name
plug Plug.Session, store: :cookie,
key: "_my_app_session",
encryption_salt: "cookie store encryption salt",
signing_salt: "cookie store signing salt"
Summary
delete(conn, sid, opts) | Callback implementation of |
get(conn, cookie, opts) | Callback implementation of |
init(opts) | Callback implementation of |
put(conn, sid, term, opts) | Callback implementation of |
Functions
Callback implementation of Plug.Session.Store.delete/3
.
Callback implementation of Plug.Session.Store.get/3
.
Callback implementation of Plug.Session.Store.init/1
.
Callback implementation of Plug.Session.Store.put/4
.