Nova Auth

Authentication library for the Nova ecosystem.

Provides a unified actor session, claims mapping, authorization policies, and optional password-based authentication. Works standalone or as the foundation for nova_auth_oidc.

Features

Quick Start

Add nova_auth to your deps:

{deps, [
{nova_auth, {git, "https://github.com/Taure/nova_auth.git", {branch, "main"}}}
]}.

OIDC-only (no database)

If you only need actor sessions and policies (e.g., with nova_auth_oidc):

%% Protect routes -- works with any auth strategy that stores an actor
#{prefix => ~"/dashboard",
security => nova_auth_security:require_authenticated(),
routes => [
{~"/profile", fun my_controller:profile/1, #{methods => [get]}}
]}
%% Access actor in controller
profile(#{auth_data := Actor} = _Req) ->
Email = maps:get(email, Actor, ~"unknown"),
{json, #{email => Email}}.

Password auth (requires Kura)

Create a config module implementing the nova_auth behaviour:

-module(my_auth).
-behaviour(nova_auth).
-export([config/0]).
config() ->
#{
repo => my_repo,
user_schema => my_user,
token_schema => my_user_token
}.

Register and authenticate:

%% Register
{ok, User} = nova_auth_accounts:register(
my_auth, fun my_user:registration_changeset/2, Params
).
%% Authenticate and store actor in session
{ok, User} = nova_auth_accounts:authenticate(my_auth, ~"user@example.com", ~"password123456").
ok = nova_auth_actor:store(Req, #{id => maps:get(id, User), provider => password, email => maps:get(email, User)}).
%% Session token (database-backed)
{ok, Token} = nova_auth_session:generate_session_token(my_auth, User).

Modules

Core (no dependencies beyond Nova)

ModuleDescription
nova_auth_actorStore/fetch actor maps from Nova session
nova_auth_claimsTransform provider claims to actor maps
nova_auth_securityRoute-level security callbacks
nova_auth_policyAuthorization policies for nova_resource
nova_auth_rate_limitRate limiting Nova plugin

Password auth (requires Kura)

ModuleDescription
nova_auth_accountsRegistration, authentication, password/identity changes
nova_auth_sessionDatabase-backed session token management
nova_auth_passwordPBKDF2-SHA256 password hashing
nova_auth_tokenToken generation and validation
nova_auth_confirmEmail confirmation flow
nova_auth_resetPassword reset flow

Configuration

Password auth options (all optional with defaults):

OptionDefaultDescription
repo--Kura repo module (required for password auth)
user_schema--Kura user schema module
token_schema--Kura token schema module
user_identity_fieldemailField used for login lookup
user_password_fieldhashed_passwordField storing the password hash
session_validity_days14Days before session tokens expire
confirm_validity_days3Days before confirmation tokens expire
reset_validity_hours1Hours before reset tokens expire
hash_algorithmpbkdf2_sha256Password hashing algorithm
token_bytes32Random bytes for token generation

Guides

Requirements

License

MIT