Playground API
DocsStatsBlogStudio
Documentation Tree
Technical BlogFeature Deep Dives
  • Introduction
  • Quickstart
    5 min
  • How It Works
  • Recipes & Cookbooks
  • Platform Comparisons
  • Real-World Showcase
  • Interactive Studio
    Studio
  • GraphiQL IDE
    IDE
  • Session Quotas & Activity
  • Network Chaos Simulator
  • Atomic Sandbox Reset
  • Overview & Models
    Hub
  • Users Resource
  • Posts Resource
  • Comments Resource
  • Todos Resource
  • Custom Collections
    Custom
  • Multipart File Uploads
    Upload
  • Dynamic SVG Avatars
    SVG
  • Image Thumbnails
    CDN
  • Relational Filtering
  • Full-Text Search
  • Dynamic Sorting
  • Offset Pagination
  • Cursor Pagination
    Scroll
  • CSV & Excel Export & Import
    IO
  • Custom Collections
    CRUD
  • Overview & Architecture
    Hub
  • JWT Auth Flow
  • Refresh Token Rotation
    Mutex
  • RBAC Permission Matrix
    Roles
  • Expiry Simulation
  • Clock Skew Drift
  • Password Recovery Loop
  • Dual-Mode Sandboxing
  • GraphiQL IDE
    IDE
  • Relational Queries
  • Stateful Mutations
  • Realtime Subscriptions
  • Overview & Flowcharts
    Hub
  • Hosted Checkout
    Stripe
  • Payment Intents API
  • 3DS Challenge Modal
    Modal
  • Customers Vault
  • Charges & Refunds
  • Test Cards Catalog
  • Overview & Channels
    Hub
  • Virtual Email Mailbox
    Mailtrap
  • Virtual SMS Terminal
    Phone
  • In-App Notifications
  • Message Dispatcher
  • Realtime Studio
    Studio
  • Native WebSocket (/ws)
  • Socket.io Gateway
  • Presence & Echo Bot
  • Server-Sent Events (SSE)
    SSE
  • Analytics Telemetry
  • Webhook Subscriptions
  • HMAC SHA-256 Signatures
  • Delivery Logs
  • Manual Retry Simulator
  • Network Latency Delay
  • HTTP Status Codes
  • Rate-Limit Simulator
    429
  • Flaky Network & Jitter
    Chaos
  • Session Quotas & Activity
  • JSON Snapshots
    JSON
  • Headless CI/CD Testing
    CI
  • Mobile QR Code Sync
  • System Metrics & Health
  • Atomic Sandbox Reset
  • Official TypeScript SDK
  • Multi-Language Generators
  • DevTools Extension
  • OpenAPI 3.1 Spec
    JSON
  • Postman Collection v2.1
  • Bruno Collection
  • Insomnia Workspace
  • TypeScript .d.ts
    .d.ts
  • AI Prompt Rules
    Rules
  • Context Index (llms.txt)
  • Full Schema (llms-full.txt)
  • Manifest (product.json)
  • All Feature Articles
    Blog
  • React CRUD Without Backend
    Deep Dive
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE Guide
Technical Blog
Articles

In-depth articles explaining stateful mock APIs, WebSockets, payments, and frontend resilience.

Read Articles
PreviousOverview & Architecture
NextRefresh Token Rotation
Auth & Security

JWT Authentication Flow & Lifecycle

Standard JSON Web Token (JWT) issuance, verification, and role resolution. Authenticate against built-in developer test personas, decode signed HMAC-SHA256 claims, and access protected endpoints using standard Bearer authorization headers.

Select Test Persona

Choose a pre-configured role persona below to load credentials into the interactive login console:

1

Execute Login Request (System Administrator)

Transmits credentials to issue a signed access token (15m expiry) and long-lived refresh token:

Login as admin

POST
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}
2

Fetch Authenticated Profile (/auth/me)

Access protected user identity and claims using the session cookie or by passing the issued Bearer token:

Verify Session Identity & Claims

GET
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}
3

Update Authenticated Profile (PATCH /auth/me)

Apply partial mutations to your active user profile. Changes are stored in your session overlay without mutating baseline seed records:

Update User Profile Attributes

PATCH
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}
4

Register Custom Mock User (POST /auth/register)

Create an ad-hoc user account within your isolated sandbox session and immediately receive a signed JWT token pair:

Register New User & Obtain Tokens

POST
response.json
1
{
2
// Click "Send" above to execute this request against the live server.
3
}

JWT Claims Anatomy & Payload Structure

Access tokens issued by Playground API are signed with HMAC-SHA256 and encode identity and authorization claims:

1. JOSE HeaderHS256
{
  "alg": "HS256",
  "typ": "JWT"
}

Cryptographic signature algorithm metadata.

2. Token PayloadClaims
{
  "userId": 1,
  "username": "admin",
  "role": "ADMIN",
  "scopes": ["read:all","write:all","admin:all","sandbox:reset"],
  "iat": 1759140000,
  "exp": 1759140900
}

Identity, role permissions, and UNIX expiry timestamps.

3. SignatureHMAC
HMACSHA256(
  base64Url(header) + "." +
  base64Url(payload),
  JWT_SECRET
)

Tamper-evident verification hash ensuring authenticity.

Frontend Client Integration Recipes

Production-ready authorization interceptors and route protection patterns:

authClient.ts
1
// Modern Native TypeScript Fetch with Bearer Auth Header
2
interface AuthResponse {
3
access_token: string;
4
refresh_token: string;
5
token_type: string;
6
expires_in: number;
7
user: {
8
id: number;
9
name: string;
10
email: string;
11
role: string;
12
};
13
}
14
15
// 1. Authenticate and retrieve token pair
16
export async function loginUser(username: string, password = 'Password@123'): Promise<AuthResponse> {
17
const res = await fetch('https://playground.nileslabs.com/api/v1/auth/login', {
18
method: 'POST',
19
headers: { 'Content-Type': 'application/json' },
20
body: JSON.stringify({ username, password }),
21
});
22
23
if (!res.ok) {
24
const error = await res.json();
25
throw new Error(error.message || 'Login failed');
26
}
27
28
const authData: AuthResponse = await res.json();
29
localStorage.setItem('access_token', authData.access_token);
30
return authData;
31
}
32
33
// 2. Access protected endpoint using Bearer token
34
export async function getProfile() {
35
const token = localStorage.getItem('access_token');
36
const res = await fetch('https://playground.nileslabs.com/api/v1/auth/me', {
37
headers: {
38
Authorization: Bearer ${token},
39
},
40
});
41
42
return res.json();
43
}