OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
671 stars 96 forks source link

Getting Cross-Origin error when using OWA rest api in owa add-in in On-Premises #991

Closed sarea closed 2 years ago

sarea commented 4 years ago

I'm getting this error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https:///{onPremisesOrigin}/v2.0/me/messages/…/?$expand=attachments($select=Name,Size,IsInline,ContentType). (Reason: CORS request did not succeed).

when fetching the message using OWA REST API As far as I know, using rest api is available since the add-in api 1.5, which has to be supported as it's mentioned this the documentation Is this a bug or On-Premises dose not support OWA rest api? if so do I need to do hybrid deployments? following this and this? knowing that in the first link it says in preview! Thanks

Environment

Exchange On-Premises 2019 CU4 Office api 1.5

schmkr commented 4 years ago

Some more info: we have identified this is an issue with configuring IIS to allow CORS requests to the rest api url provided at Office.context.mailbox.restUrl.

We cannot find any documentation on the side of OWA, nor on on the side of On Premise Exchange, how IIS is supposed to be configured to allow Add-Ins to request the Rest API. The only thing on the OfficeJs side, is this page, but the solutions provided their don't work for us.

(or, thinking out loud while I write, does JSONP as mentioned on that last page work for the REST API?)

exextoc commented 4 years ago

OWA REST API is not supported on On-Prem. You will have to hit Hybrid endpoint to make it work, Or you can try using EWS API for your scenario.

schmkr commented 4 years ago

Where can I find that in the documentation?

robino2020 commented 4 years ago

As I understand:

exextoc commented 4 years ago

yes, Outlook add-in Javascript API requirement set 1.5 is supported in both Exchange 2019 and 2016 on-premise. But the Javascript API requirement set 1.5 supports calling REST API only for Online. Its a documentation miss and we will add an workitem in our backlog to update it. For REST API, check the documentation

schmkr commented 4 years ago

Thanks for that explanation @exextoc.

You will have to hit Hybrid endpoint

How can an Add-In know if it has to hit that Hybrid endpoint or the regular REST API endpoint?

And wouldn't it make sense to set the url of the Hybrid endpoint on the Office.context.mailbox.restUrl so Add-In can work seamlessly no matter their environment? Or would an OnPrem Exchange set up in Hybrid mode already do this?

robino2020 commented 4 years ago

@exextoc is using REST API in hybrid deployment already GA? As the documentation is updated May 2019 and mentions:

Note: The ability to use these REST APIs in hybrid deployments is currently in preview.

exextoc commented 4 years ago

yes this ability is currently in preview, Can you try doing the REST call from server in onPrem.

exextoc commented 4 years ago

@sarea

We would like to clarify few things on what we mentioned in earlier comments. Hybrid deployment is NOT a requirement for REST API to work.

For On-Premise case:

  1. REST APIs does not work from a browser (addin) because of CORS issue (enforced by browser). We believe this is what you are observing right now.
  2. But REST token can be used from addin-backend and REST API is suppose to work in this case. There is no "Hybrid deployment" requirement for this.
robino2020 commented 4 years ago

@exextoc any ideas on how to fix the CORS issue (enforced by browsers)? Is this something you can solve by changing certain settings in Internet Information Services (IIS) on Microsoft Server?

exextoc commented 4 years ago

Regarding CORS issue, it is enforced by the browser. You can read more here.

As long as you try to hit REST APIs from the browser, it will throw the CORS issue. It is independent of where you have hosted your web files. Whether it is locally hosted using IIS or hosted on Microsft servers. You can find the reason behind it in the above URL.

The workaround suggested for the same was given in the previous response, REST token can be used from addin-backend and REST API is supposed to work in this case. You can try that and let us know if it works.

ghost commented 4 years ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

ghost commented 4 years ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.

robino2020 commented 4 years ago

yes, Outlook add-in Javascript API requirement set 1.5 is supported in both Exchange 2019 and 2016 on-premise. But the Javascript API requirement set 1.5 supports calling REST API only for Online. Its a documentation miss and we will add an workitem in our backlog to update it. For REST API, check the documentation

@exextoc is the documentation already updated or is there a way for us to track when this is done?

cody-lettau commented 2 years ago

@exextoc what is meant by the "addin-backend"? I am running into this for a customer with an on-prem setup using an add-in in OWA. We are trying to figure out how to make the REST API calls work in OWA for that customer.

exextoc commented 2 years ago

"Add-in backend" denotes "Addin-server" over here. We currently do not support REST calls in on-prem, and kindly use EWS calls. For more info, kindly check https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/use-rest-api#call-the-api

cody-lettau commented 2 years ago

Thanks for the answer @exextoc. Are there any plans to add support for use of the REST API in an on-prem environment? Having to rely on SOAP/XML in 2021 is a bit cumbersome...

ghost commented 2 years ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

exextoc commented 2 years ago

Currently the feature: REST API in an on-prem environment, you requested, is not a part of the product. We track Outlook add-in feature requests on our Tech Community Page. Please submit your request there and choose the appropriate label(s). Feature requests on Tech Community are considered when we go through our planning process.

Github Label: “Type: product feature request”

https://aka.ms/M365dev-suggestions

[Outlook Add-ins Engineering Team]

ghost commented 2 years ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

ghost commented 2 years ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.