Pow v1.0.14 PowPersistentSession.Plug.Cookie View Source
This plug will handle persistent user sessions with cookies.
By default, the cookie will expire after 30 days. The cookie expiration will be renewed on every request. The token in the cookie can only be used once to create a session.
If an assigned private :pow_session_metadata
key exists in the conn with a
keyword list containing a :fingerprint
key, that fingerprint value will be
set along with the user id as the persistent session value as
{user_id, session_fingerprint: fingerprint}
.
Example
defmodule MyAppWeb.Endpoint do
# ...
plug Pow.Plug.Session, otp_app: :my_app
plug PowPersistentSession.Plug.Cookie
#...
end
Configuration options
:persistent_session_store
- seePowPersistentSession.Plug.Base
:cache_store_backend
- seePowPersistentSession.Plug.Base
:persistent_session_cookie_key
- session key name. This defaults to "persistent_session_cookie". If:otp_app
is used it'll automatically prepend the key with the:otp_app
value.:persistent_session_ttl
- used for both backend store and max age for cookie. SeePowPersistentSession.Plug.Base
for more.
Link to this section Summary
Functions
Authenticates a user with the persistent session cookie.
Sets a persistent session cookie with an auto generated token.
Expires the persistent session cookie.
Link to this section Functions
authenticate(conn, config)
View Sourceauthenticate(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
Authenticates a user with the persistent session cookie.
If a persistent session cookie exists, it'll fetch the credentials from the persistent session cache, and create a new session and persistent session cookie. The old persistent session cookie and session cache credentials will be removed.
If a :session_fingerprint
is fetched from the persistent session metadata,
it'll be assigned to the private :pow_session_metadata
key in the conn as
:fingerprint
.
The cookie expiration will automatically be renewed on every request.
call(conn, config)
View Sourcecall(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
create(conn, user, config)
View Sourcecreate(Plug.Conn.t(), map(), Pow.Config.t()) :: Plug.Conn.t()
Sets a persistent session cookie with an auto generated token.
The token is set as a key in the persistent session cache with the id fetched from the struct.
If an assigned private :pow_session_metadata
key exists in the conn with a
keyword list containing a :fingerprint
value, then that value will be set
as the :session_fingerprint
in the metadata. The value will look like:
{user_id, session_fingerprint: fingerprint}
The unique cookie id will be prepended by the :otp_app
configuration
value, if present.
delete(conn, config)
View Sourcedelete(Plug.Conn.t(), Pow.Config.t()) :: Plug.Conn.t()
Expires the persistent session cookie.
If a persistent session cookie exists it'll be expired, and the token in the persistent session cache will be deleted.