Explaining JWT (JSON Web Token) for Video Game Enthusiasts

Have you ever wondered how video games remember your progress and allow you to continue playing where you left off? Well, it's kind of like having a s...

Ditulis Oleh zidan Pada

Have you ever wondered how video games remember your progress and allow you to continue playing where you left off? Well, it's kind of like having a special ticket that carries all your game data and secrets. Let me introduce you to JWT (JSON Web Token), the digital equivalent of that ticket!

In the gaming world, imagine you've conquered a challenging level, and as a reward, you receive a unique ticket. This ticket contains essential information, such as your current level, remaining lives, collected items, and other achievements. The crucial thing is that this ticket is protected with a special key, and only the game itself can access and modify it.

Now, when you want to dive into a new level, you hand over the ticket to the game. The game checks the ticket to know precisely where you paused your adventure. This way, you can seamlessly continue your journey without starting from scratch every time you play.

In the programming realm, JWT acts just like that game ticket. When you log in to a website or app, you receive a JWT that holds information about you and your authorized actions within the application. From then on, whenever you interact with the site or app, you present the JWT alongside the request.

The beauty of JWT lies in its secure nature. Just like the game ticket's special key, JWT is digitally signed, ensuring that its contents cannot be altered by anyone other than the issuing party (the game or the website). This way, the application can trust that the data sent along with the JWT is legitimate and that it indeed belongs to you.

Here's how it works in a nutshell:

  1. You log in to the game/website, and the server generates a JWT containing your user information and permissions.

  2. Every time you perform an action, like completing a level or obtaining rewards, you include the JWT in the request.

  3. The server validates the JWT's signature and extracts the information it needs to process your request.

  4. Based on the JWT data, the server knows it's you and what you're allowed to do, enabling you to pick up your gaming journey right where you left off.

So, next time you enjoy your favorite video game or explore a web application, remember that the magic of JWT is helping you continue your adventures smoothly and securely.

Credit to: https://www.linkedin.com/in/fromentp/ for this brilliant analogy! 🙌