Pow v1.0.21 Pow.Store.CredentialsCache behaviour View Source
Default module for credentials session storage.
A key (session id) is used to store, fetch, or delete credentials. The
credentials are expected to take the form of
{credentials, session_metadata}
, where session metadata is data exclusive
to the session id.
This module also adds two utility methods:
users/2
- to list all current userssessions/2
- to list all current sessions
Custom credentials cache module
Pow may use the utility methods in this module. To ensure all required
methods has been implemented in a custom credentials cache module, the
@behaviour
of this module should be used:
defmodule MyApp.CredentialsStore do
use Pow.Store.Base,
ttl: :timer.minutes(30),
namespace: "credentials"
@behaviour Pow.Store.CredentialsCache
@impl Pow.Store.CredentialsCache
def users(config, struct) do
# ...
end
@impl Pow.Store.CredentialsCache
def put(config, key, value) do
# ...
end
end
Link to this section Summary
Functions
Delete the user credentials data from the backend store.
Fetch user credentials from the backend store from session id.
Add user credentials with the session id to the backend store.
List all existing sessions for the user fetched from the backend store.
List all user for a certain user struct.
Link to this section Functions
backend_config(config)
View Sourcebackend_config(Pow.Store.Base.config()) :: Pow.Store.Base.config()
Delete the user credentials data from the backend store.
This following two key-value will be deleted:
{session_id, {[user_struct, :user, user_id], metadata}}
{[user_struct, :user, user_id, :session, session_id], inserted_at}
The {[user_struct, :user, user_id], user}
key-value is expected to expire
when reaching its TTL.
get(config, key)
View Sourceget(Pow.Store.Base.config(), binary()) :: {map(), list()} | :not_found
Fetch user credentials from the backend store from session id.
put(config, key, value)
View Sourceput(Pow.Store.Base.config(), binary(), {map(), list()}) :: :ok
Add user credentials with the session id to the backend store.
The credentials are expected to be in the format of
{credentials, metadata}
.
This following three key-value will be inserted:
{session_id, {[user_struct, :user, user_id], metadata}}
{[user_struct, :user, user_id], user}
{[user_struct, :user, user_id, :session, session_id], inserted_at}
If metadata has :fingerprint
any active sessions for the user with the same
:fingerprint
in metadata will be deleted.
sessions(config, user)
View Sourcesessions(Pow.Store.Base.config(), map()) :: [binary()]
List all existing sessions for the user fetched from the backend store.
users(config, struct)
View Sourceusers(Pow.Store.Base.config(), module()) :: [any()]
List all user for a certain user struct.
Sessions for a user can be looked up with sessions/3
.
Link to this section Callbacks
put(arg1, binary, {})
View Sourceput(Pow.Store.Base.config(), binary(), {map(), list()}) :: :ok
sessions(arg1, map)
View Sourcesessions(Pow.Store.Base.config(), map()) :: [binary()]
users(arg1, module)
View Sourceusers(Pow.Store.Base.config(), module()) :: [any()]