Skip to content

Auth0 Device Authorization Flow — OAuth 2.0 Device Flow for Auth0

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you'll learn about Auth0 Device Auth. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Device Authorization Grant enables authentication on devices with limited input capabilities like smart TVs, CLI tools, and IoT devices.

// Device authorization flow
async function deviceAuthFlow() {
  // Step 1: Request device code
  const deviceResponse = await axios.post(`https://{tenant}.auth0.com/oauth/device/code`, {
    client_id: process.env.AUTH0_CLIENT_ID,
    scope: 'openid profile email scan:read',
    audience: 'https://scan-api.example.com'
  });

  const { device_code, user_code, verification_uri_complete, interval, expires_in } = deviceResponse.data;

  console.log(`Please visit ${verification_uri_complete} and enter code: ${user_code}`);
  console.log(`Code expires in ${expires_in} seconds`);

  // Step 2: Poll for token
  const pollInterval = interval * 1000;
  const startTime = Date.now();

  while (Date.now() - startTime < expires_in * 1000) {
    await delay(pollInterval);
    try {
      const tokenResponse = await axios.post(`https://{tenant}.auth0.com/oauth/token`, {
        grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
        device_code: device_code,
        client_id: process.env.AUTH0_CLIENT_ID
      });

      return tokenResponse.data;
    } catch (err) {
      if (err.response?.data?.error === 'authorization_pending') continue;
      if (err.response?.data?.error === 'slow_down') {
        await delay(pollInterval);
        continue;
      }
      throw err;
    }
  }

  throw new Error('Device code expired');
}

The device flow enables secure authentication on devices with limited input or display capabilities.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro