I need to call a downstream API, i.e., PowerBI Service, from inside my Azure Function. I have a working example inside a web app but I am not able to make it happen inside my Azure Function.
In the web app sample, the configuration happens via Microsoft.Identity.Web like this.
services.AddMicrosoftIdentityWebAppAuthentication(Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddInMemoryTokenCaches();
Then inside a controller I am able to receive a ITokenAcquisition object injected in the constructor
public HomeController(ITokenAcquisition tokenAcquisition, ...
{
this._tokenAcquisition = tokenAcquisition;
and I can do:
var accessToken =
this._tokenAcquisition.GetAccessTokenForAppAsync(powerbiApiDefaultScope).Result;
and get a token credential like this:
var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
With this tokenCredentials I can achieve my goal, i.e., instantiate a PowerBIClient class to interact with PowerBI service.
var client = new PowerBIClient(new Uri(urlPowerBiServiceApiRoot), tokenCredentials);
The problem is that I am not able to set the configuration in the Startup class of my isolated Azure Function. Therefore, I cannot get a ITokenAcquisition injected in my Azure Fucntion that allows me to get an access token.
Could anybody please advice? Thanks a million.