top | item 33020720

(no title)

themenomen | 3 years ago

Can't you keep a whitelist/blacklist of tokens in a memory cache like redis/memcached and go from there? As far as I know that is the standard practice to invalidate non expired sessions tokens.

discuss

order

jaimehrubiks|3 years ago

Yes but if each microservice needs to check a cache on each request, then why use jwt at all, you could just save a classic session (with random token) in that cache as well

hunterb123|3 years ago

The redis cache with invalidated tokens will be much smaller than storing all sessions.

And you can expire the invalidated keys faster (set the invalidated key expiration to the expiration of the JWT)

Not many people revoke sessions, but a lot of people create sessions. Much more efficient to only store and check revocations. The rest can be stateless.

wdb|3 years ago

Why not let the API Gateway check it?

drinchev|3 years ago

As explained in the article, if that's the case then you can't really trust the JWT anymore only for it's cryptographic signature and you rely on an internal store entry that makes the token valid / invalid.

This makes no benefits as to bearer token or any random string that the server "knows" is a valid authenticated request via internal store, like a DB.

brunojppb|3 years ago

But then you introduce a database-like dependency that potentially every micro service will need access to.

themenomen|3 years ago

Yes, that comes with its own caveats

rkagerer|3 years ago

That's discussed in the article in the second paragraph under "Problems with JWT". If you're keeping a cache at each server node then you might as well just use bearer tokens.

eli|3 years ago

why not just use a session token at that point?

hunterb123|3 years ago

Because you're only storing the invalidated tokens and you're only storing them for the length of the token's lifetime (expire the redis key when the JWT expires)

So instead of storing all session tokens indefinitely, you only store invalidated tokens for a short period of time.