Forum Discussion
Using acquireTokenWithClientCredentials, got token, but failed to use REST API - error "Unauthorized
I am following the Power BI embed guide: https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-sample-for-customers?tabs=net-core#client-id, using “Service Principle” for authentication. I see issues already:
Validation #1:
I download a nodejs sample code that is used to validate the embed.
} else if (config.authenticationMode.toLowerCase() === "serviceprincipal") {
authorityUrl = authorityUrl.replace("common", config.tenantId);
let context = new AuthenticationContext(authorityUrl);
return new Promise(
(resolve, reject) => {
context.acquireTokenWithClientCredentials(
config.scope,
config.clientId,
config.clientSecret,
function (err, tokenResponse) {
// Function returns error object in tokenResponse
// Invalid Username will return empty tokenResponse, thus err is used
if (err) {
reject(tokenResponse == null ? err : tokenResponse);
}
console.log(tokenResponse);
resolve(tokenResponse);
})
}
);
}
So far, I can see the “access token” is back, but while using that access token with Power BI REST API - Get Reports In Group, then I see an Error – Unauthorized.
Validation #2
If I test the REST API using: https://docs.microsoft.com/en-us/rest/api/power-bi/reports/getreportsingroup , then I can see the response coming back correctly.
Then, I noticed that the access token is different in term of what I get from nodejs code vs. the one in https://docs.microsoft.com/en-us/rest/api/power-bi/reports/getreportsingroup.
So I hard code the access token from Validation #2 into the nodejs code, then I can see the report I created in Power BI in testing web page, which is what I am looking for.
Now the question is why the access token I got from nodejs api is not working? Did I miss something? 😊
Any ideas?
Thanks,
Yong
- Anonymous5 years ago
It 's confiruration issue. I did have the admin rights. Asked IT admin to help out.
6 Replies
- V-lianl-msft
Community Support
Hi Anonymous ,
Please refer to these threads:
https://community.powerbi.com/t5/Developer/Generating-Power-Bi-Access-Token-in-NodeJS/td-p/276522
https://community.powerbi.com/t5/Developer/API-Generate-Embed-Token-in-Node-js/td-p/405201
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- AnonymousNot applicable
Thanks for the info. But the issue I have is different. We are not generating Access Token, we acquire the Access Token using Azure AD secret ... the issue is why the token returned does not work when it is used with Power BI REST API ?
Thanks
Yong
- AnonymousNot applicable
It 's confiruration issue. I did have the admin rights. Asked IT admin to help out.