Phauxth v2.0.0-alpha.1 Phauxth.Config View Source

This module provides an abstraction layer for configuration.

The following are valid configuration items.

nametypedefault
session_modulemoduleN/A
log_levelatom:info
drop_user_keyslist of atoms[]
user_messagesmodulePhauxth.UserMessages
endpointmoduleN/A
token_modulemoduleN/A
token_saltstringN/A

Umbrella apps

Due to how the configuration is handled in umbrella apps, you might need to override the token_salt and endpoint values when using them in the sub-apps.

The example below shows how the token can be generated this way:

Phauxth.Token.sign(data, endpoint: MyAppWeb.Endpoint, token_salt: "somesalt")

And this example shows how the Phauxth.Confirm.verify function needs to be called:

Phauxth.Confirm.verify(params, [
  session_module: MyApp.Sessions,
  endpoint: MyAppWeb.Endpoint,
  token_salt: "somesalt"
])

Examples

Add a phauxth entry to the config.exs file in your project, as in the following example.

config :phauxth,
  session_module: MyApp.Sessions,
  token_salt: "YkLmt7+f",
  endpoint: MyAppWeb.Endpoint,
  log_level: :warn,
  drop_user_keys: [:shoe_size]

Link to this section Summary

Functions

The keys that are removed from the user struct before it is passed on to another function

The endpoint of your app

Generates a random salt for use with token authentication

The log level for Phauxth logs

The sessions module to be used when querying the database

The module used to sign and verify tokens

The salt to be used when creating and verifying tokens

Module to be used to display messages to users

Link to this section Functions

The keys that are removed from the user struct before it is passed on to another function.

This should be a list of atoms.

By default, :password_hash, :encrypted_password, :password and :otp_secret are removed, and this option allows you to add to this list.

The endpoint of your app.

This is used by the Phauxth.Confirm module.

Link to this function gen_token_salt(length \\ 8) View Source

Generates a random salt for use with token authentication.

The log level for Phauxth logs.

This can be false, :debug, :info, :warn or :error.

The default is :info, which means that :info, :warn and :error logs will be returned.

The sessions module to be used when querying the database.

This module needs to have a get_by(attrs) function defined, which is the used to fetch the relevant data.

The module used to sign and verify tokens.

This module must implement the Phauxth.Token behaviour. See Phauxth.PhxToken for an example token module.

The salt to be used when creating and verifying tokens.

This is used by the Phauxth.Authenticate module, if you are using token authentication, and by the Phauxth.Confirm module.

Module to be used to display messages to users.

The default is Phauxth.UserMessages. See the documentation for Phauxth.UserMessages.Base for details about customizing / translating these messages.