Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mahmoodtahir
Regular Visitor

Cannot get access token

Hi,

I’m trying to integrate Power BI into my application. I’m trying to get access token from Azure directory using my Acure account.

One of MS Employee has uploaded this code. I just updated configurations (clientID) and it’s not working
https://github.com/guyinacube/Embed-API-Sample

I’ve also tried this code but have the same issue
https://github.com/Microsoft/PowerBI-Developer-Samples

 

{"error":"invalid_grant","error_description":"AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\nTrace ID: 4aa2b383-6a83-4052-91f0-021a8ff72300\r\nCorrelation ID: 25b0177d-8cd1-457f-9909-87f1f8a0b8bc\r\nTimestamp: 2017-11-13 14:41:58Z","error_codes":[70002,50126],"timestamp":"2017-11-13 14:41:58Z","trace_id":"4aa2b383-6a83-4052-91f0-021a8ff72300","correlation_id":"25b0177d-8cd1-457f-9909-87f1f8a0b8bc"}: Unknown error

1 ACCEPTED SOLUTION


@mahmoodtahir wrote:

Hi, yes it is valid power bi account and azure account (for both portals i've same email address)

 

if i use "User Owns Data" application, then i can get access token and see dashboards and everything

https://github.com/Microsoft/PowerBI-Developer-Samples

 

but if i use "App Owns Data" code then i get following error message

 

{"error":"invalid_client","error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.\r\nTrace ID: 1cd4832f-7748-4e25-92f3-bedc7c871700\r\nCorrelation ID: 2caf178e-af91-4d8d-86ca-2601f6813a0f\r\nTimestamp: 2017-11-15 09:54:08Z","error_codes":[70002],"timestamp":"2017-11-15 09:54:08Z","trace_id":"1cd4832f-7748-4e25-92f3-bedc7c871700","correlation_id":"2caf178e-af91-4d8d-86ca-2601f6813a0f"}: Unknown error

 

FYI:

If I hard code access token in "App Owns Data" then I can get all reports. As you know I can't hard code token it expires in an hour. (10mins to 1 day validity)

string accessToken = "ACCESS TOKEN";

var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
// Get a list of reports.
var reports = await client.Reports.GetReportsAsync();
}

 


@mahmoodtahir

The error message is different from the error in your original post. In this post, the error indicates that you're using a server-wide application, please register a native app instead.

View solution in original post

7 REPLIES 7
Eric_Zhang
Microsoft Employee
Microsoft Employee


@mahmoodtahir wrote:

Hi,

I’m trying to integrate Power BI into my application. I’m trying to get access token from Azure directory using my Acure account.

One of MS Employee has uploaded this code. I just updated configurations (clientID) and it’s not working
https://github.com/guyinacube/Embed-API-Sample

I’ve also tried this code but have the same issue
https://github.com/Microsoft/PowerBI-Developer-Samples

 

{"error":"invalid_grant","error_description":"AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\nTrace ID: 4aa2b383-6a83-4052-91f0-021a8ff72300\r\nCorrelation ID: 25b0177d-8cd1-457f-9909-87f1f8a0b8bc\r\nTimestamp: 2017-11-13 14:41:58Z","error_codes":[70002,50126],"timestamp":"2017-11-13 14:41:58Z","trace_id":"4aa2b383-6a83-4052-91f0-021a8ff72300","correlation_id":"25b0177d-8cd1-457f-9909-87f1f8a0b8bc"}: Unknown error


@mahmoodtahir

The error message is intuitive. What is the account and password in your App Owns Data sample? Can you confirem that account is a valid Power BI account?

Hi, yes it is valid power bi account and azure account (for both portals i've same email address)

 

if i use "User Owns Data" application, then i can get access token and see dashboards and everything

https://github.com/Microsoft/PowerBI-Developer-Samples

 

but if i use "App Owns Data" code then i get following error message

 

{"error":"invalid_client","error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.\r\nTrace ID: 1cd4832f-7748-4e25-92f3-bedc7c871700\r\nCorrelation ID: 2caf178e-af91-4d8d-86ca-2601f6813a0f\r\nTimestamp: 2017-11-15 09:54:08Z","error_codes":[70002],"timestamp":"2017-11-15 09:54:08Z","trace_id":"1cd4832f-7748-4e25-92f3-bedc7c871700","correlation_id":"2caf178e-af91-4d8d-86ca-2601f6813a0f"}: Unknown error

 

FYI:

If I hard code access token in "App Owns Data" then I can get all reports. As you know I can't hard code token it expires in an hour. (10mins to 1 day validity)

string accessToken = "ACCESS TOKEN";

var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
// Get a list of reports.
var reports = await client.Reports.GetReportsAsync();
}

 


@mahmoodtahir wrote:

Hi, yes it is valid power bi account and azure account (for both portals i've same email address)

 

if i use "User Owns Data" application, then i can get access token and see dashboards and everything

https://github.com/Microsoft/PowerBI-Developer-Samples

 

but if i use "App Owns Data" code then i get following error message

 

{"error":"invalid_client","error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.\r\nTrace ID: 1cd4832f-7748-4e25-92f3-bedc7c871700\r\nCorrelation ID: 2caf178e-af91-4d8d-86ca-2601f6813a0f\r\nTimestamp: 2017-11-15 09:54:08Z","error_codes":[70002],"timestamp":"2017-11-15 09:54:08Z","trace_id":"1cd4832f-7748-4e25-92f3-bedc7c871700","correlation_id":"2caf178e-af91-4d8d-86ca-2601f6813a0f"}: Unknown error

 

FYI:

If I hard code access token in "App Owns Data" then I can get all reports. As you know I can't hard code token it expires in an hour. (10mins to 1 day validity)

string accessToken = "ACCESS TOKEN";

var tokenCredentials = new TokenCredentials(accessToken, "Bearer");
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
// Get a list of reports.
var reports = await client.Reports.GetReportsAsync();
}

 


@mahmoodtahir

The error message is different from the error in your original post. In this post, the error indicates that you're using a server-wide application, please register a native app instead.

@Eric_Zhang, thanks a lot. solved the problem.

Juramirez
Resolver I
Resolver I

Hi @mahmoodtahir

 

Check this link https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-register-app/

It seems like you didn't Grant Permissions to your app

 

Regards

Thanks @Juramirez for your reply

 

If I use "User Owns Data" example then i can access token and able to embed dashboard

 

but If I use same registered app (in azure) with "App Owns Data" example then i get this issue.

@mahmoodtahir

 

I use AOD and the problem you're getting I solved it doing that. Please be sure you're following all steps in https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embed-sample-app-owns-data/ 

Did you change your web config parameters? 

 

Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.