Auctoritas v0.2.3 Auctoritas.AuthenticationManager View Source

AuthenticationManager

Manages Auctoritas Authentication GenServer

Link to this section Summary

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

Start Auctoritas GenServer with specified config (from Auctoritas.Config)

Link to this section Functions

Link to this function

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"}
Link to this function

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"}

Returns a specification to start this module under a supervisor.

See Supervisor.

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}
Link to this function

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 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
 }
}}
Link to this function

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
 }
}}
Link to this function

get_tokens(start, amount) View Source

Link to this function

get_tokens(name, start, amount) View Source

Link to this function

get_tokens_with_data(start, amount) View Source

Link to this function

get_tokens_with_data(name, start, amount) 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 calling Supervisor.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.

Link to this function

login(authentication_data, data) View Source

Link to this function

login(name, authentication_data, data) View Source

Start Auctoritas GenServer with specified config (from Auctoritas.Config)