We use JWT to send bunch of public claims around, one of which is session_id which refers to session in backend cache. Are we doing it wrong?
We use JWT to send bunch of public claims around, one of which is session_id which refers to session in backend cache. Are we doing it wrong?
The article doesn't offer much of a solution either.
The only valid criticism I see in these threads are unless you are tracking a revoke list then the JWT is still valid on a user initiated logout until it expires.
If you're going to roll your own tokens you're probably going to end up some form of tamper proof encryption even if you're storing additional session information on the backend.
Without specific comparison to other styles of session management this is just all FUD to me.
If you want a session, just use an opaque session cookie. Then all information is safely handled in the server.
While it's certainly technically possible to use a JWT like a session cookie (or store session information in it), what you then get is a solution that combines the disadvantages of both approaches: All the complexity of making "visible" client-handled information safe, with the additional overhead of also having it in the server, while you loose the advantages of a JWT in integrating third-party services.
So, either use one, or use the other, depending on your requirements. Don't combine them.
a) Store sessionId as a cookie on the browser, pull all details on backend from cache server - requires network call every time when any tiny user detail is needed, not a showstopped and it worked for us for quite a while but we wanted something more convenient.
b) Fully stateless backend, keep entire session in JWT - our user's session is on the huge, plus user's session has private data (we declined this option rather quickly)
Instead we ended up with JWT which contains sessionId + bunch of most commonly accessed user properties (various identifiers, roles, login time, etc).
Now it seems like that somehow I missed this "JWT means stateless" thingy, well, let's see what people say.
It's a fintech consumer website (sorry, can't disclose the name).
But if you're statefully storing sessions anyway...