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

AadHttpClient sandbox iframe restrictions issue

Open duffysp opened this issue 7 years ago • 6 comments

Category

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

Expected or Desired Behavior

For the response to be output to the console

Observed Behavior

I have an SPFX Web part running on 1.7.0 using AADHttpClient that generates the following error in the console when the page is opened: Unsafe JavaScript attempt to initiate navigation for frame with origin from frame with URL 'https://login.microsoftonline.com/... The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

Code: ` let client = new AadHttpClient(this.context.serviceScope, 'xxxxx');

client.get('https://xxxxx.azurewebsites.net/api/HttpTrigger1', AadHttpClient.configurations.v1)
  .then((res: HttpClientResponse): Promise<any> => {
  return res.json();
  })
  .then(data => {
  console.log(data);
  });`

Steps to Reproduce

Create a new web part, add the code above and try to authenticate.

Thanks for your contribution! Sharing is caring.

duffysp avatar Mar 14 '19 13:03 duffysp

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

msft-github-bot avatar Mar 14 '19 13:03 msft-github-bot

Same issue here. Can also reproduce with the MsGraphClient sample code:

    this.context.msGraphClientFactory
      .getClient()
      .then((client: MSGraphClient): void => {
        // get information about the current user from the Microsoft Graph
        client
          .api('/me')
          .get((error, response: any, rawResponse?: any) => {
            // handle the response
        });
      });

deodad avatar Mar 14 '19 13:03 deodad

So I managed to get rid of the error. I tried going to the URL that it was complaining about in the console: https://login.microsoftonline.com/....etc and it gave error: "The reply url specified in the request does not match the reply urls configured for the application" <- I KNOW I setup my Azure Function Registration correctly so started looking for the ID it mentioned. Turns out the app it was talking about was NOT the one I setup for my azure function but the one created when I deployed the app to SharePoint.

@adaddeo to see if you have the same issue, note the name of your web part (shown in the name property in package.json) go to Azure Portal > Azure Active Directory > App Registrations (Preview) > look for yourappname-client-side-solution (Make sure you click "All Applications" tab as it won't show in Owned Applications) > Authentication > then add https://yourtenant.sharepoint.com/_forms/spfxsinglesignon.aspx

This has now resolved my issue. I raided a few blogs but none of them mention the App Registration that SharePoint created but I noticed they called their initial app registration the same name as their app (mine was different):

https://github.com/SharePoint/sp-dev-docs/blob/master/docs/spfx/use-aadhttpclient-enterpriseapi.md https://spblog.net/post/2018/07/30/Call-Azure-AD-secured-API-from-your-SPFx-code-Story-3-Web-app-(or-Azure-Function)-and-SPFx-with-AadHttpClient

duffysp avatar Mar 15 '19 14:03 duffysp

Thanks @duffysp, that resolved the issue for me as well.

deodad avatar Mar 15 '19 16:03 deodad

Closing issue. Solution above.

duffysp avatar Mar 18 '19 11:03 duffysp

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 25 '20 00:01 msft-github-bot