Packages
openmaize
0.15.0
3.0.1
retired
3.0.0
2.9.0
2.8.0
2.7.0
2.6.0
2.5.1
2.5.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
1.0.1
1.0.0
1.0.0-beta.5
1.0.0-beta.4
1.0.0-beta.3
1.0.0-beta.2
1.0.0-beta.1
1.0.0-beta.0
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0
0.12.0
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.8.1
0.8.0
0.7.5
0.7.4
0.7.2
0.7.1
0.7.0
0.6.7
0.6.6
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.1
0.4.0
Authentication library for Elixir using Plug
Current section
Files
Jump to
Current section
Files
lib/openmaize/config.ex
defmodule Openmaize.Config do
@moduledoc """
This module provides an abstraction layer for configuration.
The following are valid configuration items.
| name | type | default |
| :----------------- | :------ | -------: |
| user_model | module | N/A |
| repo | module | N/A |
| hash_name | atom | :password_hash |
| crypto_mod | atom | :bcrypt |
| token_alg | atom | :sha512 |
| keyrotate_days | int | 28 |
| redirect_pages | map | %{"admin" => "/admin", "login" => "/login", "logout" => "/"} |
The values for user_model and repo should be module names.
If, for example, your app is called Coolapp and your user
model is called User, then `user_model` should be
Coolapp.User and `repo` should be Coolapp.Repo.
## Examples
The simplest way to change the default values would be to add
the following to the `config.exs` file in your project.
config :openmaize,
user_model: Coolapp.User,
repo: Coolapp.Repo,
hash_name: :encrypted_password,
crypto_mod: :pbkdf2,
token_alg: :sha256,
keyrotate_days: 7,
redirect_pages: %{"admin" => "/admin", "login" => "/admin/login", "logout" => "/admin/login"}
"""
@doc """
The user model name.
"""
def user_model do
Application.get_env(:openmaize, :user_model)
end
@doc """
The repo name.
"""
def repo do
Application.get_env(:openmaize, :repo)
end
@doc """
The name in the database for the password hash.
"""
def hash_name do
Application.get_env(:openmaize, :hash_name, :password_hash)
end
@doc """
The password hashing and checking algorithm. You can choose between
bcrypt and pbkdf2_sha512. Bcrypt is the default.
For more information about these two algorithms, see the documentation
for Comeonin.
"""
def get_crypto_mod do
case crypto_mod do
:pbkdf2 -> Comeonin.Pbkdf2
_ -> Comeonin.Bcrypt
end
end
defp crypto_mod do
Application.get_env(:openmaize, :crypto_mod, :bcrypt)
end
@doc """
The algorithm used to sign the token.
The default value is :sha512, and :sha256 is also supported.
"""
def get_token_alg do
case token_alg do
:sha256 -> {"HS256", :sha256}
_ -> {"HS512", :sha512}
end
end
defp token_alg do
Application.get_env(:openmaize, :token_alg, :sha512)
end
@doc """
The number of days after which the JWT signing keys will be rotated.
"""
def keyrotate_days do
Application.get_env(:openmaize, :keyrotate_days, 28)
end
@doc """
The pages users should be redirected to after logging in or if there
is an error.
This is a map where the key is the role of the user and the value is
the page to be redirected to.
## Redirects for login and logout
The "login" key refers to the login page that unauthorized users should
be redirected to. The default value is "/login".
The "logout" key refers to the page users should be redirected to after
logging out. The default value is "/".
"""
def redirect_pages do
Map.merge(%{"login" => "/login", "logout" => "/"},
Application.get_env(:openmaize, :redirect_pages, %{"admin" => "/admin"}))
end
end