javascriptangularjsoauth-2.0ms-officeofficedev

Links and JS redirects, cause openning a new window in Office JS add-ins


I'm working on a gig which is an Office (Excel) 2016 add-in for data integration with a web application. We're using Office JS API, and the XML manifest file points to an AngularJS web app. Everything's OK and works properly so far.

Recently, we decided to add OAuth2 feature to the web app so that users can authenticate through a 3rd party authorization server.

The problem being, once I put a link (<a> tag) or run a window.location.replace() or set the window.location.href which points to a URL with a host name other than the one mentioned in the manifest file, it opens the URL in a new window, whereas I want it to just redirect to the URL within the Add-in window.

Any one's got any idea how to resolve this?

Thanks


Solution

  • To open the url in the add-in window, you'll need to add an entry for that url's domain in the AppDomains section of the Manifest file. For example, this snippet shows how to have links on www.northwindtraders.com appear within an add-in hosted on www.contoso.com.

    <?xml version="1.0" encoding="UTF-8"?>
    <OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="TaskPaneApp">
      <Id>c6890c26-5bbb-40ed-a321-37f07909a2f0</Id>
      <Version>1.0</Version>
      <ProviderName>Contoso, Ltd</ProviderName>
      <DefaultLocale>en-US</DefaultLocale>
      <DisplayName DefaultValue="Northwind Traders Excel" />
      <Description DefaultValue="Search Northwind Traders data from Excel"/>
      <AppDomains>
        <AppDomain>https://www.northwindtraders.com</AppDomain>
      </AppDomains>
      <DefaultSettings>
        <SourceLocation DefaultValue="https://www.contoso.com/search_app/Default.aspx" />
      </DefaultSettings>
      <Permissions>ReadWriteDocument</Permissions>
    </OfficeApp>