|
1 | 1 | ---
|
2 | 2 | title: Creating SharePoint Add-ins that use the cross-___domain library
|
3 |
| -ms.date: 09/25/2017 |
| 3 | +description: Intended for scenarios where the add-in has cloud-hosted components, but the customer's corporate firewall makes it difficult to use the low-trust system. The user's browser blocks scripts from other domains, but the JavaScript library encapsulates a secure system for working around this restriction. |
| 4 | +ms.date: 12/27/2017 |
4 | 5 | ms.prod: sharepoint
|
5 | 6 | ---
|
6 | 7 |
|
7 | 8 |
|
8 |
| -# Creating SharePoint Add-ins that use the cross-___domain library |
9 |
| -Learn about the SharePoint cross-___domain JavaScript library. |
10 |
| - |
| 9 | +# Creating SharePoint Add-ins that use the cross-___domain library |
11 | 10 |
|
12 |
| - |
| 11 | +There are some scenarios in which neither the low-trust nor the high-trust authorization systems can be used by a SharePoint Add-in, or they are not a good choice as the only means for the add-in to gain authorization to SharePoint resources. |
13 | 12 |
|
14 |
| -There are some scenarios in which neither the low-trust nor the high-trust authorization systems can be used by a SharePoint Add-in, or they are not a good choice as the only means for the add-in to gain authorization to SharePoint resources. Examples: |
15 |
| - |
| 13 | +Examples: |
16 | 14 |
|
17 |
| -- The remote components of the SharePoint Add-in are not on-premise, but a corporate firewall blocks server-to-server communication between SharePoint and ACS, thereby preventing the use of the low-trust system. |
| 15 | +- The remote components of the SharePoint Add-in are not on-premises, but a corporate firewall blocks server-to-server communication between SharePoint and ACS, thereby preventing the use of the low-trust system. |
18 | 16 |
|
19 |
| - |
20 | 17 | - The SharePoint Add-in is designed as a single-page web application that relies on client-side JavaScript for data operations with SharePoint.
|
21 | 18 |
|
22 |
| - |
23 | 19 | - The SharePoint Add-in relies mainly on server-to-server calls to access SharePoint data (and is authorized by either the low-trust or high-trust systems), but it needs to be supplemented with some JavaScript calls. For example, a graphics-heavy page can use JavaScript to make minor updates to displayed data without having to reload the entire page.
|
24 | 20 |
|
25 |
| - |
26 |
| -However, [for security](http://msdn.microsoft.com/en-us/library%28d=robot%29/cc709423(d=robot,l=en-us,v=vs.85).aspx), browsers do not allow JavaScript that is hosted on one ___domain to access resources on another ___domain, so a special technique is required to allow the remote JavaScript to access SharePoint resources. The SharePoint cross-___domain JavaScript library makes it easy for your remote web application to use the technique. |
| 21 | +However, [for security](https://msdn.microsoft.com/en-us/library(d=robot)/cc709423(d=robot,l=en-us,v=vs.85).aspx), browsers do not allow JavaScript that is hosted on one ___domain to access resources on another ___domain, so a special technique is required to allow the remote JavaScript to access SharePoint resources. The SharePoint cross-___domain JavaScript library makes it easy for your remote web application to use the technique. |
27 | 22 |
|
28 | 23 | > [!NOTE]
|
29 |
| -> The cross-___domain library is also used to allow access to data in the reverse direction; that is, to allow JavaScript on a SharePoint page to access data in a remote ___domain. See [Access remote data from a SharePoint page](#ReverseDirection) for more information. |
30 |
| - |
31 |
| - |
| 24 | +> The cross-___domain library is also used to allow access to data in the reverse direction; that is, to allow JavaScript on a SharePoint page to access data in a remote ___domain. For more information, see [Access remote data from a SharePoint page](#ReverseDirection). |
32 | 25 |
|
33 | 26 | ## Understand the architecture of the cross-___domain library
|
34 | 27 |
|
35 |
| -The SharePoint cross-___domain library is contained in the file SP.RequestExecutor.js which is located in the /_layouts/15/ virtual folder of every SharePoint website. The scripts in this file encapsulate a secure well-known technique for overcoming the browser's restriction on cross-___domain scripting: An iFrame can communicate with its parent page by means of the `window.postMessage()` function, even if the page in the iFrame is in a different ___domain. So data requests and responses are passed over the ___domain boundary by using calls to `postMessage()`. |
| 28 | +The SharePoint cross-___domain library is contained in the file SP.RequestExecutor.js, which is located in the /_layouts/15/ virtual folder of every SharePoint website. The scripts in this file encapsulate a secure well-known technique for overcoming the browser's restriction on cross-___domain scripting: an iFrame can communicate with its parent page by means of the `window.postMessage()` function, even if the page in the iFrame is in a different ___domain. So data requests and responses are passed over the ___domain boundary by using calls to `postMessage()`. |
36 | 29 |
|
37 |
| - |
38 |
| - |
39 |
| - |
40 |
| - **Caution** The `postMessage()` function works only on browsers that support HTML 5, so SharePoint Add-ins that use the cross-___domain library will not work on older browsers. |
| 30 | +> [!WARNING] |
| 31 | +> The `postMessage()` function works only on browsers that support HTML 5, so SharePoint Add-ins that use the cross-___domain library will not work on older browsers. |
41 | 32 |
|
| 33 | +For SharePoint, the cross-___domain library is loaded on a page of the remote web application where it creates a hidden iFrame that hosts a special proxy page from the SharePoint ___domain. The proxy page already exists on every SharePoint website. |
42 | 34 |
|
43 |
| -For SharePoint, the cross-___domain library is loaded on a page of the remote web application where it creates a hidden iFrame that hosts a special proxy page from the SharePoint ___domain. The proxy page already exists on every SharePoint website. The library is used to create a JavaScript Object Notation (JSON) object which contains all the information needed to make a CRUD call to the REST APIs of SharePoint. The JSON object is passed to the proxy page by using `postMessage()`. On the proxy page, where the library is also loaded, the JSON object is parsed and reconstructed as a REST call to SharePoint. Since the proxy page is in the SharePoint ___domain, the browser allows the call. |
44 |
| - |
| 35 | +The library is used to create a JavaScript Object Notation (JSON) object which contains all the information needed to make a CRUD call to the REST APIs of SharePoint. The JSON object is passed to the proxy page by using `postMessage()`. On the proxy page, where the library is also loaded, the JSON object is parsed and reconstructed as a REST call to SharePoint. Because the proxy page is in the SharePoint ___domain, the browser allows the call. |
45 | 36 |
|
46 |
| - |
47 | 37 | Of course, the remote components of the SharePoint Add-in still have to have authorized access to the SharePoint resources. There are two ways to do this:
|
48 |
| - |
49 | 38 |
|
50 |
| - |
51 |
| - |
52 |
| -- Set the add-in principal type to **RemoteWebApplication** (the default for provider-hosted apps) in the add-in manifest. When the add-in is registered with ACS, the registration includes the ___domain of the remote web application. SharePoint trusts domains that are registered with ACS, even though it is not, in this scenario, using any of the token passing flows that are part of the server-side low-trust system. For detailed information about registering add-ins, see [Register SharePoint Add-ins 2013](register-sharepoint-add-ins.md). |
| 39 | +- Set the add-in principal type to **RemoteWebApplication** (the default for provider-hosted apps) in the add-in manifest. When the add-in is registered with ACS, the registration includes the ___domain of the remote web application. SharePoint trusts domains that are registered with ACS, even though it is not, in this scenario, using any of the token passing flows that are part of the server-side low-trust system. For detailed information about registering add-ins, see [Register SharePoint Add-ins](register-sharepoint-add-ins.md). |
53 | 40 |
|
54 |
| - |
55 |
| -- In a SharePoint-hosted add-in, you can leave the add-in principal type set to its default, which is **Internal**. Then set the **AllowedRemoteHostUrl** attribute of the **Internal** element to the URL of the remote web application, as in the following example. |
| 41 | +- In a SharePoint-hosted add-in, you can leave the add-in principal type set to its default, which is **Internal**. You can then set the **AllowedRemoteHostUrl** attribute of the **Internal** element to the URL of the remote web application, as in the following example. |
56 | 42 |
|
57 |
| -``` |
| 43 | +```XML |
58 | 44 | <AppPrincipal>
|
59 |
| - <Internal AllowedRemoteHostUrl="https://example.com/Home.html" /> |
60 |
| -</AppPrincipal> |
| 45 | + <Internal AllowedRemoteHostUrl="https://example.com/Home.html" /> |
| 46 | + </AppPrincipal> |
61 | 47 | ```
|
62 | 48 |
|
63 | 49 | > [!NOTE]
|
64 |
| -> If you use the second option (an **Internal** add-in principal), then you can use only JavaScript and the cross-___domain library to access SharePoint. The SharePoint client object model is blocked for **Internal**SharePoint Add-ins, so you cannot have a dual authorization system that uses both the cross-___domain library and either the low-trust or high-trust systems. |
65 |
| - |
| 50 | +> If you use the second option (an **Internal** add-in principal), you can use only JavaScript and the cross-___domain library to access SharePoint. The SharePoint client object model is blocked for **Internal** SharePoint Add-ins, so you cannot have a dual authorization system that uses both the cross-___domain library and either the low-trust or high-trust systems. |
66 | 51 |
|
67 |
| -For details on how to use the library, see [Access SharePoint data from add-ins using the cross-___domain library](access-sharepoint-data-from-add-ins-using-the-cross-___domain-library.md). |
| 52 | +For details on how to use the library, see [Access SharePoint data from add-ins using the cross-___domain library](access-sharepoint-data-from-add-ins-using-the-cross-___domain-library.md). |
68 | 53 |
|
69 | 54 |
|
70 |
| - |
| 55 | +<a name="ReverseDirection"> </a> |
71 | 56 |
|
72 | 57 | ## Access remote data from a SharePoint page
|
73 |
| -<a name="ReverseDirection"> </a> |
74 |
| - |
75 |
| -The SharePoint cross-___domain library can also be used in the reverse direction; that is, JavaScript on a SharePoint page can use the library to get data from the remote components of the add-in. To do this, you reverse the cross-___domain architecture: you create a proxy page in the remote web application. The library is called from a SharePoint page where it creates an iFrame to host the proxy page. For details on how to use the library in this way, see [Create a custom proxy page for the cross-___domain library in SharePoint](create-a-custom-proxy-page-for-the-cross-___domain-library-in-sharepoint.md). |
76 |
| - |
77 | 58 |
|
78 |
| - |
79 |
| - |
80 |
| -## In this section |
81 |
| -<a name="ReverseDirection"> </a> |
| 59 | +The SharePoint cross-___domain library can also be used in the reverse direction; that is, JavaScript on a SharePoint page can use the library to get data from the remote components of the add-in. To do this, you reverse the cross-___domain architecture: you create a proxy page in the remote web application. The library is called from a SharePoint page where it creates an iFrame to host the proxy page. |
82 | 60 |
|
83 |
| - |
84 |
| -- [Access SharePoint data from add-ins using the cross-___domain library](access-sharepoint-data-from-add-ins-using-the-cross-___domain-library.md) |
85 |
| - |
86 |
| - |
87 |
| -- [Work with the cross-___domain library across different Internet Explorer security zones in SharePoint Add-ins](work-with-the-cross-___domain-library-across-different-internet-explorer-security-z.md) |
88 |
| - |
| 61 | +For details about how to use the library in this way, see [Create a custom proxy page for the cross-___domain library in SharePoint](create-a-custom-proxy-page-for-the-cross-___domain-library-in-sharepoint.md). |
89 | 62 |
|
90 | 63 |
|
91 | 64 | ## See also
|
92 |
| -<a name="ReverseDirection"> </a> |
93 |
| - |
94 | 65 |
|
95 |
| -- [Solving cross-___domain problems in SharePoint Add-ins](http://blogs.msdn.com/b/officeapps/archive/2012/11/29/solving-cross-___domain-problems-in-apps-for-sharepoint.aspx) |
| 66 | +- [Access SharePoint data from add-ins using the cross-___domain library](access-sharepoint-data-from-add-ins-using-the-cross-___domain-library.md) |
| 67 | +- [Work with the cross-___domain library across different Internet Explorer security zones in SharePoint Add-ins](work-with-the-cross-___domain-library-across-different-internet-explorer-security-z.md) |
| 68 | +- [Solving cross-___domain problems in SharePoint Add-ins (blog post)](https://blogs.msdn.microsoft.com/officeapps/2012/11/29/solving-cross-___domain-problems-in-apps-for-sharepoint/) |
| 69 | +- [Authorization and authentication of SharePoint Add-ins](authorization-and-authentication-of-sharepoint-add-ins.md) |
96 | 70 |
|
97 | 71 |
|
98 | 72 |
|
0 commit comments