Library name and version using Azure.Identity 1.9.0
Query/Question Currently I pick up a acces token in the following way:
AuthenticationResult authenticationResult = null;
var authenticationContext = new AuthenticationContext(authorityUrl + $"{TenantId.Trim()}");
var credential = new ClientCredential($"{SPId}", $"{SPSecret}");
authenticationResult = authenticationContext.AcquireTokenAsync(resourceUrl, credential).Result;
return authenticationResult;
with
- authorityUrl = https://login.microsoftonline.com/common
- TenantId = xxxxxx-xxxx-xxxx-xxxxx-xxxxxxxx (in form of)
- SPId = xxxxxx-xxxx-xxxx-xxxxx-xxxxxxxx (in form of)
- SPSecret = xxxxxxxxxxxxxxxxxxx= (in form of)
- resourceUrl= https://analysis.windows.net/powerbi/api
Within the new company regulations I cant no longer connect via this way and need to connect via ManagedIdentites.
In order to do this I wanted to make use of DefaultAzureCredential()
With the following code:
var tokenCredential = new DefaultAzureCredential();
var tokenContext = new TokenRequestContext( scopes: new string[] { resourceUrl });
var accessToken = await tokenCredential.GetTokenAsync(tokenContext);
I do get a token back but if I try to connect to the PBI reports, I get a 401 not authorised error and I dont understand why.
Do I need to add the authorityUrl and TenentId somewhere? If so, where or why not? I cant find an example where this connection to PBI is made so I am really stuck here..