Edit

Share via


How-To: Acquire Microsoft Entra tokens

This quick start guide shows you how to acquire Microsoft Entra tokens in your Fabric extension to access APIs. For comprehensive API reference and advanced scenarios, see the Authentication JavaScript API documentation.

Prerequisites

  • A Fabric extension project set up with the Extensibility Toolkit
  • Basic understanding of JavaScript/TypeScript

Basic token acquisition

The simplest way to get a token for Fabric APIs:

// Get a token for Fabric APIs
const token = await workloadClient.auth.acquireFrontendAccessToken({ scopes: [] });

// Use the token to call Fabric APIs
const response = await fetch('https://api.fabric.microsoft.com/v1/workspaces', {
  headers: {
    'Authorization': `Bearer ${token.token}`,
    'Content-Type': 'application/json'
  }
});

Get tokens for specific services

For Azure services or custom applications, specify the required scopes:

// Get token for Azure Storage
const storageToken = await workloadClient.auth.acquireFrontendAccessToken({
  scopes: ['https://storage.azure.com/user_impersonation']
});

// Get token for Microsoft Graph
const graphToken = await workloadClient.auth.acquireFrontendAccessToken({
  scopes: ['https://graph.microsoft.com/User.Read']
});

Error handling

Handle common authentication errors:

try {
  const token = await workloadClient.auth.acquireFrontendAccessToken({ scopes: [] });
  // Use token...
} catch (error) {
  console.error('Authentication failed:', error.message);
  // Handle error appropriately
}

Next steps