SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.23k stars 994 forks source link

"Token request previously failed" for any attempt to get a token using AadHttpClient #9793

Open andrewpeterson99 opened 2 weeks ago

andrewpeterson99 commented 2 weeks ago

Target SharePoint environment

SharePoint Online

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

💥 SharePoint Framework

Developer environment

Linux

What browser(s) / client(s) have you tested

Additional environment details

Describe the bug / error

Some clients I'm working with have issues loading my Sharepoint integration on their site. For those clients who are experiencing the issue (which is not all of them), they get the following error:

Error: Token request previously failed
    at new t (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:103:184)
    at e._getTokenDataInternal (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:103:2580)
    at e._getTokenInternal (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:103:1480)
    at e.getToken (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:103:1077)
    at e.getToken (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:103:11037)
    at n._fetch (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:118:7290)
    at n.fetch (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:118:5748)
    at n.get (isolated-web-part-application-assembly_en-us_0163bd78c832d245659e31eafdd0fd47.js:118:6126)
    ...

This error is caused by the following lines in my application:

const tokenProvider = await this.context.aadTokenProviderFactory.getTokenProvider();
return await tokenProvider.getToken(Config.azureAppUrl);

I've managed to repro this on a local test account, and no matter how many reinstalls I do of my Sharepoint app, the error still occurs. I have other accounts where the app works fine and token requests go through. I tried following the steps here, but they did not resolve the issue. I am happy to provide any more details that are required. This is quite a big issue for my application since I rely on the JWT provided by MS as part of the auth process in my application's backend. Thank you for any help you can provide.

Steps to reproduce

This does not occur on every install of my application, and so I'm not sure exactly what's triggering it. However, this is what I have setup right now to repro it:

  1. Install my Sharepoint integration that makes a call to get a JWT in the callstack as part of the render() entrypoint for the webpart.
  2. Observe that the error discussed above appears.

Expected behavior

A token is returned as part of the call w/out an error as mentioned above (copied here): This error is caused by the following lines in my application:

const tokenProvider = await this.context.aadTokenProviderFactory.getTokenProvider();
return await tokenProvider.getToken(Config.azureAppUrl);
andrewpeterson99 commented 2 weeks ago

Testing this in an incognito window/with cookies cleared does not resolve this issue either.

andrewpeterson99 commented 5 days ago

By using a local override of my app in prod, I can see that the initial token request fails with: BrowserAuthError: monitor_window_timeout: Token acquisition in iframe failed due to timeout. However, it's not clear why since the same app works for me on the same connection on a different tenant.