Auctoritas v0.2.5 Auctoritas.AuthenticationManager View Source
AuthenticationManager
Manages Auctoritas Authentication GenServer
Link to this section Summary
Types
Token expiration in seconds
Name from config (Auctoritas supervisor name)
Authentication token
Functions
Authenticate with supplied arguments to default authentication_manager;
- authentication_data is checked and then used to generate token
- data is stored inside data_storage with token as the key
Authenticate with supplied arguments to custom authentication_manager;
- authentication_data is checked and then used to generate token
- data is stored inside data_storage with token as the key
Returns a specification to start this module under a supervisor
Deauthenticate supplied token from default authentication_manager
Deauthenticate supplied token from custom authentication_manager
Get associated token data;
Get associated token data;
Invoked when the server is started. start_link/3
or start/3
will
block until it returns
Alternative to authenticate(authentication_data, data)
Alternative to authenticate(name, authentication_data, data)
Alternative to logout(token)
Alternative to logout(name, token)
Start Auctoritas GenServer with specified config (from Auctoritas.Config
)
Link to this section Types
expiration()
View Source
expiration() :: non_neg_integer()
expiration() :: non_neg_integer()
Token expiration in seconds
name()
View Source
name() :: String.t()
name() :: String.t()
Name from config (Auctoritas supervisor name)
token()
View Source
token() :: String.t()
token() :: String.t()
Authentication token
Link to this section Functions
authenticate(authentication_data, data) View Source
Authenticate with supplied arguments to default authentication_manager;
- authentication_data is checked and then used to generate token
- data is stored inside data_storage with token as the key
Examples
iex> Auctoritas.AuthenticationManager.authenticate(%{username: "username"}, %{user_id: 1})
{:ok, "ec4eecaff1cc7e9daa511620e47203424e70b9c9785d51d11f246f27fab33a0b"}
authenticate(name, authentication_data, data) View Source
Authenticate with supplied arguments to custom authentication_manager;
- authentication_data is checked and then used to generate token
- data is stored inside data_storage with token as the key
Examples
iex> Auctoritas.AuthenticationManager.authenticate("custom_name", %{username: "username"}, %{user_id: 1})
{:ok, "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633"}
child_spec(arg) View Source
Returns a specification to start this module under a supervisor.
See Supervisor
.
deauthenticate(token) View Source
Deauthenticate supplied token from default authentication_manager
Examples
iex> Auctoritas.AuthenticationManager.authenticate(%{username: "username"}, %{user_id: 1})
{:ok, "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633"}
iex> Auctoritas.AuthenticationManager.deauthenticate("0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633")
{:ok, true}
deauthenticate(name, token) View Source
Deauthenticate supplied token from custom authentication_manager
Examples
iex> Auctoritas.AuthenticationManager.authenticate("custom_name", %{username: "username"}, %{user_id: 1})
{:ok, "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633"}
iex> Auctoritas.AuthenticationManager.deauthenticate("custom_name", "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633")
{:ok, true}
get_token_data(token) View Source
Get associated token data;
Examples
iex> Auctoritas.AuthenticationManager.authenticate(%{username: "username"}, %{user_id: 1})
{:ok, "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633"}
iex> Auctoritas.AuthenticationManager.get_token_data("0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633")
{:ok,
%Auctoritas.AuthenticationManager.DataStorage.Data{
data: %{user_id: 1},
metadata: %{
expires_in: 86310242,
inserted_at: 1547201115,
updated_at: 1547201115
}
}}
get_token_data(name, token) View Source
Get associated token data;
Examples
iex> Auctoritas.AuthenticationManager.authenticate("custom_name", %{username: "username"}, %{user_id: 1})
{:ok, "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633"}
iex> Auctoritas.AuthenticationManager.get_token_data("custom_name", "0a0c820b3640bca38ec482da31510803e369e7b90dfc01cb1e571b7970b02633")
{:ok,
%Auctoritas.AuthenticationManager.DataStorage.Data{
data: %{user_id: 1},
metadata: %{
expires_in: 86310242,
inserted_at: 1547201115,
updated_at: 1547201115
}
}}
get_tokens(start, amount) View Source
get_tokens(name, start, amount) View Source
get_tokens_with_data(start, amount) View Source
get_tokens_with_data(name, start, amount) View Source
init(config) View Source
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
args
is the argument term (second argument) passed to start_link/3
.
Returning {:ok, state}
will cause start_link/3
to return
{:ok, pid}
and the process to enter its loop.
Returning {:ok, state, timeout}
is similar to {:ok, state}
except handle_info(:timeout, state)
will be called after timeout
milliseconds if no messages are received within the timeout.
Returning {:ok, state, :hibernate}
is similar to {:ok, state}
except the process is hibernated before entering the loop. See
c:handle_call/3
for more information on hibernation.
Returning {:ok, state, {:continue, continue}}
is similar to
{:ok, state}
except that immediately after entering the loop
the c:handle_continue/2
callback will be invoked with the value
continue
as first argument.
Returning :ignore
will cause start_link/3
to return :ignore
and
the process will exit normally without entering the loop or calling
c:terminate/2
. If used when part of a supervision tree the parent
supervisor will not fail to start nor immediately try to restart the
GenServer
. The remainder of the supervision tree will be started
and so the GenServer
should not be required by other processes.
It can be started later with Supervisor.restart_child/2
as the child
specification is saved in the parent supervisor. The main use cases for
this are:
- The
GenServer
is disabled by configuration but might be enabled later. - An error occurred and it will be handled by a different mechanism than the
Supervisor
. Likely this approach involves callingSupervisor.restart_child/2
after a delay to attempt a restart.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without
entering the loop or calling c:terminate/2
.
Callback implementation for GenServer.init/1
.
login(authentication_data, data) View Source
Alternative to authenticate(authentication_data, data)
login(name, authentication_data, data) View Source
Alternative to authenticate(name, authentication_data, data)
logout(token) View Source
Alternative to logout(token)
logout(name, token) View Source
Alternative to logout(name, token)
start_link(config) View Source
Start Auctoritas GenServer with specified config (from Auctoritas.Config
)