Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 8 Next »

Power BI Authentication with Service Principal

Service principal authentication relies on the Power BI Tenant ID and the Azure Active Directory application ID that you provide in the lineage harvester configuration file. The password you need to access Power BI is the client secret key of the Azure Active Directory application.

Requirement

Enable the Admin API Settings (access read-only admin APIs) for the service principal in the Admin Portal of Power BI Service : Enable service principal authentication for read-only admin APIs - Microsoft Fabric | Microsoft Learn

  • Make sur to add the latter in a security group.

image-20250123-202012.png

Authentication & Authorization

We need to keep the following values to get the authorization from the Power BI Service : tenant id, client id and client secret associated with the service principal.

public static IContextServicePowerBI GetContextServicesFromPowerBI(string tenantId, string clientId, string clientSecret)
{
   var credential = new ClientSecretCredential(tenantId, clientId, clientSecret); // A service principal
   var accessToken = credential.GetToken(new Azure.Core.TokenRequestContext(new[] { "https://analysis.windows.net/powerbi/api/.default" }));
   var client = new HttpClient();
   client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token);
            
    return new ContextServicePowerBI("", "", accessToken.Token, "Url", client, client.DefaultRequestHeaders.Authorization, "", "", "");
}

Power BI REST APIs

Creation of a repository layer for the APIs

public interface IRepositoryAPI<T> where T : class
{
    T? GetById(string id);
    T? GetById(string id, string id2);
    IEnumerable<T>? GetAll();
    IEnumerable<T>? GetAll(string id);
    IEnumerable<T>? GetAll(string id, string id2);
}

Creation of the PBI objects for the T object

image-20250123-203820.png

PBI service return a JSON. So, we will have to deserialize the data.

public class RootGroup
{
        [JsonPropertyName("@odata.context")]
        public string? OdataContext { get; set; }
        public List<Group>? value { get; set; }
}
public class Group
{
    public bool isReadOnly { get; set; }
    public bool isOnDedicatedCapacity { get; set; }
    public Guid capacityId { get; set; }
    public string? defaultDatasetStorageFormat { get; set; }
    public string? type { get; set; }
    public Guid id { get; set; }
    public string? name { get; set; }
}

  • No labels