Description
Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
💥 SharePoint Framework
Developer environment
macOS
What browser(s) / client(s) have you tested
- 💥 Internet Explorer
- 💥 Microsoft Edge
- 💥 Google Chrome
- 💥 FireFox
- 💥 Safari
- mobile (iOS/iPadOS)
- mobile (Android)
- not applicable
- other (enter in the "Additional environment details" area below)
Additional environment details
- browser version: Chrome, Version 136.0.7103.114 (Official Build) (arm64)
- SPFx version: 1.20.0
- Node.js version: 18.20.2
Describe the bug / error
We've been calling the Power BI REST API for about five years using a token retrieved from the web part context's AAD token provider. However, starting around Thursday, May 29 or Friday morning, May 30, the token no longer includes previously granted scopes, resulting in 401 Unauthorized errors on endpoints like https://api.powerbi.com/v1.0/myorg/groups
.
Although the Workspace.Read.All
permission is granted for the Power BI Service
resource, the generated token no longer includes this scope, which appears to be the cause of the failures.
Steps to reproduce
I built a dummy web part to showcase the unexpected behavior. See attached projects below for full reproduction.
Some specifics:
package-solution.json
contains following props:
"webApiPermissionRequests": [
{
"resource": "Power BI Service",
"scope": "Workspace.Read.All"
}
],
These permissions have been granted after the solution was installed, which can be seen on the service principal:
Token is retrieved using the web part context object:
const tokenProvider =
await context.aadTokenProviderFactory.getTokenProvider();
const accessToken = await tokenProvider.getToken(
"https://analysis.windows.net/powerbi/api"
);
API is then called using a simple fetch with auth bearer token:
// Try to fetch Power BI groups, this requires scope Workspace.Read.All or Workspace.ReadWrite.All
// https://learn.microsoft.com/en-us/rest/api/power-bi/groups/get-groups
const response = await fetch(
"https://api.powerbi.com/v1.0/myorg/groups",
{
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
}
);
The dummy web part will render something like this:
It shows that:
- fetching the token itself was successful
- fetching groups failed in an unexpected 401
- fetching reports was successful (because the token does contain a scope for this endpoint)
- the scopes in the token aren't what's to be expected
The full solution, zipped:
SPFx project.zip
The solution package (unzip first):
power-bi-api-401.sppkg.zip
Expected behavior
The Power BI Service token should contain all the scopes that have been granted to the SharePoint service principal.