Wednesday, June 7, 2023

Call Power BI API from .net Core API with Delegated Permissions

 If you want to consume Power BI API from .net Core API there are multiple ways of doing it. 

1. Call with Delegated Permission. 

2. Call with Service Principle. 

Certain endpoints cannot be called with Service Principle. Like you want to get the list of reports that caller user has access too. In this case, you'll need to use Delegated Permission. 

In order to achieve this in ASP.NET Core API,  you need to do the following 


1. Register an App in Azure. 

2. Go to API Permissions and select the Delegated Permissions for Power BI Service. 

3. In your API, you need to inject the following. 


3. Pay attention to the method "GetAccessTokenForUserAsync" used to get the delegated access and the ClaimPrincipal is passed in the method. 

4. This will give you the token which you can use to call the Power BI API. 




Thursday, May 4, 2023

Some Useful features - Microsot Devleoper World!!

 Here are some of the new and exciting features in Microsoft Dev World.

Some of them are available in preview. 

EF Core Power Tool - To generate DB Context

 Nice tool with a lots of customization to generate the DB Schema. 

EF Core Power Tools 

There are lot of material available on how to get started and it is very straight forward to start using it. 

Best thing I like about this and why I used it to customize the name of the Class which is being generated. If you have multiple table with the same name but in the different schema, by default the class name are appended with 1,2. 

For example,

If you have two tables, 

Local.Customer
Master.Customer

Then default EF core will generate the class name as Customer & Customer1. Not that intuitive. 

With EF Core Power Tools, You can customize the class name generation. 

Create a new file with the name "efpt.renaming.json" and put it inside the same folder as your "efpt.config.json".





    







You can also customize the columns inside a table. 

* If you are renaming multiple tables from a single schema, add all of them in the same Tables array. 

 I would try to create a small video some time and share the link.

Until next Cheers!