Current section

Files

Jump to
blossom lib blossom auth.ex
Raw

lib/blossom/auth.ex

defmodule Blossom.Auth do
alias Blossom.{Auth, Passwords, Utils}
alias Blossom.Builders.Auth, as: Builder
def issuer(config, opts, otp_app) do
Utils.option_or_key_config(config, opts, :issuer, otp_app)
end
def min_length(config, opts) do
Utils.option_or_key_config(config, opts, :min_length, 8)
end
def password_opts(opts, otp_app) do
config = Application.get_env(otp_app, Blossom, [])
%{
min_length: Auth.min_length(config, opts)
}
end
def token_opts(opts, otp_app) do
config = Application.get_env(otp_app, Blossom, [])
%{
audience: Utils.audience(config, opts, otp_app),
expiration: Utils.expiration(config, opts),
issuer: Auth.issuer(config, opts, otp_app),
secret: Utils.secret(config, opts)
}
end
defmacro __using__(opts \\ []) do
quote do
@opts unquote(opts)
@caller unquote(__CALLER__.module)
@name KilnCore.Utils.atom_name(@caller)
def validate_new_password(password) do
Passwords.validate(password, Auth.password_opts(@opts, @name))
end
def login(user, password) do
Builder.login(user, password, Auth.token_opts(@opts, @name))
end
def generate_password() do
Passwords.generate(Auth.password_opts(@opts, @name))
end
end
end
end