I research AI tools, APIs & agents — comparing specs, pricing and real user reports — then publish honest rankings so you don't waste money. Research-first, never sponsored fluff.
Decoded the example token — 'Thor's secret enemy' and 'I love you 3000' sitting in plain base64 is the whole lesson in one string. Anyone can read it; the signature's the only thing stopping them rewriting it. The short-lived + refresh token bit is the part I'd want the follow-up on — do you rotate the refresh token on every use, or is that a whole second post?
Ohh, thanks for cracking the code. Yep, I was tempted to add the refresh token topic here but I feel like it would be too much for a single post. For the next one? I'm thinking of a completely different topic!
The key analogy works well. One thing I'd want in the follow-up next to logout is where the browser keeps that key. In localStorage any script on the page can read it, so a single XSS hands over the key to every door. An httpOnly cookie keeps it out of JavaScript's reach, at the cost of having to think about CSRF. For a Kanban backend it's a small decision now and an annoying migration later.
"Encoded, not encrypted" is the line every beginner needs to hear early. People put emails, roles, sometimes worse in the payload thinking nobody can read it.
One thing worth a follow-up post: revocation. Since the server doesn't store the token, logging someone out or kicking a compromised user is harder than it looks. Short expiry plus refresh tokens is the usual answer, but it has its own trade-offs.
Auth comes up a lot in the API design interviews we help people prep for at DesignGurus, and revocation is almost always the follow-up question that trips candidates up. Nice write-up, the Kanban backend context makes it easy to follow.
Yep, I've actually implemented token revocation and refresh token rotation but I feel like it would be too deep for this one blog post. But thanks for making this comment. Now readers would know more if they want to go more in-depth.
Great framing. Knowing it's the same person and being able to prove it are different problems, and most auth bugs live in the gap between them. Nice walk through it.
Clear walkthrough of the encoding vs. signature distinction, which trips up a lot of first-time backend builds. When wiring up jwt.verify() in Node/Express, one subtle edge case worth pinning down is passing an explicit algorithms: ['HS256'] allowlist rather than trusting the token header's alg field, so alg: none or key-confusion payloads get rejected immediately. Storing those short-lived tokens in HttpOnly; SameSite=Lax cookies instead of localStorage also prevents stray client-side scripts from exfiltrating them.
Yes, I believe I did SameSite=Lax and HttpOnly on my first backend. But explicitly saying I only allow 'HS256' is new to me. It make sense actually, if not the same, the token is rejected ASAP. Thanks for the in-depth explanation!
The noobmaster69 payload in the example token was a fun touch, and keeping the distinction between base64 encoding and actual encryption clear is something a lot of JWT intros skip
fun next one to write: logout. the token stays valid until exp no matter what the user clicks, and that's usually where people first meet short expiry plus a denylist
Great detail article on JWT Elmar!
Thank you @francistrdev!
Decoded the example token — 'Thor's secret enemy' and 'I love you 3000' sitting in plain base64 is the whole lesson in one string. Anyone can read it; the signature's the only thing stopping them rewriting it. The short-lived + refresh token bit is the part I'd want the follow-up on — do you rotate the refresh token on every use, or is that a whole second post?
Ohh, thanks for cracking the code. Yep, I was tempted to add the refresh token topic here but I feel like it would be too much for a single post. For the next one? I'm thinking of a completely different topic!
The key analogy works well. One thing I'd want in the follow-up next to logout is where the browser keeps that key. In localStorage any script on the page can read it, so a single XSS hands over the key to every door. An httpOnly cookie keeps it out of JavaScript's reach, at the cost of having to think about CSRF. For a Kanban backend it's a small decision now and an annoying migration later.
Right on. Been reading a lot about XSS and CSRF so everything was kind of new to me. Thanks for explaining this a bit further.
"Encoded, not encrypted" is the line every beginner needs to hear early. People put emails, roles, sometimes worse in the payload thinking nobody can read it.
One thing worth a follow-up post: revocation. Since the server doesn't store the token, logging someone out or kicking a compromised user is harder than it looks. Short expiry plus refresh tokens is the usual answer, but it has its own trade-offs.
Auth comes up a lot in the API design interviews we help people prep for at DesignGurus, and revocation is almost always the follow-up question that trips candidates up. Nice write-up, the Kanban backend context makes it easy to follow.
Yep, I've actually implemented token revocation and refresh token rotation but I feel like it would be too deep for this one blog post. But thanks for making this comment. Now readers would know more if they want to go more in-depth.
Great framing. Knowing it's the same person and being able to prove it are different problems, and most auth bugs live in the gap between them. Nice walk through it.
Thanks @gautamtalksdev, glad you liked it.
Anytime, looking forward to the next one.
Clear walkthrough of the encoding vs. signature distinction, which trips up a lot of first-time backend builds. When wiring up jwt.verify() in Node/Express, one subtle edge case worth pinning down is passing an explicit algorithms: ['HS256'] allowlist rather than trusting the token header's alg field, so alg: none or key-confusion payloads get rejected immediately. Storing those short-lived tokens in HttpOnly; SameSite=Lax cookies instead of localStorage also prevents stray client-side scripts from exfiltrating them.
Yes, I believe I did SameSite=Lax and HttpOnly on my first backend. But explicitly saying I only allow 'HS256' is new to me. It make sense actually, if not the same, the token is rejected ASAP. Thanks for the in-depth explanation!
I just made a simple flowchart for how refresh tokens work and I also added it in my GitHub issue.
Feel free to have a look for anyone who's curious:
The noobmaster69 payload in the example token was a fun touch, and keeping the distinction between base64 encoding and actual encryption clear is something a lot of JWT intros skip
Glad that distinction came out well. Thanks @parimalmakes
fun next one to write: logout. the token stays valid until exp no matter what the user clicks, and that's usually where people first meet short expiry plus a denylist
Ohhh, I'll keep this in mind!
I think the encoding versus encryption distinction was the clearest part for me.
Thanks! I did quite a lot of thinking of how I could translate it in real world visuals.