Skip to main content
REST API

OAuth 2.0 Token Exchange

AuthRequestValidateHard

What you will learn

  • Validate token response envelope strictly: access_token, token_type, expires_in, optional refresh_token โ€” missing fields break client flows silently
  • Test all four grant types (auth code, client creds, password, refresh) if supported โ€” each has distinct failure modes
  • Never put tokens in URL query strings โ€” they leak via Referer, browser history, and server access logs

Description

Exchange authorization code for access token. Implement OAuth flow.

Test Scenario

const response = await request.post('/api/v1/auth/oauth/token', {
  data: {
    grant_type: 'authorization_code',
    code: 'auth_code',
    client_id: 'client_123'
  }
});
const { access_token, refresh_token } = await response.json();
Endpoint/api/v1/auth/oauth/token

Testing Tips

  • โ€ขPOST with grant_type, code, client_id
  • โ€ขHandle refresh token flow
  • โ€ขCheck token scopes
// Playwright API Testing - REST
import { test, expect } from '@playwright/test';
test('REST API request', async ({ request }) => {
const response = await request.get('/api/v1/resource');
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
const data = await response.json();
expect(data).toBeDefined();
});

Challenge ID: rest-auth-oauth-token

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/auth/oauth/token

Press Enter to send