Openmaize.Config

This module provides an abstraction layer for configuration. The following are valid configuration items.

nametypedefault
user_modelmoduleN/A
repomoduleN/A
crypto_modatom:bcrypt
token_algatom:sha512
keyrotate_daysint28
login_dirstring“/admin”
redirect_pagesmap%{“admin” => “/admin”, nil => “/“}
protectedmap%{“/admin” => ["admin"]}

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,
  crypto_mod: :bcrypt,
  token_alg: :sha256,
  keyrotate_days: 7,
  login_dir: "admin",
  redirect_pages: %{"admin" => "/admin", "user" => "/users", nil => "/"},
  protected: %{"/admin" => ["admin"], "/users" => ["admin", "user"], "/users/:id" => ["user"]}

Summary

Functions

The password hashing and checking algorithm. You can choose between bcrypt and pbkdf2_sha512. Bcrypt is the default

The algorithm used to sign the token

The number of days after which the keys will be rotated

The login directory. For example, the default value of “/admin” means that the login page is “/admin/login”

Paths that should be protected. This is a map associating each path with a role

The pages users should be redirected to after logging in. This is a map where the key is the role of the user and the value is the page to be redirected to

The repo name

The user model name

Functions

get_crypto_mod()

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.

get_token_alg()

The algorithm used to sign the token.

The default value is :sha512, and :sha256 is also supported.

keyrotate_days()

The number of days after which the keys will be rotated.

login_dir()

The login directory. For example, the default value of “/admin” means that the login page is “/admin/login”.

protected()

Paths that should be protected. This is a map associating each path with a role.

The path is the start of the path. For example, “/users” refers to all paths that start with “/users”.

redirect_pages()

The pages users should be redirected to after logging in. This is a map where the key is the role of the user and the value is the page to be redirected to.

If there is no role, the user will be redirected to the home page.

repo()

The repo name.

user_model()

The user model name.