OAuth2 Flow Visualizer
Understand OAuth2 authorization flows with interactive step-by-step diagrams. Compare Authorization Code, PKCE, Client Credentials, Device Code, and the deprecated Implicit flow. Includes JavaScript code examples for each flow.
Frequently Asked Questions
What is OAuth2 and when should I use it?▼
OAuth2 is an authorization framework that lets users grant third-party applications limited access to their accounts without sharing credentials. Use it when you need to let users sign in with Google/GitHub, when your app needs to access user data from another service (calendar, repositories), or when building APIs that third-party developers will integrate with. OAuth2 handles authorization; add OpenID Connect (OIDC) on top for authentication and user identity.
Which OAuth2 flow should I use for my app?▼
Authorization Code + PKCE: for SPAs, mobile apps, and any public client — this is the modern standard. Authorization Code (with client secret): for server-side apps where the secret stays on the server. Client Credentials: for machine-to-machine (M2M) APIs, backend services, and cron jobs — no user involved. Device Code: for CLI tools, smart TVs, and IoT devices without a browser. Implicit flow is deprecated — never use it for new apps.
What is PKCE and why is it required for SPAs?▼
PKCE (Proof Key for Code Exchange) prevents authorization code interception attacks. In SPAs and mobile apps, you cannot safely store a client secret — the code is visible to users. PKCE replaces the client secret with a cryptographic challenge: the app generates a random verifier, hashes it (code_challenge), sends the hash with the auth request, then sends the verifier when exchanging the code for tokens. The server verifies the verifier matches the challenge — an intercepted code is useless without the verifier.
What is the difference between access tokens and refresh tokens?▼
Access tokens are short-lived credentials (typically 15 minutes to 1 hour) sent with every API request as a Bearer token. Refresh tokens are long-lived (days to weeks) and used only to get new access tokens when they expire. Store access tokens in memory (not localStorage) to reduce XSS risk. Store refresh tokens in httpOnly cookies for web apps. When an access token expires, use the refresh token to get a new one without prompting the user to log in again.
How do I implement OAuth2 in a Next.js app?▼
Use next-auth (Auth.js) — it handles the OAuth2/OIDC flow, session management, and token refresh automatically for 50+ providers. Configure providers in route.ts under app/api/auth/[...nextauth]/route.ts. For custom OAuth: store the code_verifier in a server-side session during the redirect, exchange the code server-side in a route handler (never in client components), and store tokens securely in httpOnly cookies or your database.
What is OpenID Connect (OIDC) and how does it relate to OAuth2?▼
OIDC is an identity layer built on top of OAuth2. OAuth2 handles authorization (can this app access this resource?), but says nothing about user identity. OIDC adds an ID token (JWT) containing user claims (sub, email, name, picture) and standardizes the /userinfo endpoint. When you add openid to the OAuth2 scope, you get both an access token (for API calls) and an ID token (for authentication). Most identity providers (Google, Microsoft, GitHub) support OIDC.
Related Products
on GumroadTypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →DevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
OpenAPI Validator
Paste your OpenAPI 3.x spec (YAML or JSON) to validate structure, find missing required fields, detect duplicate paths, check for missing operationIds, and get errors and warnings with path references.
Open free tool →
API Response Mock Generator
Generate realistic mock API responses with custom status codes, headers, and JSON body. Quick templates for 200, 401, 404, 429, 500 and more. Runs in your browser.
Open free tool →
API Response Time Tester
Test API endpoint response times directly from your browser. Run multiple requests, see average/min/max times, status codes, and response sizes. GET, POST, PUT, DELETE support. Free.
Open free tool →
More Free Tools
Related Articles
JWT Authentication Best Practices 2026: Secure Your API Tokens
Complete JWT security guide for 2026. Covers RS256 vs HS256 signing, token storage strategies, expiry and refresh token patterns, revocation, common vulnerabilities, and a production security checklist.
JWT Token Decoder: How to Debug Authentication Issues
Learn how to use a JWT token decoder to diagnose 401 errors, expired tokens, missing claims, and auth misconfiguration. Practical debugging guide with code examples.
JWT Tokens Explained: How to Decode and Debug Them
Understand JSON Web Tokens from header to signature. Learn how to decode JWTs, read their claims, debug authentication issues, and use free online JWT tools.
Web Authentication Patterns in 2026: OAuth, Passkeys, and JWT Best Practices
A complete guide to modern web authentication: OAuth 2.0/OIDC, Passkeys/WebAuthn, JWT best practices, session management, and MFA strategies for secure apps.
Base64 Encode/Decode Explained: When and How to Use It
Understand when to use Base64 encoding and when to avoid it. This guide explains the Base64 algorithm, practical use cases, code examples in JavaScript, Python, Go, and more.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →