Ekaitz Zárraga 👹 is a user on mastodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Ekaitz Zárraga 👹 @ekaitz_zarraga

So many random doubts about the Authorization in my web application I'm making in .

I'm using Buddy to handle the auth stuff. And I'm making a template based website, no SPA, and the auth handled in the sessions.

I know how to create users and check if they are authenticated.

The problem I see now is how should I handle the authorization? should I store the Role of the user in the session too (in the login step)? Or is that a bad choice?

· Web · 0 · 0

If I don't do that, I had to check the role in the db in the middleware... and... I don't like that for *reasons*

@ekaitz_zarraga @yabirgb Couple of resources explaining why JWT are not the best idea for sessions: cryto.net/~joepie91/blog/2016/ and developer.okta.com/blog/2018/0 The latter contains some advertising of the company writing the post, but it's not bad.

@ekaitz_zarraga I personally don't like jwt but for some situations they are good. Also they appeared in a blog post that you shared before. Storing the role and sending it is not safe and shouldn't be trusted (as far as I know)

@yabirgb That's why I want to store the whole thing on the session of the app. That's not sent to the client (is it?) so I can handle cool things there (in-memory) and check them when a new query arrives.

The app is not a SPA so I can't control the tokens sent. That's why I avoided them.

@ekaitz_zarraga @yabirgb I tend to user either memory session or something like Redis in such cases. These are never sent to the client being inherently safer than cookie based sessions in my view.

Swapping in different implementations is very easy since it's a protocol, so I'd start with a memory session as the default.

I think storing the role in the session is fine as well, here's an example of role based auth in one of my apps github.com/yogthos/memory-hole

@yogthos @yabirgb Yeah, and how to do that without Redis? By default ring sessions are handled in-memory too, right?
So... using buddy and simply storing the role in the session is enough...?
can I put {:user id :role role} in the identity directly?

@ekaitz_zarraga @yabirgb yeah memory store should be the default, and yeah just adding something like {:uderid id :role role} to the sesssion is pretty standard.