IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| Session vs Token-Based Authentication | Redirect URIs and Open Redirect Attacks | |
JWT Structure and Signature Validation |
A JSON Web Token (JWT) is a compact, URL-safe way to securely transmit information between two parties as a JSON object. It is digitally signed to ensure integrity and authenticity, making it a popular choice for stateless authentication in APIs, SPAs, and microservices.
A JWT has three parts, separated by dots (.):
<Header>.<Payload>.<Signature>
Example:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 .eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ .SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
typ) and signing algorithm (alg).{
"alg": "HS256",
"typ": "JWT"
}
iss, sub, aud, exp, iat.{
"sub": "1234567890",
"name": "John Doe",
"admin": true,
"iat": 1516239022
}
encodedHeader + "." + encodedPayload.[Client] -- Login Credentials --> [Auth Server] [Auth Server] -- Validate Credentials --> [Database] [Auth Server] -- Create Header & Payload --> [Sign with Secret/Private Key] [Auth Server] -- Return JWT --> [Client Stores Token]
alg) from the header.header.payload.exp, iss, aud).[Client] -- JWT --> [Server] [Server] -- Split into Header, Payload, Signature [Server] -- Recreate Signature using Key & Algorithm [Server] -- Compare with Provided Signature [Server] -- If Match --> Validate Claims --> Authorize [Server] -- If No Match --> Reject
const jwt = require('jsonwebtoken');
const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
const secret = "my_secret_key";
try {
const decoded = jwt.verify(token, secret);
console.log("Valid token:", decoded);
} catch (err) {
console.error("Invalid token:", err.message);
}
exp) to limit misuse.alg: none — it disables signature verification.
HEADER: { "alg": "HS256", "typ": "JWT" }
Base64UrlEncode(header)
PAYLOAD: { "sub": "1234567890", "name": "John Doe", "admin": true }
Base64UrlEncode(payload)
SIGNATURE: HMACSHA256(
base64UrlEncode(header) + "." + base64UrlEncode(payload),
secret
)
| Session vs Token-Based Authentication | Redirect URIs and Open Redirect Attacks | |