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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews