Skip to main content

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.

✓ 5 OAuth2 flows ✓ Step-by-step diagram ✓ JS code examples ✓ Token explanations

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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

OpenAPI Validator API Response Mock Generator API Response Time Tester OpenAPI Schema Validator OpenAPI Mock Generator OAuth2 Flow Debugger API Test Case Generator API Request Builder HTTP Security Headers Generator JS Prototype Chain Visualizer API Mock Server Config Generator HTTP Security Headers Checker API Rate Limit Calculator API Response Formatter & Analyzer HTTP API Tester JavaScript Formatter & Minifier LLM Cost Calculator OAuth2 Flow Tester AI Prompt Cost Calculator REST API Request Builder Content Security Policy Builder LLM Prompt Cost Calculator API Response Mocker HTTP Header Inspector AI Rate Limit Calculator HTML5 Canvas API Playground Prompt Injection Tester GCP Service Account Key Auditor HTTP Headers Analyzer API Key Generator AI Doc Generator — Pro Tool AI System Guardian Code Tools .htaccess Generator HTTP Methods Reference HTTP Code Snippet Generator HTTP Status Code Reference HTTP Status Code Reference JSON Diff Viewer JSON Diff nginx Config Generator Prettier Config Generator Password Strength Checker Regex Visualizer Regex Tester Pro Regex Tester TypeScript Playground TypeScript to JavaScript Converter Rate Limiter Tester API Changelog Generator HTTP Mock Response Builder HMAC Generator CSP Header Builder Rate Limit Calculator Biome Config Generator CORS Policy Builder AWS IAM Policy Validator HTTP Cookie Parser SBOM Generator HTTP Status Code Lookup HTTP Status Code Lookup Vue Component Generator HTTP Status Code Reference LLM Context Window Calculator HTTP Header Analyzer Regex Flags Explainer LLM Token Counter Dockerfile Linter mTLS Certificate Chain Builder Bundle Size Estimator JavaScript Memory Leak Detector Prompt Token Estimator NPM Bundle Size Estimator Jest Testing Framework Guide Mock Service Worker (MSW) API Mocking Guide Pulumi Modern IaC Guide Casdoor Docker Layer Optimizer Bundle Size Impact Calculator Game Loop Calculator Bezier Curve Editor Particle System Config Generator Token Context Calculator GraphQL Client Configurator OpenAI Function Calling Generator Token Counter & Cost Estimator AI API Rate Limit Calculator Password Strength Analyzer

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →