cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
visuresh
Microsoft
Microsoft

Unauthorized access when trying to access PowerBI API with ClientCredentials

I am getting the token using the below code:

 

string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
string tenantID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;

ClientCredential clientcred = new ClientCredential(clientId, appKey);

AuthenticationContext authenticationContext = new AuthenticationContext(aadInstance + tenantID, new ADALTokenCache(signedInUserID));
AuthenticationResult authenticationResult = null;

authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceURL, clientcred).ConfigureAwait(false);

 

 

I get a valid token but when I try to call the rest API using https://analysis.windows.net/powerbi/api to refresh the dataset I get Unauthorized access. I call this from a Azure web app and it has permissions to Power BI.

 

1 REPLY 1
V-lianl-msft
Community Support
Community Support

Hi @visuresh ,

 

403 or 401? 

Make sure that the app that you registered with AAD has the read-write all datasets permission. 

You could also check this document:

https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-vs-authorization#daem... 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are You Ready?

Test your skills now with the Cloud Skills Challenge.

Top Solution Authors