SPFx webparts not able to acquire token in SharePoint
Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
💥 SharePoint Framework
Developer environment
None
What browser(s) / client(s) have you tested
- [ ] 💥 Internet Explorer
- [ ] 💥 Microsoft Edge
- [X] 💥 Google Chrome
- [X] 💥 FireFox
- [ ] 💥 Safari
- [ ] mobile (iOS/iPadOS)
- [ ] mobile (Android)
- [ ] not applicable
- [ ] other (enter in the "Additional environment details" area below)
Additional environment details
- browser version - firefox 131
- SPFx version - 1.18.1
- Node.js version 18
Describe the bug / error
We have created a Webpart for SharePoint. This webpart loads a button in SharePoint document collections when items are selected. Pressing the button calls our own separate API. A token is included in the header of the request.
Before the request is initiated a token is fetched.
const tokenProvider = await this.context.aadTokenProviderFactory.getTokenProvider();
const authToken = await this.tokenProvider.getToken(config.authAppId);
This produces a GET request that fails with error 500
https://testinfoprojects.sharepoint.com/sites/dev-testing/_api/Microsoft.SharePoint.Internal.ClientSideComponent.Token.AcquireOBOToken?resource='api://iprox******'&clientId='ac5c3377-6028-42d9-a545-07699813e16d'
Error response:
{
"odata.error": {
"code": "-1, System.AggregateException",
"message": { "lang": "en-US", "value": "One or more errors occurred." }
}
}
where api://iprox****** is an app registration in our tenant.
I've found similar issues: https://techcommunity.microsoft.com/t5/sharepoint-developer/spfx-webparts-not-able-to-acquire-token-for-graph-api-in-teams/m-p/3886488 which leads to: https://github.com/SharePoint/sp-dev-docs/issues/9099#issuecomment-1701406090
and this one: https://github.com/SharePoint/sp-dev-docs/issues/4915
Neither proposed solutions by others have any effect on the error.
We're kind of lost here at the moment.
Steps to reproduce
1. 2. 3.
Expected behavior
A 200 status code after which the webpart can use the token in its headers
I have the same issue.
My code:
return await this.context.aadHttpClientFactory
.getClient(this.resourceEndpoint)
.then((client: AadHttpClient) =>
client
.post(this.externalApiAuthUrl, AadHttpClient.configurations.v1, httpClientOptions)
.catch(r => { // "One or more errors occurred."
console.log(r);
})
.then((response: HttpClientResponse): Promise<string> => response.json())
).then(token => token);
@svrijsewijk , Please check this answer, it helps for me - https://github.com/SharePoint/sp-dev-docs/issues/9099#issuecomment-1701406090
Hello @svrijsewijk, Thank you for bringing this issue to our attention. We will look into it and get back to you shortly.
@svrijsewijk, Will you please confirm, if https://github.com/SharePoint/sp-dev-docs/issues/9099#issuecomment-1701406090 works for you as well.
We are closing this issue for now. If the problem persists, feel free to reopen it or open a new one.