I am new to Azure Function apps. Just to brief my requirement and the issue that I am facing. I want to communicate to the
Microsoft.IdentityModel.Clients.ActiveDirectory through my user credentials(azure account) and generate a token through which I can refresh a Power BI dataset.
Now as part of my Windows Azure Function, Please Note: I am trying to write the piece of code in the azure portal functions(HttpTriggers) iteslf i.e the sandbox. As windows function apps support .Net frmaework 4.6 installing nuget packages using project.json, I have installed the Microsoft.IdentityModel.Clients.ActiveDirectory
dll version 3.14.x(latest) through project.json.
Then I am trying to get the token using the below line of code
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
string token = authContext.AcquireTokenAsync(resourceUri, clientID, new UserPasswordCredential(username, password)).Result.AccessToken;
(Please Note: authorityUri = "https://login.windows.net/common/oauth2/authorize"; clientID="myclientid";resourceUri = "https://analysis.windows.net/powerbi/api"
)
(Please Note: Microsoft.IdentityModel.Clients.ActiveDirectory dll v 3.x onwards does not support AcquireToken function so using AcquireTokenAsync)
Now I am getting an error in this line with an exception "AADSTS50131: AccessPolicy does not allow token issuance.".
When I am calling the same through my WEB API function I am able to generate the token.
Any kind of help on this will be of great importance.
Thanks in advance.