DEV Community

Cover image for JWT (JSON Web Token)

JWT (JSON Web Token)

Shubham Yadav on August 16, 2022

What JWT is used for? A JWT is used for authorisation, authorisation is making sure that the user that sends a request to your server is...
Collapse
 
almogtzabari profile image
Almog Tzabari

For a second there I thought JWT = James web telescope 😅

Collapse
 
shubhamyadav profile image
Shubham Yadav

😂😂

Collapse
 
ngocsotn profile image
The Ngoc Nguyen

đŸ¤ŖđŸ¤ŖđŸ¤Ŗ

Collapse
 
devarshishimpi profile image
Devarshi Shimpi

Hahaha same.

Collapse
 
fmcdev profile image
fmcdev

JWT is great. Essential for single page web apps for example where you don't want to keep user credentials in memory along the session and you rely on continuous calls to REST APIs

Collapse
 
zoppatorsk profile image
Zoppatorsk

One interesting thing that u did not mention. The use of private/public keys..
In short before it gets confusing, u can have one entity that is responsible for signing the JTW (so like a "central login" where u get the JWT from). The signing is done with the private key. The public key, (it's not public in the way everyone can have it) can be used to verify if the JWT is valid (so that key can be used in all services to verify the user).

One important thing to remember about JWT's is that u can not invalidate a JWT (but u can set an expatiation time) as it is "stateless".

Collapse
 
kolja profile image
Kolja

Thanks a lot😃
But i have a question about the payload:
Is the payload part of the JWT?
And is the payload hashed with the token?
So, will the server recognize, if the payload has been changed on the client?

Collapse
 
zoppatorsk profile image
Zoppatorsk

Payload is part of the JWT and anyone can decode it jwt.io, however the client can't change the payload as the server is the only one having the key it was signed with and with that key can verify that the JWT is valid.

Collapse
 
shubhamyadav profile image
Shubham Yadav

right!!👍

Collapse
 
vermaneerajin profile image
Neeraj Verma

This example doesn't seem correct to me. In case of session based authentication we can use common session database (redis) between multiple servers.

Collapse
 
blackr1234 profile image
blackr1234

Agree, and it says nothing about expiring or invalidating the issued tokens.

Collapse
 
devarshishimpi profile image
Devarshi Shimpi

Great article!!!

Collapse
 
shubhamyadav profile image
Shubham Yadav

thankyou!!

Collapse
 
arosebine profile image
Arowolo Ebine

Yeah, nice one

Collapse
 
shubhamyadav profile image
Shubham Yadav

thanks!!

Collapse
 
vaishnavi_2211 profile image
Vaishnavi Patil

Informative 🚀🚀

Collapse
 
shubhamyadav profile image
Shubham Yadav

thanks!!