Logo

dev-resources.site

for different kinds of informations.

Definition of Jwt and Use

Published at
12/16/2024
Categories
jwt
programming
webdev
Author
316nancy
Categories
3 categories in total
jwt
open
programming
open
webdev
open
Author
8 person written this
316nancy
open
Definition of Jwt and Use

Jwt(Json Web Token)is an open standard for securely transmitting information between parties as a Json object.

Structure of Jwt

Jwt consist of three parts.

Image description

  • Header : Contain metadata about the token, such as the algorithm used for signing.

  • Payload : Include the actual data you want to share.

  • Signature : A cryptographic "seal" that ensures the data hasn't been tempered with.

These three parts are combined into a single, encoded String that is sent between the client and the server.


Why use Jwt

  • Authentication : After a user logs in, the server generates a Jwt and send it to client. The client stores this token and send it back with every request to prove, "I'm authenticated user!"

  • Authorization : The Jwt can include roles, So the server can easily check what the user is allowed to do.


How Jwt works

1- The user logs in with their credentials (username, pw etc..)
2- The server creates 'Refresh Token' and 'Access Token' and then send both token to client.

Refresh Token: A short lived token (ex) 15min)
Access Token: A long lived token (ex) 7 days)

3- The client stores
the Access Token (ex) RAM mememory, HttpOnly cookie)
and Refresh Token. (ex) HttpOnly cookie)

To store token in localStorage or SessionStorage isn't recommended, Because they are vulnerable to XSS(Cross-Site Scripting) attack.

4- The client sends the access token with every request to the server (Authorization header as Bearer )

5- The server verifies the token and processes the request.

6- Once the access token expires, the client can't use it anymore protected resources, So we should be issued access token by using refresh token.

7- If the refresh token expires, the user should log in again with their credentials.


How to use

(Planned to be added)

Adding

XSS: XSS allows attackers to inject and excute malicious scripts in a user's browser.
CSRF: CSRF tricks an authentication user into performing unintended actions on the website where the user is already authenticated.

jwt Article's
30 articles in total
Favicon
Testing with JWT in .NET APIs
Favicon
JWT Authentication With NodeJS
Favicon
[Part 1] Rails 8 Authentication but with JWT
Favicon
How to Generate a Secure JWT Secret Using Node.js
Favicon
Implementing JWT Authentication in .NET API
Favicon
Managing JWT Logout with Blacklists and Redis: A Beginner-Friendly Guide
Favicon
Understanding the Differences Between OAuth2 and OpenID Connect (OIDC)
Favicon
JWT vs Opaque Tokens: A Comprehensive Guide to Choosing Wisely
Favicon
วิธีทำ Auth API ด้วย Express, JWT, MySQL และ Prisma
Favicon
JsonWebTokenError: jwt must be provided
Favicon
JSON Web Tokens (JWT): Guía Esencial y Buenas Prácticas
Favicon
Djoser+SimpleJWT
Favicon
Mastering JWT Authentication: A Complete Guide with MERN Stack
Favicon
How to secure minimal api microservices with asp.net core identity
Favicon
PHP HyperF -> Firebase JWT
Favicon
How to Create a quick Authentication library for NestJS/MongoDB application
Favicon
Learning JWT security using KumuluzEE — The finances of a league of the environment
Favicon
Feijuca.Auth - Part 1: Configuring the tool
Favicon
Securing Your .NET APIs with JWT Authentication
Favicon
"Unauthorized: No token provided")
Favicon
Implementing JWT Authentication in Express API
Favicon
Integration of Salesforce, Node.js, and React: A Step-by-Step Guide
Favicon
Definition of Jwt and Use
Favicon
Implementing JWT Authentication in Go API
Favicon
flow design for access and refresh token- JWT
Favicon
Implementing JWT Authentication in Spring Boot API
Favicon
What is REST Api ? Implement and Secure ?
Favicon
Securing a REST API with JWT Authentication in C# Using AES-Encrypted Keys
Favicon
MS Graph API Certificate and Client Secret OAuth2.0 in Java Spring boot
Favicon
Securing Your Fullstack App: Authentication & Authorization with JWT in Next.js and Node 🔒 🚀

Featured ones: