sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

The issue with calling Azure AD secured API by using AadHttpClient.

Open rememberDL opened this issue 7 years ago • 51 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

We use aadHttpClientFactory from SP context in order to work with Azure App Service API . And it worked very well.

Observed Behavior

When I call Azure App Service API by using AadHttpClient I get the error in the browser console:

TypeError: Cannot read property 'call' of undefined
    at o (listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js:19)
    at o.t (listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js:19)

Steps to Reproduce

  1. Create a SPFx 1.9.1 (it doesn't work both in version 1.9.1 and in version 1.7.1) extension (both ListView Command Set and Field Customizer) solution
  2. Use AadHttpClient to access Azure App Service

Sample code we use:

      const aadClicent = await this.context.aadHttpClientFactory.getClient(""8dexxx-xxx-xxx-xxx"");
      requestHeaders.append('Content-type', 'application/json');
      const httpClientOptions: IHttpClientOptions = {
        headers: requestHeaders
      };
      const response = await aadClicent.get("https://xxxxxx.azurewebsites.net/api/xxxxx/checkid/", 
          AadHttpClient.configurations.v1, httpClientOptions);
      const json = await response.json();

      if (response.status == 200) {
        return json;
      }
      else {
        return null;
      }

It should be noted: this.context above is ExtensionContext This code worked very well until 2019-10-29.

rememberDL avatar Oct 30 '19 12:10 rememberDL

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Oct 30 '19 12:10 msft-github-bot

We get the same error when using MSGraphClient. It stopped working the last 2 hours.

nmnikolov avatar Oct 30 '19 15:10 nmnikolov

this error happens with the aadHttpClientFactory as well as trying to get a token from the AadTokenProvider. Working fine from a WebPart but not in a CommandSet Extension (hence the listview related error).

ghost avatar Oct 30 '19 15:10 ghost

Same issue here happening in 2 tenants. Our code was working fine before and nothing has changed. Same issue reported here: https://github.com/SharePoint/sp-dev-fx-extensions/issues/265

andygjones-nz avatar Oct 30 '19 18:10 andygjones-nz

Same issue. Our code was working fine yesterday (2019-10-29).

patrickbeaulieu72 avatar Oct 30 '19 19:10 patrickbeaulieu72

Same here. This bug is a showstopper to our Azure related services. It started already 2019-10-28.

punamaki avatar Oct 31 '19 07:10 punamaki

It stopped working for us too, please fix this ASAP as it is causing major issues and most of the applications don't work. 🧯🔥

nayots avatar Oct 31 '19 08:10 nayots

We are facing the same issue. Extension in view worked perfectly before.

ltdu avatar Oct 31 '19 10:10 ltdu

I'm unable to repro... was the issue possibly temporary?

Network trace two demo web parts... one uses AADHttpClient & the other uses MSGraphClient...

image

andrewconnell avatar Oct 31 '19 19:10 andrewconnell

We're still experiencing it and is consistent. We're getting it on list extensions using AADHttpClient. image

andygjones-nz avatar Oct 31 '19 20:10 andygjones-nz

Please provide the code you're using to call the client... the following code is working in multiple tenants I've tested, so I'm not able to repro this...

  public getCurrentUser(): Promise<any> {
    return new Promise<any>((resolve, reject) => {
      this.context.aadHttpClientFactory
        .getClient('https://graph.microsoft.com')
        .then((client: AadHttpClient) => {
          client.get('https://graph.microsoft.com/v1.0/me', AadHttpClient.configurations.v1)
          .then((response: HttpClientResponse) => {
            return response.json();
          })
          .then((jsonResponse: any) => {
            resolve(jsonResponse);
          })
          .catch((error) => {
            reject(error);
          });
        });
    });
  }

andrewconnell avatar Oct 31 '19 20:10 andrewconnell

This is some test code. It's trying to call an Azure function secured by AAD. Framework is v1.9.0

public test(): Promise<any> {
    const requestOptions: IHttpClientOptions = {
      body: JSON.stringify({
      SiteUrl: "http://blah.com",
      Fullpath: "/something.doc"
      })
    };

return new Promise<any>((resolve, reject) => {
      this.context.aadHttpClientFactory
      .getClient("320xxx-xxx-xxx-xxx") //App Id
      .then((client: AadHttpClient): void => { 
          client.post('https://xxxxxxx.azurewebsites.net/api/ValidateFilename', AadHttpClient.configurations.v1, requestOptions)
          .then((res: HttpClientResponse): Promise<any> => {
              if (res.status == 200) {
                  return res.json();
              } else {
                  throw new Error("An error occured. Please try again");
              }
          })
          .catch(err => {
              reject(err);
          });
    });
  });
}

andygjones-nz avatar Oct 31 '19 21:10 andygjones-nz

I've also been able to repro using this /me graph call in a fresh Yeoman helloworld listview customiser (v1.9.1) so not sure if it's tenant specific? It's occuring in both our O365 developer tenant and production tenant.

Please provide the code you're using to call the client... the following code is working in multiple tenants I've tested, so I'm not able to repro this...

  public getCurrentUser(): Promise<any> {
    return new Promise<any>((resolve, reject) => {
      this.context.aadHttpClientFactory
        .getClient('https://graph.microsoft.com')
        .then((client: AadHttpClient) => {
          client.get('https://graph.microsoft.com/v1.0/me', AadHttpClient.configurations.v1)
          .then((response: HttpClientResponse) => {
            return response.json();
          })
          .then((jsonResponse: any) => {
            resolve(jsonResponse);
          })
          .catch((error) => {
            reject(error);
          });
        });
    });
  }

andygjones-nz avatar Oct 31 '19 21:10 andygjones-nz

What's the release configuration of the tenants, TR/SR?

andrewconnell avatar Oct 31 '19 22:10 andrewconnell

Dev tenant is TR for all. Production is TR for certain users - have tried for a TR and SR user and the same occurs.

I've just switched our dev tenant over to SR for all to see what happens - I assume this takes a while to have take effect so will report back once it does. Is there an easy way to tell if a user is seeing SR?

andygjones-nz avatar Oct 31 '19 22:10 andygjones-nz

Dev tenant has now switched to SR and can confirmed the same issue exists whether SR or TR.

andygjones-nz avatar Nov 01 '19 02:11 andygjones-nz

Same issue using fieldcustomizer on one of 3 tested tenants

sample code: image

console.log is never hit instead error: “listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js:19 Uncaught (in promise) TypeError: Cannot read property 'call' of undefined at o (listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js:19) at o.t (listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js:19)” “https://spoprod-a.akamaihd.net/files/sp-client-prod_2019-10-18.025/listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js” ” https://spoprod-a.akamaihd.net/files/sp-client-prod_2019-10-18.025/listview-host-assembly_default_65e11fefa9767af7e7b350ea75aebfbd.js”

zaiby avatar Nov 01 '19 06:11 zaiby

I noticed that we have the issue using both AadHttpClient and MSGraphClient with the latest version of SPFx 1.9.1. There is no issue when using older version of SPFx 1.7.0 on the same tenant.

nmnikolov avatar Nov 01 '19 06:11 nmnikolov

I noticed that we have the issue using both AadHttpClient and MSGraphClient with the latest version of SPFx 1.9.1. There is no issue when using older version of SPFx 1.7.0 on the same tenant.

Strange I have a fieldcustomizer using 1.9.1 not working and a normal SPFx webpart also 1.9.1 which works on same tenant. Maybe it's just coincident that 1.7.0 works?

The SPFx which works is '"isDomainIsolated": true,' if that helps.

zaiby avatar Nov 01 '19 06:11 zaiby

Another gues is that it my be related only to extensions. With a new fresh SPFx 1.9.1 webpart I have no issues using the graph client. I noticed the issue when using extensions.

nmnikolov avatar Nov 01 '19 06:11 nmnikolov