Hi Debashis Jena,
Thanks for reaching out to us on the Microsoft Q&A forum.
You can connect to Microsoft Fabric Lakehouse using C# with the help of a service principal. For instructions on creating a service principal, please refer to the provided link: Service principal authentication for Microsoft purview.
After creating a Service Principal in Azure Entra ID, you need to add it to Fabric workspaces as follows:
Ensure that access to service principals is allowed by enabling the following option in the Admin Portal:
After granting access, you should be able to establish a connection using the Service Principal. To connect to the Lakehouse in C# by generating a token with the client credentials flow, you can use the following sample code:
#region
using Microsoft.Identity.Client;
using System.Net.Http.Headers;
string ClientId = "appId";
string ClientSecret = "secret";
string Authority = "https://login.microsoftonline.com/tenantId";
#endregion
#region
string[] scopes = new string[] { "https://api.fabric.microsoft.com/.default" };
ConfidentialClientApplicationBuilder confidentialClientAppBuilder =
ConfidentialClientApplicationBuilder.Create(ClientId)
.WithClientSecret(ClientSecret)
.WithAuthority(Authority);
IConfidentialClientApplication confidentialClientApplication = confidentialClientAppBuilder.Build();
AuthenticationResult result = await confidentialClientApplication.AcquireTokenForClient(scopes)
.ExecuteAsync()
.ConfigureAwait(false);
Console.WriteLine(result.AccessToken);
Console.WriteLine();
#endregion
// Create client
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
string baseUrl = "https://api.fabric.microsoft.com/v1/";
client.BaseAddress = new Uri(baseUrl);
// Call list workspaces API
HttpResponseMessage response = await client.GetAsync("workspaces");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
Please don't hesitate to reach out to us if you have any other queries.
If you found the information helpful, we would greatly appreciate it if you could acknowledge it by selecting the Accept Answer & Upvote options.