Hi ElixirForum,
I was looking for a library to help me implement authorization in a principled way, and looking around, I liked the simplicity of authorize, but I wanted to try out my own variation on the theme.
So yesterday I published auval_office, a flexible AUthorization policy eVALuator.
What’s in the box?
When you define a policy module like this:
defmodule My.Policy
use AuvalOffice.Policy
rule ...
rule ...
rule ...
end
then auval_office will augment your policy with an authorize function:
case My.Policy.authorize(subject, object, action) do
{:ok, rule_id, parameters} -> # allowed
{:error, rule_id, parameters} -> # not allowed
end
What’s different from other authorization packages?
-
auval_officeis self-contained.It has no dependency on
phoenixorecto. It includes no plug for your web pipeline. You decide if authorization should be a domain responsiblity or a web layer responsibility, and where authorization-related data should be stored. -
auval_officedoes not favor one access control model.It is flexible enough to implement lots of different access-control schemes, but favors none of them. I believe it offers enough flexibility to implement Role-Based Access Control (RBAC), Attribute-Based Access Control (ABAC) and Access Control Lists (ACLs), and combinations of those models.
-
auval_officejustifies its decisions.The return value of the
authorizefunction includes the ID of therulethat made the decision, and you can return parameters from the rule to augment that information. This enables the user to build historical audit trails, answering questions like “Who changed that data, and why was that allowed at the time?” -
auval_officecan consider context.The
authorizefunction has an optionalcontextparameter, where you can provide a map of additional information items to consider when making an authorization decision:My.Policy.authorizer(subject, object, action, %{moon_in_house: :seventh})auval_officealso includes afetcher facility, that enables you to fetch necessary context values at authorization time. Just include afetchin your policy:defmodule My.Policy do use AuvalOffice.Policy fetch :fetch_user_group_memberships, :groups, subject: %User{id: id} do groups = Accounts.get_groups_by_user_id(id) {:ok, groups} end rule ... endBefore evaluating the policy,
auval_officewill check if a:groupsitem is present in the context, and if not, will call the fetcher you defined to add the:groupsto the context.




















