vamsiikrishna

vamsiikrishna

Hello there !

In the application I am working on we have a user status in the user schema. If a user is marked as inactive , the user won’t be allowed to login. Now we have a requirment where in, as soon as a user is marked as inactive, we also want to force logout the user ( revoking the jwt ).
from what I have read , one can use the GitHub - ueberauth/guardian_db: Guardian DB integration for tracking tokens and ensuring logout cannot be replayed. · GitHub module to store active tokens and delete the same once we want to invalidate the token..

This sounds almost like using sessions ?
to be clear the library indeed says that if you are considering using it, you have to rethink about authorization .

is this the only way to invalidate the tokens ?

Showing Posts 1 to 10

chulkilee

chulkilee

Do you use JWT for access token? Then how do you handle logout currently?

If you always look up access tokens when authenticating a request - then you can revoke all access tokens by removing them from the table. (whitelist approach)

If you only check JWT - then you have to implement blacklist, since JWT will be valid until it expires. Search “jwt logout” :slightly_smiling_face:

Note:

  • Both requires some state stored somewhere.
  • Seems like guardian_db implements the first approach (whitelist) - keep the all issued tokens in the database.

The real question guardian_db asks is: whether to “revoke” JWT or not. If you’re not required to invalidate issued JWT, then you may just keep the JWT expires, and asks clients not to use it anymore. It solves most cases. However, in some cases.. you may be required to implement strictly “revoke” the issued token. In that case, you have to do either whiltelist or blacklist.

hauleth

hauleth

This sounds almost like using sessions ?

Because it is. JWT is terrible choice for user session management.

Just use plain old cookie with session ID and call it a day.

vamsiikrishna

vamsiikrishna OP

looks like a sane thing to do.
but this is primarily an API and would need to “stateless” .

hauleth

hauleth

If it requires guardian_db (and I assume has log-in feature) then it is not stateless.

vamsiikrishna

vamsiikrishna OP

mhm. got it !
if I store an API token for a user, is it considered stateless or not ?

OvermindDL1

OvermindDL1

If you store anything, such as revocation or validity, then it is not stateless since there is state.

Don’t use JWT/Guardian for stateful services. In general you should not use it at all unless you specifically require JWT for some reason (which is basically never).

hauleth

hauleth

Hmmmm… you store state of the user session, answer this question for yourself. I will just say that in reality there is very few truly stateless services, and in most cases you have stateful services.

bryanhuntesl

bryanhuntesl

I keep thinking JWT is a solution in search of a problem - maybe useful for giving a client access to a service - but for front end authentication? Seems a bit much… Would love to know what the advantage is over a token and a session. Or is it just that the front-end frameworks decided this would be how the world works and we all just have to jump to their tune?

mythicalprogrammer

mythicalprogrammer

is this the only way to invalidate the tokens ?

JWT are stateless. So you need a way to keep track of it.

So yes this general solution of keeping state is the only way.

The only good solution for JWT after help from this community and trying various libraries of login is API stuff. If you need user to login from a browser I would recommend the wonderful library POW.

hauleth

hauleth

No you do not need to keep track of it. If you keep track then you use stateful JWT, which removes all niceties of JWT.

Yes and no, it depends :wink:

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews