Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Per facilitare l'accesso degli sviluppatori del carico di lavoro alle API pubbliche di Fabric, forniamo il client FabricPlatformAPIClient che astrae le chiamate. Questo client usa principalmente il flusso OBO (On-Behalf-Of) per accedere alle API di Fabric usando le credenziali e le autorizzazioni dell'utente corrente.
Metodo di autenticazione primario: flusso OBO (On-Behalf-Of)
Il toolkit di estendibilità è progettato intorno al flusso On-Behalf-Of (OBO), che è il modo consigliato e principale per accedere alle API di Fabric. Questo flusso:
- Usa le credenziali utente: funziona con le autorizzazioni dell'utente attualmente connesso
- Gestisce il contesto di sicurezza: assicura che gli utenti possano accedere solo alle risorse a cui dispongono dell'autorizzazione
- Semplifica lo sviluppo: non è necessario gestire le credenziali dell'entità servizio
- Seguire le procedure consigliate: Allinea al modello di sicurezza di Microsoft Fabric
Creazione di un FabricPlatformAPIClient
Uso del flusso On-Behalf-Of (scelta consigliata)
import { getWorkloadClient } from "../controller/WorkloadClient";
import { FabricPlatformAPIClient } from "../clients/FabricPlatformAPIClient";
// Create the client using the workload client (uses current user's credentials via OBO flow)
const client = FabricPlatformAPIClient.create(getWorkloadClient());
Uso di un principale del servizio (solo scenari avanzati)
Annotazioni
L'autenticazione dell'entità servizio è necessaria solo per scenari avanzati in cui è necessario accedere alle API di Infrastruttura senza un contesto utente, ad esempio l'elaborazione in background o i flussi di lavoro automatizzati. Per la maggior parte dei carichi di lavoro del toolkit di estendibilità, usare invece il flusso OBO.
import { FabricPlatformAPIClient } from "../clients/FabricPlatformAPIClient";
// Create with service principal authentication (advanced scenarios)
const client = FabricPlatformAPIClient.createWithServicePrincipal(
"your-client-id",
"your-client-secret",
"your-tenant-id"
);
Esempio: Creazione di un nuovo elemento
Ecco un esempio di come creare un nuovo elemento notebook usando il flusso OBO (scelta consigliata):
import { FabricPlatformAPIClient } from "../clients/FabricPlatformAPIClient";
import { getWorkloadClient } from "../controller/WorkloadClient";
async function createNewNotebook() {
try {
// Create the client using OBO flow with current user's credentials
const client = FabricPlatformAPIClient.create(getWorkloadClient());
// Get the current workspace ID
const workspace = await client.workspaces.getCurrentWorkspace();
const workspaceId = workspace.id;
// Create a new notebook item
const newItem = await client.items.createItem(workspaceId, {
displayName: "My New Notebook",
description: "Created via FabricPlatformAPIClient",
type: "Notebook", // Item type code
// Optional: Specify folder ID if you want to create in a specific folder
// folderId: "your-folder-id",
// Optional: Add item-specific creation properties
creationPayload: {
notebookDefaultLanguage: "python"
}
});
console.log("Created new item:", newItem);
return newItem;
} catch (error) {
console.error("Error creating item:", error);
throw error;
}
}
Esempio: Creazione di un elemento con una definizione
Per elementi più complessi che richiedono una definizione (ad esempio una Lakehouse), è possibile includere la definizione usando il flusso OBO:
async function createLakehouse() {
// Create the client using OBO flow with current user's credentials
const client = FabricPlatformAPIClient.create(getWorkloadClient());
const workspace = await client.workspaces.getCurrentWorkspace();
const newLakehouse = await client.items.createItem(workspace.id, {
displayName: "My New Lakehouse",
description: "Sample Lakehouse created programmatically",
type: "Lakehouse",
definition: {
format: "json",
parts: [
{
path: "definition/settings.json",
content: JSON.stringify({
schemaVersion: "1.0",
// Lakehouse-specific settings
settings: {
defaultDatabase: "MyDatabase"
}
})
}
]
}
});
return newLakehouse;
}
}
Collaborazione con altre risorse di Fabric
FabricPlatformAPIClient consente l'accesso a varie risorse di Fabric usando il flusso OBO:
// Create the client using OBO flow with current user's credentials
const client = FabricPlatformAPIClient.create(getWorkloadClient());
// List all workspaces the user has access to
const workspaces = await client.workspaces.listWorkspaces();
// Get workspace capacities
const capacities = await client.capacities.listCapacities();
// Work with OneLake (with user's permissions)
const tables = await client.oneLake.listTables(workspaceId, lakehouseId);
// Work with connections (scoped to user's access)
const connections = await client.connections.listConnections(workspaceId);
Vantaggi principali dell'uso di FabricPlatformAPIClient con il flusso OBO
- Sicurezza: tutte le operazioni rispettano le autorizzazioni e il contesto di sicurezza dell'utente corrente
- Semplicità: non è necessario gestire le credenziali dell'entità servizio o i flussi di autenticazione
- Coerenza: funziona perfettamente con l'architettura front-end-only del toolkit di estendibilità
- Controllabilità: tutte le azioni vengono eseguite e registrate con l'account dell'utente effettivo
- Procedure consigliate: segue i modelli consigliati da Microsoft per l'accesso all'API infrastruttura in scenari di estendibilità