Packages
charon
2.7.2
4.3.0
4.3.0-beta1
4.2.0
4.2.0-beta3
4.2.0-beta2
4.2.0-beta1
4.1.0
4.0.1
4.0.0
4.0.0-beta3
4.0.0-beta2
4.0.0-beta1
3.4.1
3.4.0
3.3.0
3.2.0
3.1.1
3.1.0
3.0.3
3.0.2
3.0.1
3.0.0
3.0.0-beta1
2.8.0
2.8.0-beta1
2.7.3
2.7.2
2.7.1
2.7.0
2.6.1
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.2.0-beta
2.1.3
2.1.2
2.1.2-beta
2.1.1
2.1.0
2.0.0
1.3.4
1.3.3
1.3.2-beta
1.3.1-beta
1.3.0-beta
1.2.0-beta
1.1.0-beta
1.0.1-beta
1.0.0-beta1
0.0.4-alpha
0.0.3-alpha
0.0.2-alpha
0.0.1-alpha
Authentication & sessions for API's.
Current section
Files
Jump to
Current section
Files
lib/charon/session_store/behaviour.ex
defmodule Charon.SessionStore.Behaviour do
@moduledoc """
Behaviour definition of a persistent session store.
Clients should not use the implementation directly, but should use `Charon.SessionStore`.
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.
Implementations should return the session exactly as it went in
(they don't have to take care of struct version upgrades).
Implementations should handle cleanup of expired entries,
but may define additional functions and instructions to take care of such things
(like a `cleanup/0` that should run periodically).
"""
alias Charon.Session
alias Charon.Config
@optional_callbacks [get_all: 3, delete_all: 3]
@doc """
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.
"""
@callback delete(
session_id :: binary,
user_id :: binary | integer(),
type :: atom(),
config :: Config.t()
) ::
:ok | {:error, binary}
@doc """
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.
"""
@callback upsert(session :: Session.t(), config :: Config.t()) :: :ok | {:error, binary}
@doc """
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.
"""
@callback get(
session_id :: binary,
user_id :: binary | integer(),
type :: atom(),
config :: Config.t()
) ::
Session.t() | nil | {:error, binary}
@doc """
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 get_all(user_id :: binary | integer, type :: atom(), config :: Config.t()) ::
[Session.t()] | {:error, binary}
@doc """
Delete all sessions of type `type` for the user with id `user_id`.
"""
@callback delete_all(user_id :: binary | integer, type :: atom(), config :: Config.t()) ::
:ok | {:error, binary}
end