View Source Charon.SessionStore.Behaviour behaviour (Charon v2.1.1)

Behaviour definition of a persistent session store. The implementation is expected to handle cleanup of expired entries.

Implementations are expected to store sessions by ID, user ID and session type. For the optional callbacks get_all/3 and delete_all/3, sessions should be retrievable by user ID and session type only.

Link to this section Summary

Callbacks

Delete session of type type with id session_id for user with id user_id.

Delete all sessions of type type for the user with id user_id.

Get session of type type with id session_id for user with id user_id. Must not return sessions that have expired, or that can't be refreshed anymore because the refresh token has expired.

Get all sessions of type type for the user with id user_id. Must not return sessions that have expired, or that can't be refreshed anymore because the refresh token has expired.

Insert or update session.

Link to this section Callbacks

Link to this callback

delete(session_id, user_id, type, config)

View Source
@callback delete(
  session_id :: binary(),
  user_id :: binary() | integer(),
  type :: atom(),
  config :: Charon.Config.t()
) :: :ok | {:error, binary()}

Delete session of type type with id session_id for user with id user_id.

Implementations may choose to ignore user_id, since session_id is unique by itself.

Link to this callback

delete_all(user_id, type, config)

View Source (optional)
@callback delete_all(
  user_id :: binary() | integer(),
  type :: atom(),
  config :: Charon.Config.t()
) :: :ok | {:error, binary()}

Delete all sessions of type type for the user with id user_id.

Link to this callback

get(session_id, user_id, type, config)

View Source
@callback get(
  session_id :: binary(),
  user_id :: binary() | integer(),
  type :: atom(),
  config :: Charon.Config.t()
) :: Charon.Session.t() | nil | {:error, binary()}

Get session of type type with id session_id for user with id user_id. Must not return sessions that have expired, or that can't be refreshed anymore because the refresh token has expired.

Implementations may choose to ignore user_id, since session_id is unique by itself.

Link to this callback

get_all(user_id, type, config)

View Source (optional)
@callback get_all(
  user_id :: binary() | integer(),
  type :: atom(),
  config :: Charon.Config.t()
) :: [Charon.Session.t()] | {:error, binary()}

Get all sessions of type type for the user with id user_id. Must not return sessions that have expired, or that can't be refreshed anymore because the refresh token has expired.

@callback upsert(session :: Charon.Session.t(), config :: Charon.Config.t()) ::
  :ok | {:error, binary()}

Insert or update session.

Values session_id, user_id and type are taken from the session struct. Implementations may choose to ignore user_id, since session_id is unique by itself.