How to register an app, implement authorization code grant with PKCE, and exchange tokens
If you are building an integration that accesses Connextify on behalf of other users, use our OAuth 2.0 service. We support standard Authorization Code flow with PKCE (Proof Key for Code Exchange) and Dynamic Client Registration.
Step 2: Generate PKCE parameters and redirect user
PKCE prevents authorization code injection attacks. Always generate a cryptographically random code verifier and SHA-256 challenge for every login attempt.
// 1. Generate a random 32-byte verifier stringfunction generateCodeVerifier() { const bytes = new Uint8Array(32); crypto.getRandomValues(bytes); return btoa(String.fromCharCode(...bytes)) .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, '');}// 2. Hash with SHA-256 to create the code challengeasync function generateCodeChallenge(verifier) { const data = new TextEncoder().encode(verifier); const digest = await crypto.subtle.digest('SHA-256', data); return btoa(String.fromCharCode(...new Uint8Array(digest))) .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, '');}async function startOAuthFlow() { const verifier = generateCodeVerifier(); const challenge = await generateCodeChallenge(verifier); // Store verifier in sessionStorage to verify during the callback step sessionStorage.setItem('pkce_code_verifier', verifier); const authUrl = new URL('https://connextify.com/mcp/oauth/authorize'); authUrl.searchParams.set('client_id', 'YOUR_CLIENT_ID'); authUrl.searchParams.set('redirect_uri', 'https://myapp.com/oauth/callback'); authUrl.searchParams.set('response_type', 'code'); authUrl.searchParams.set('scope', 'shorturl:read shorturl:create'); authUrl.searchParams.set('state', 'random_csrf_token_xyz'); authUrl.searchParams.set('code_challenge', challenge); authUrl.searchParams.set('code_challenge_method', 'S256'); window.location.href = authUrl.toString();}
Refresh Token Rotation: Every refresh response issues a new refresh token and invalidates the previous one. Always overwrite your stored refresh token with the latest value returned.