Before rolling out an OAuth integration to real users, test the authorization handshake, token rotation, and error states in a local development environment.

Local testing checklist

  1. Register a localhost callback: Register a test client with http://localhost:3000/callback as a redirect URI.
  2. Run the authorization handshake: Test user approval and denial in a real browser window.
  3. Exchange the authorization code: Verify PKCE validation and token generation.
  4. Make an authenticated API request: Use the access token to create a test short URL.
  5. Test token refresh and rotation: Verify that refreshing invalidates the old refresh token.
  6. Trigger error cases: Test expired codes, missing scopes, and state mismatch.

1. Register a test client

For local development, you can register http://localhost:... redirect URIs without SSL:
curl -X POST https://connextify.com/mcp/oauth/register \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "Local Dev Sandbox",
    "redirect_uris": ["http://localhost:3000/oauth/callback"],
    "scope": "shorturl:read shorturl:create qrcode:read qrcode:create analytics:read"
  }'
Save the returned client_id and client_secret.

2. Minimal local Express server

Here is a runnable Node.js test server that handles login redirects, PKCE generation, code exchange, and token display:
// server.js (requires express)
const express = require('express');
const crypto = require('crypto');

const app = express();
const PORT = 3000;

const CLIENT_ID = process.env.CONNEXTIFY_CLIENT_ID || 'connextify_client_your_id';
const CLIENT_SECRET = process.env.CONNEXTIFY_CLIENT_SECRET || 'sec_your_secret';
const REDIRECT_URI = `http://localhost:${PORT}/oauth/callback`;

// In-memory session store for local testing
const sessionStore = {};

function base64Url(buffer) {
  return buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}

app.get('/', (req, res) => {
  res.send('<h1>OAuth Test App</h1><a href="/login">Connect Connextify</a>');
});

app.get('/login', (req, res) => {
  // Generate PKCE verifier and S256 challenge
  const verifier = base64Url(crypto.randomBytes(32));
  const challenge = base64Url(crypto.createHash('sha256').update(verifier).digest());
  const state = base64Url(crypto.randomBytes(16));

  sessionStore[state] = { verifier };

  const authUrl = new URL('https://connextify.com/mcp/oauth/authorize');
  authUrl.searchParams.set('client_id', CLIENT_ID);
  authUrl.searchParams.set('redirect_uri', REDIRECT_URI);
  authUrl.searchParams.set('response_type', 'code');
  authUrl.searchParams.set('scope', 'shorturl:read shorturl:create');
  authUrl.searchParams.set('state', state);
  authUrl.searchParams.set('code_challenge', challenge);
  authUrl.searchParams.set('code_challenge_method', 'S256');

  res.redirect(authUrl.toString());
});

app.get('/oauth/callback', async (req, res) => {
  const { code, state, error, error_description } = req.query;

  if (error) {
    return res.status(400).send(`<h3>Authorization error:</h3><p>${error}: ${error_description}</p>`);
  }

  const session = sessionStore[state];
  if (!session) {
    return res.status(400).send('<h3>Invalid state token (CSRF mismatch).</h3>');
  }

  // Exchange authorization code for tokens
  const tokenResponse = await fetch('https://connextify.com/mcp/oauth/token', {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: new URLSearchParams({
      grant_type: 'authorization_code',
      code,
      client_id: CLIENT_ID,
      client_secret: CLIENT_SECRET,
      redirect_uri: REDIRECT_URI,
      code_verifier: session.verifier
    })
  });

  const tokens = await tokenResponse.json();
  delete sessionStore[state];

  res.json({
    message: 'OAuth handshake successful!',
    tokens
  });
});

app.listen(PORT, () => {
  console.log(`OAuth test server listening at http://localhost:${PORT}`);
});
Run it with:
node server.js
Open http://localhost:3000 in your browser and click Connect Connextify.

3. Testing API calls with your new token

Once you have your access_token, make an authenticated call against the Connextify API:
curl -X POST https://connextify.com/api/v1/short-urls \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/oauth-test",
    "custom_alias": "oauth-test-link"
  }'

4. Testing token refresh & reuse prevention

Access tokens are valid for 1 hour. To verify that your refresh logic works:
# 1. Exchange refresh token for a new access token
curl -X POST https://connextify.com/mcp/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=refresh_token" \
  -d "refresh_token=YOUR_REFRESH_TOKEN" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET"
You receive a new access_token and a new refresh_token.

Test reuse detection

Try running the exact same command a second time using the old refresh token. You should receive a rejection:
{
  "error": "invalid_grant",
  "error_description": "Refresh token has been revoked or already rotated"
}
This confirms your server handles token rotation properly and protects against replay attacks.

5. Decoding JWT access tokens

Connextify access tokens are signed JSON Web Tokens (JWT). You can paste your token into jwt.io or inspect the payload to verify the granted scopes and expiry:
{
  "sub": "usr_94812301923",
  "client_id": "connextify_client_abc123",
  "scope": "shorturl:read shorturl:create",
  "iat": 1773820800,
  "exp": 1773824400
}

Going to production checklist

Before shipping your integration to production users:
  • Ensure all redirect_uris registered in production use HTTPS.
  • Store client_secret and user refresh_tokens in an encrypted database or secrets store.
  • Implement automatic token refreshing when an API request encounters a 401.
  • Handle access_denied gracefully in your UI when a user cancels the login prompt.