AadHttpClient sandbox iframe restrictions issue
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
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.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
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
});
});
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
Thanks @duffysp, that resolved the issue for me as well.
Closing issue. Solution above.
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