Authorization Library

Hi All.

I’m developing a Phoenix App where a logged on user can have one of three roles a, b, c. I’d like to restrict access to some controller functions e…g update, create but also have some functions e.g. list available to anyone. I’ve looked at Canada but even this seems too complex for my simple needs. I’ve also thought about using some sort of Plug but not quite sure where to start. So my questions. Is there a simple (plug) based library that would allow me to achieve me aims or a tutorial that might point me in the right direction. I’m sure I’m not the first to have such a requirement.

Any help gratefully received.

cheers

Dave

Canary is the most popular from this search. Building you own solution is pretty simple once you understand how to build a plug and protocols. Both are good things to know. If you have the time and want to learn Phoenix well, I suggest you try it your self.

Thanks @smpallen99. I should have done a bit more research (I keep forgetting about hex).

cheers

Dave

Here are a couple resources that may help in building your own. BTW, building plugs is very simple once you understand the basic concepts…

https://www.coshx.com/blog/2016/07/01/authorization-with-plug/
From this https://hackernoon.com/writing-a-blog-engine-in-phoenix-part-2-authorization-814c06fa7c0, review section “Restricting posting to users”

Also, keep in mind that you will need to plug your controllers, not your router if you want access to the action since action does not get resolved until after the router plug completes.

2 Likes

Wow the tutorial was absolutely perfect - Elixir and Phoenix keep blowing me away with how straight forward everything is.

thank you so much for the tip.

cheers
Dave

1 Like

@smpallen99 - just wanted to say thank you (again). In just over an hour I’ve built a plug based authorization system for my application (and that includes 10 minutes making my wife a coffee!!). It is pretty simple but importantly it fits my use case perfectly.

cheers

Dave

2 Likes

@shortlyportly Thanks for the feedback. Much appreciated. Glad your enjoying Elixir/Phoenix.

1 Like