Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have registered an app with Azure AD and now have an Application ID (Register an Azure AD application to use with Power BI) i've now tried to complete step 2 of the process, which is to Get an authentiaction access token I have downloaded Visual Studio 2019 onto my laptop and followed the steps in the documentation, but I get the following errors:
CS0246 The type or namespace name 'Task<>' could not be found (are you missing a using directive or an assembly reference?)
CS1503 Argument 3: cannot convert from 'System.Uri' to 'Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential'
I can sort out the first error by changing the line below:
private static async Task<string> GetToken()
to:
private static string GetToken()
But i can't figure out how to correct the second issue.
Has anybody else come across this problem. Thank you
Hi @Anonymous i've done the following:
Home/App Registrations/{App Name}
API Permissions
Grant Admin Consent for {Directory}
Result - 'Successfully granted admin consent for the requested permissions'
I've tried the following in Postman again with the same result:
client_id - {Application (client) ID}
grant_type - password
resource - https://analysis.windows.net/powerbi/api
username - {my username}
password - {my password}
In 'API Permissions' I have 'Azure Active Directory Graph' and 'Power BI Service'. Am I missing any other permissions?
Thanks
Hi @rdc_green
Way 1:
In the sample, steps 2 is using
Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory -Version 2.21.301221612
Please make sure you have installed the package correctly.
In the newer ADAL v3, try this sample code.
using Microsoft.IdentityModel.Clients.ActiveDirectory; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication32 { class Program { static void Main(string[] args) { string token = GetToken(); Console.WriteLine(token); Console.ReadLine(); } #region Get an authentication access token private static string GetToken() { // TODO: Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory -Version 2.21.301221612 // and add using Microsoft.IdentityModel.Clients.ActiveDirectory //The client id that Azure AD created when you registered your client app. string clientID = "3f756axxxxxxx3662e"; //RedirectUri you used when you register your app. //For a client app, a redirect uri gives Azure AD more details on the application that it will authenticate. // You can use this redirect uri for your client app string redirectUri = "https://login.live.com/oauth20_desktop.srf"; //Resource Uri for Power BI API string resourceUri = "https://analysis.windows.net/powerbi/api"; //OAuth2 authority Uri string authorityUri = "https://login.windows.net/common/oauth2/authorize"; //Get access token: // To call a Power BI REST operation, create an instance of AuthenticationContext and call AcquireToken // AuthenticationContext is part of the Active Directory Authentication Library NuGet package // To install the Active Directory Authentication Library NuGet package in Visual Studio, // run "Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory" from the nuget Package Manager Console. // AcquireToken will acquire an Azure access token // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint AuthenticationContext authContext = new AuthenticationContext(authorityUri); //string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken; return authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri), new PlatformParameters(0)).Result.AccessToken; } #endregion } }
Way 2. Or you can have a test on getting access token or generate embed token by postman.
Enter the same link and body in postman.
For reference: Solved: Power BI REST API using postman - generate embed t... - Microsoft Power BI Community
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you @Anonymous for your suggestions I have attempted both ways and have the following issues:
Way 1
I have the following 4 errors
Way 2
I have the following error due to MFA
Hi @rdc_green
Please try below steps to fix Way 2:
1.Login as a tenant admin to https://portal.azure.com
2.Open the registration for your app in the
3.Go to Settings then Required Permissions
4.Press the Grant Permissions button
Note: If you are not a tenant admin, you cannot give admin consent
You may try the solutions provided in similar GitHub issue.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I managed to get my access token by disabling MFA in AAD
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
6 | |
4 | |
2 | |
2 |
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
3 |