alichoopani

alichoopani

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.

Most Liked

woylie

woylie

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

KristerV

KristerV

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!

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New

We're in Beta

About us Mission Statement