SharePoint / SharePoint/sp-dev-docs

SPFX + Service Bus using SPFX AAD Token

Open
#10,394 9 comments 0 reactions 1 assignee View on GitHub

@Ashlesha-MSFT is already working on this.

Since Sep 5, 2025.

area:spfx sharepoint-developer-support type:bug-confirmed
Dominant language
PowerShell
Stars
1.4k
Forks
1.1k
Avg merge
4d 12h
Merged PRs (30d)
12

Description

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

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 latest
  • SPFx version 1.21.1
  • Node.js version 22
  • etc
Issue description

In the SPFX it's possible to make HTTP requests to Azure using AadHttpClient.post / get.

But sometimes it fails to get the access token inside of these post / get methods with error "Error: Token request previously failed".

To avoid this I currently getting token (from context.aadTokenProviderFactory.getTokenProvider() + then getToken => which returns the token string) and make the usual JS fetch request with this token.

Getting token is secured with the retry and w/o cache to avoid the error above.

Obviously I try to avoid send connection string or other credentials to the frontend except of the Entra ID token.

Questions:

  1. Is there a way to use AadHttpClient.post / get but with possibility to request a new token if "Error: Token request previously failed" ?
  2. Since it's used for Service Bus ideally would be using their native library, but during the tests seems it's impossible to implement TokenCredential with SPFX AAD Token, maybe because it lacks other props from accesstoken, is there a way in SPFX getting these? (nuances if service bus lib is working at all in the browser is another topic, rather not) Preferrably in a form of TokenCredential, but not nesessarily.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.