Packages
phauxth
1.0.0
2.5.1
retired
2.5.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.0
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
2.0.0-beta.1
2.0.0-beta.0
2.0.0-alpha.5
2.0.0-alpha.4
retired
2.0.0-alpha.3
retired
2.0.0-alpha.2
retired
2.0.0-alpha.1
retired
2.0.0-alpha.0
retired
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.17.1
0.17.0
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0-rc.1
0.13.0-rc.0
0.12.1-rc.1
0.12.1-rc.0
0.12.0-rc
0.11.0
0.10.3
0.10.2
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
Authentication library for Phoenix, and other Plug-based, web applications
Current section
Files
Jump to
Current section
Files
lib/phauxth/config.ex
defmodule Phauxth.Config do
@moduledoc """
This module provides an abstraction layer for configuration.
The following are valid configuration items.
| name | type | default |
| :----------------- | :----------- | ---------------: |
| log_level | atom | :info |
| drop_user_keys | list of atoms | [] |
| endpoint | module | N/A |
| token_salt | string | N/A |
## Examples
The simplest way to change the default values would be to add
a `phauxth` entry to the `config.exs` file in your project,
like the following example.
config :phauxth,
endpoint: MyAppWeb.Endpoint,
log_level: :warn,
drop_user_keys: [:shoe_size]
"""
@doc """
The log level for Phauxth logs.
This should either be an atom, :debug, :info, :warn or :error, or
false.
The default is :info, which means that :info, :warn and :error logs
will be returned.
"""
def log_level do
Application.get_env(:phauxth, :log_level, :info)
end
@doc """
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, :password and :otp_secret are removed,
and this option allows you to add to this list.
"""
def drop_user_keys do
Application.get_env(:phauxth, :drop_user_keys, []) ++
[:password_hash, :password, :otp_secret]
end
@doc """
The endpoint of your app.
This is used by the Phauxth.Confirm module.
"""
def endpoint do
Application.get_env(:phauxth, :endpoint) || raise """
You need to set the `endpoint` value in the config/config.exs file.
"""
end
@doc """
The salt to be used when creating and verifying tokens.
"""
def token_salt do
Application.get_env(:phauxth, :token_salt) || raise """
You need to set the `token_salt` value in the config/config.exs file.
To generate a suitable random salt, use the `gen_token_salt` function
in the Phauxth.Config module.
"""
end
@doc """
Generate a random salt for use with token authentication.
"""
def gen_token_salt(length \\ 8)
def gen_token_salt(length) when length > 7 do
:crypto.strong_rand_bytes(length) |> Base.encode64 |> binary_part(0, length)
end
def gen_token_salt(_) do
raise ArgumentError, """
The length is too short. The token_salt should be at least 8 characters long.
"""
end
end