RIG.Session (Reactive Interaction Gateway v3.0.0-alpha.2) View Source

A session is defined by a user's JWT.

Client connections with the same JWT are associated to the same session. That is, if a user uses the same JWT to connect to RIG multiple times (e.g., using multiple devices), all of those connections are associated to the same session.

Sessions can be blacklisted, which makes them illegal to use for a specified amount of time. Established connections related to a blacklisted session are terminated automatically.

By default, the session identifier within a JWT is the jti claim. You can change this using the JWT_SESSION_FIELD environment variable.

Link to this section Summary

Functions

Disallow sessions with the given name for a specific amount of time.

Check whether a session name has been disallowed.

Returns module configuration.

Infers the session name from JWT claims.

Associates a connection process to a session identifier.

Link to this section Types

Specs

session_name_t() :: String.t()

Specs

validity_period_t() :: pos_integer()

Link to this section Functions

Link to this function

blacklist(session_name, validity_period_s)

View Source

Specs

blacklist(session_name_t(), validity_period_t()) :: nil

Disallow sessions with the given name for a specific amount of time.

Link to this function

blacklisted?(session_name)

View Source

Specs

blacklisted?(session_name_t()) :: boolean()

Check whether a session name has been disallowed.

Specs

config() :: any()

Returns module configuration.

If application environment contains values in Keyword or Map struct, defaults from macro usage will be recursively merged with application configuration.

If one of the configuration parameters does not exist or can not be resolved, raises ArgumentError.

Specs

from_claims(claims :: map()) :: Result.t(session_name_t(), String.t())

Infers the session name from JWT claims.

  • claims: The JWT claims map. The claim used to identify a session in an authorization token is defined by the :jwt_session_field in the module configuration.
Link to this function

register_connection(session_name, connection_pid)

View Source

Specs

register_connection(session_name_t(), pid()) :: :ok

Associates a connection process to a session identifier.

  • session_name: If the session with the given name doesn't exist yet, it will be created.
  • pid: The client connection process. Once the associated session is terminated, this process will receive a {:session_killed, <session name>} message.