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 variales.

-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_value(binary(),term(),term()) -> term().

Gets session variable from session storage.

set_value(binary(),term(),term()) -> term().

Sets session variable to session storage.

storage() -> atom().

Returns current sessions backend. n2o_session by default.

prolongate() -> boolean().

Returns nitro_prolongate n2o parameter. false by default.

BACKEND

clear(binary()) -> ok.

Clears all session ovariables by session sid.

update(session()) -> ok.

Updates session.

delete(session_key()) -> ok.

Removes session by key.

lookup(session_key()) -> ok.

Lookups session by key.

invalidate_sessions() -> ok.

Removes all expired variables across all sessions.

You may also want to read: n2o_nitro, n2o.