SESSION

INTRO

The n2o_session module provides session variables protected by authorization token.

> ets:tab2list(cookies). [{{<<"05dcf467c79071008bc4">>,user},{63710034516,"maxim"}}, {{<<"05dcf467c79071008bc4">>,room},{63710034516,"n2o"}}, {{<<"05dcf467c79071008bc4">>,auth},{63710033891,[]}}]

TYPES

Session token represents tuple cached in ETS. It consists of session id, key, expiration time and value. Session token used both for auth and for session variables.

-type expires() :: integer(). -type session_sid() :: binary(). -type session_key() :: { session_sid() , term() }. -type session_val() :: { expires() , term() }. -type session() :: { session_key() , session_val() }.

Session token encoded with pickler tagged as 'Token' tuple.

-type token() :: { 'Token', binary() }.

API

authenticate([], binary()) -> token().

The protocol is following. If session is expired or session token is invalid then new session token issued. If session token is not expired and valid then two cases could happen: 1) if nitro_prolongate n2o parameter is true, then new expiration value is updated for current session, while session sid remains unchanged; 2) if nitro_prolongate is false then full session token remains unchanged.

Get session variable from session storage
get_value(binary(), term(), term()) -> term().
Set session variable to session storage
set_value(binary(), term(), term()) -> term().
Get current sessions backend. n2o_session by default
storage() -> atom().
Get nitro_prolongate n2o parameter. false by default
prolongate() -> boolean().

BACKEND

Clear all session variables by session sid
clear(binary()) -> ok.
Update session
update(session()) -> ok.
Remove session by key
delete(session_key()) -> ok.
Lookup session by key
lookup(session_key()) -> ok.
Remove all expired variables across all sessions
invalidate_sessions() -> ok.

You may also want to read: n2o_nitro, n2o.