Role-based and Access-based Authorization in Phoenix controller

I am currently working on an Elixir application and I would like to implement role-based and access-based authorization. In Spring Security, there is a convenient syntax using the @PreAuthorize annotation. However, I couldn’t find a similar syntax in Elixir. Are there any libraries or approaches that can help me achieve this kind of authorization in Elixir?

In Spring Security, I could use @PreAuthorize("hasRole('ROLE_ADMIN')") to restrict access to certain roles. Is there a comparable way to achieve this in Elixir, perhaps with a similar syntax? For example, something like @security(roles: [:admin] or privileges: [:write]).

I would appreciate any guidance on how to implement role-based and access-based authorization in Elixir, along with any recommended libraries or approaches. Thank you.

i looked into this recently. i ended up using Canada because it’s simple and just what i need. but Canary does more what you asked for.

there’s a few more options, but watch out for abandoned libraries!

In addition to Canada and Canary, Bodyguard and LetMe are worth mentioning. Although the latter was written by me, so I might be biased.