Free · Private · Client-side

OAuth 2.0 Token Generator with Interactive Playground

Generate production-ready OAuth tokens for access control, refresh flows, and client authentication. Test complete OAuth flows with our interactive playground.

Generated values never leave this device.

Short-lived token for API access · Recommended expiry: 1-2 hours

Estimated entropy: 256 bits · 32 random bytes · base64 encoded~132,943,112,026,157,700,000,000,000,000 quintillion times the age of the universe to crack
Weak · <50 bitsFairGood · 70+Strong · 100+

In plain terms: a gaming PC guessing a million passwords per second would need 132,943,112,026,157,700,000,000,000,000,000,000 quintillion times the age of the universe. Even someone renting every cloud server on Earth — a trillion guesses per second — would need 132,943,112,026,157,700,000,000,000,000 quintillion times the age of the universe. Nobody is guessing this password; the only realistic risks are it being reused or phished.

Generated tokens

Strong256 bits
Strong256 bits
Strong256 bits
Strong256 bits

Interactive OAuth 2.0 Playground

Step through a complete OAuth authorization flow with live examples and generated tokens.

Step 1: Authorization Request

Build the authorization URL to redirect users to the OAuth provider.

https://oauth.provider.com/authorize?response_type=code&client_id=client_123456&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=read%3Aprofile%20read%3Aemail&state=

OAuth 2.0 Flow Comparison

Flow TypeUse CaseClient TypeTokens UsedSecurity Level
Authorization CodeWeb applicationsConfidentialAuth Code + Access + RefreshHigh
PKCESPAs, Mobile appsPublicAuth Code + AccessHigh
ImplicitLegacy SPAsPublicAccess (fragment)Medium
Client CredentialsAPI to APIConfidentialClient Secret + AccessHigh

Complete Implementation Examples

Express.js OAuth Server

oauth-server.js
const express = require('express');
const crypto = require('crypto');
const jwt = require('jsonwebtoken');

class OAuthServer {
  constructor() {
    this.clients = new Map();
    this.authCodes = new Map();
    this.accessTokens = new Map();
    this.refreshTokens = new Map();
  }

  registerClient(clientId, clientSecret, redirectUris) {
    this.clients.set(clientId, {
      secret: clientSecret,
      redirectUris: new Set(redirectUris)
    });
  }

  generateAuthCode(clientId, userId, scopes) {
    const code = crypto.randomBytes(24).toString('base64url');
    this.authCodes.set(code, {
      clientId,
      userId,
      scopes,
      expiresAt: Date.now() + 10 * 60 * 1000 // 10 minutes
    });
    return code;
  }

  generateTokens(userId, clientId, scopes) {
    const accessToken = crypto.randomBytes(32).toString('base64url');
    const refreshToken = crypto.randomBytes(64).toString('base64url');

    this.accessTokens.set(accessToken, {
      userId,
      clientId,
      scopes,
      expiresAt: Date.now() + 3600 * 1000 // 1 hour
    });

    this.refreshTokens.set(refreshToken, {
      userId,
      clientId,
      scopes,
      expiresAt: Date.now() + 90 * 24 * 3600 * 1000 // 90 days
    });

    return { accessToken, refreshToken, expiresIn: 3600 };
  }

  validateAccessToken(token) {
    const tokenData = this.accessTokens.get(token);
    return tokenData && tokenData.expiresAt > Date.now() ? tokenData : null;
  }
}

const oauthServer = new OAuthServer();

// Register a client
oauthServer.registerClient(
  'client_123456',
  'cs_client_secret_here',
  ['https://example.com/callback']
);

// Authorization endpoint
app.get('/oauth/authorize', (req, res) => {
  const { client_id, redirect_uri, scope, state } = req.query;

  // Validate client and redirect URI
  const client = oauthServer.clients.get(client_id);
  if (!client || !client.redirectUris.has(redirect_uri)) {
    return res.status(400).json({ error: 'invalid_client' });
  }

  // In real implementation, show user consent form
  // For demo, auto-approve
  const authCode = oauthServer.generateAuthCode(client_id, 'user123', scope);

  res.redirect(`${redirect_uri}?code=${authCode}&state=${state}`);
});

// Token endpoint
app.post('/oauth/token', (req, res) => {
  const { grant_type, code, client_id, client_secret, refresh_token } = req.body;

  if (grant_type === 'authorization_code') {
    const codeData = oauthServer.authCodes.get(code);
    if (!codeData || codeData.expiresAt < Date.now()) {
      return res.status(400).json({ error: 'invalid_grant' });
    }

    const tokens = oauthServer.generateTokens(codeData.userId, client_id, codeData.scopes);
    oauthServer.authCodes.delete(code); // One-time use

    res.json({
      access_token: tokens.accessToken,
      token_type: 'Bearer',
      expires_in: tokens.expiresIn,
      refresh_token: tokens.refreshToken,
      scope: codeData.scopes
    });
  }

  // Handle refresh_token grant type...
});

Python Flask OAuth Client

oauth_client.py
from flask import Flask, request, session, redirect, url_for
import requests
import secrets
from urllib.parse import urlencode

app = Flask(__name__)
app.secret_key = '5Vu3mR43MjAmcMco0h4H45bdjwqiS2ZW5y80UqS3jFM='

# OAuth configuration
OAUTH_CONFIG = {
    'client_id': 'client_123456',
    'client_secret': 'cs_client_secret_here',
    'auth_url': 'https://oauth.provider.com/authorize',
    'token_url': 'https://oauth.provider.com/token',
    'redirect_uri': 'https://example.com/callback',
    'scope': 'read:profile read:email'
}

@app.route('/login')
def login():
    # Generate state for CSRF protection
    state = secrets.token_urlsafe(32)
    session['oauth_state'] = state

    # Build authorization URL
    params = {
        'response_type': 'code',
        'client_id': OAUTH_CONFIG['client_id'],
        'redirect_uri': OAUTH_CONFIG['redirect_uri'],
        'scope': OAUTH_CONFIG['scope'],
        'state': state
    }

    auth_url = f"{OAUTH_CONFIG['auth_url']}?{urlencode(params)}"
    return redirect(auth_url)

@app.route('/callback')
def callback():
    # Verify state parameter
    if request.args.get('state') != session.get('oauth_state'):
        return 'Invalid state parameter', 400

    # Get authorization code
    auth_code = request.args.get('code')
    if not auth_code:
        return 'Missing authorization code', 400

    # Exchange code for tokens
    token_data = {
        'grant_type': 'authorization_code',
        'code': auth_code,
        'client_id': OAUTH_CONFIG['client_id'],
        'client_secret': OAUTH_CONFIG['client_secret'],
        'redirect_uri': OAUTH_CONFIG['redirect_uri']
    }

    response = requests.post(OAUTH_CONFIG['token_url'], data=token_data)

    if response.status_code == 200:
        tokens = response.json()
        session['access_token'] = tokens['access_token']
        session['refresh_token'] = tokens.get('refresh_token')
        return redirect(url_for('profile'))
    else:
        return 'Token exchange failed', 400

@app.route('/profile')
def profile():
    access_token = session.get('access_token')
    if not access_token:
        return redirect(url_for('login'))

    # Make API request with access token
    headers = {'Authorization': f'Bearer {access_token}'}
    response = requests.get('https://api.provider.com/user/profile', headers=headers)

    if response.status_code == 200:
        user_data = response.json()
        return f"Welcome, {user_data.get('name', 'User')}!"
    else:
        # Token might be expired, try refresh
        return refresh_and_retry()

def refresh_and_retry():
    refresh_token = session.get('refresh_token')
    if not refresh_token:
        return redirect(url_for('login'))

    # Refresh access token
    token_data = {
        'grant_type': 'refresh_token',
        'refresh_token': refresh_token,
        'client_id': OAUTH_CONFIG['client_id'],
        'client_secret': OAUTH_CONFIG['client_secret']
    }

    response = requests.post(OAUTH_CONFIG['token_url'], data=token_data)

    if response.status_code == 200:
        tokens = response.json()
        session['access_token'] = tokens['access_token']
        return redirect(url_for('profile'))
    else:
        return redirect(url_for('login'))

OAuth 2.0 Security Best Practices

✓ Security Recommendations

  • Always use HTTPS for all OAuth endpoints
  • Implement state parameter for CSRF protection
  • Use PKCE for public clients (SPAs, mobile)
  • Validate redirect URIs against whitelist
  • Set short expiry for authorization codes (10 min)
  • Implement proper token storage (secure, httpOnly cookies)
  • Use refresh token rotation
  • Implement token revocation endpoints

✗ Common Vulnerabilities

  • Missing or weak state validation (CSRF)
  • Authorization code replay attacks
  • Redirect URI manipulation
  • Token leakage in logs or URLs
  • Insufficient client authentication
  • Long-lived access tokens without refresh
  • Implicit flow without proper validation
  • Missing token revocation on logout

OAuth Security Checklist

Bulk Token Generation

access tokens

Generate Tokens in Terminal

OpenSSL (32 bytes, base64)

$openssl rand -base64 32

Python with prefix

$python3 -c "import secrets; print('ya29_' + secrets.token_urlsafe(32))"

Node.js with prefix

$node -e "console.log('ya29_' + require('crypto').randomBytes(32).toString('base64url'))"

UUID (for client IDs)

$uuidgen

How to Generate OAuth 2.0 Tokens

01
Choose Token Type
Select the OAuth token type you need: access token, refresh token, or client secret.
02
Configure Token Parameters
Set token length, expiration, and scope requirements based on your OAuth flow.
03
Generate Secure Tokens
Click generate to create cryptographically secure tokens with proper entropy.
04
Implement in OAuth Flow
Use the tokens in your OAuth 2.0 authorization flow with proper validation and expiry.