Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
SharePoint Add-ins
Developer environment
Windows
What browser(s) / client(s) have you tested
Additional environment details
SP Addin built with .Net 4.8 and VS 2022
Describe the bug / error
Remote Event Receivers allows to intercept item updating or item adding event, and item updated or item added event.
However, these event has empty context token when action is issued from another site collection, especially using the standard OOB "Copy to action" from a document library. These leads to issues when some operation has to be made on the target site collection.
I have two site collections (let call them src and dest)
In the dest site collection I have a remote event receiver that triggers whenever a document is updated in the default document library (ItemAdded, ItemAdding, ItemUpdated and ItemUpdating event are tracked).
This works perfectly when I work whithin the site collection dest (drag and drop file from windows explorer or using the "copy to" action within the same site collection.
However, if I copy a file from src to dest using the OOB copy to action, the RER fails, having in the payload this error:
Failed to get the context token for the remote event receiver url.
After some tests, I land to the conclusion this is due to the browser session creating an auth token for the site src to call the copy file api.
Then the RER triggers using the context token for site src not site dest and fails because of that.
How to overcome this issue ?
Some details:
-
the RER is registered using an application. It handles AppInstalled event to register the receivers onto the host site's document library under the RER app context.
-
the error is taken from the incoming payload, in the SPRemoteEventProperties.ErrorMessage node
-
The RER is built using the addin model (.app package), uploaded in the site collection's app catalog, then activated (from add an app menu)
-
the manifest declare this permissions request :
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection"
Right="FullControl" />
</AppPermissionRequests>
As I said, it's working perfectly when working within the dest site.
sample SOAP payloads:
Payload of the ItemAdded event, if file copy within the same site collection :
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ProcessOneWayEvent xmlns="http://schemas.microsoft.com/sharepoint/remoteapp/">
<properties xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AppEventProperties i:nil="true"/>
<ContextToken>eyJ0eXAiOiJKV1QiLC .........</ContextToken>
<CorrelationId>8d8d6ba0-f0d7-5000-72d5-187dc612d273</CorrelationId>
<CultureLCID>1033</CultureLCID>
<EntityInstanceEventProperties i:nil="true" />
<ErrorCode />
<ErrorMessage />
<EventType>ItemAdded</EventType>
<ItemEventProperties>
<AfterProperties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>somefield</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">14</a:Value>
</a:KeyValueOfstringanyType>
... othter fields omitted for brievety ...
</AfterProperties>
<AfterUrl>Documents partages/myfile.pdf</AfterUrl>
<BeforeProperties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<BeforeUrl i:nil="true"/>
<CurrentUserId>14</CurrentUserId>
<ExternalNotificationMessage i:nil="true"/>
<IsBackgroundSave>false</IsBackgroundSave>
<ListId>96e3b5dc-7e94-4db9-b2cd-f0bbda1a59ab</ListId>
<ListItemId>64</ListItemId>
<ListTitle>Documents</ListTitle>
<UserDisplayName>Steve BEAUGÉ</UserDisplayName>
<UserLoginName>i:0#.f|membership|steve@mytenant.onmicrosoft.com</UserLoginName>
<Versionless>false</Versionless>
<WebUrl>https://mytenant.sharepoint.com/sites/mycoll</WebUrl>
</ItemEventProperties>
<ListEventProperties i:nil="true"/>
<SecurityEventProperties i:nil="true"/>
<UICultureLCID>1033</UICultureLCID>
<WebEventProperties i:nil="true"/>
</properties>
</ProcessOneWayEvent>
</s:Body>
</s:Envelope>
Payload when copied from different site collections :
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ProcessOneWayEvent xmlns="http://schemas.microsoft.com/sharepoint/remoteapp/">
<properties xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AppEventProperties i:nil="true"/>
<ContextToken/>
<CorrelationId>cbf86ba0-0089-5000-5f44-207718e56ee9</CorrelationId>
<CultureLCID>1033</CultureLCID>
<EntityInstanceEventProperties i:nil="true"/>
<ErrorCode>GetContextTokenError</ErrorCode>
<ErrorMessage>Failed to get the context token for the remote event receiver url https://url/of/my/function.</ErrorMessage>
<EventType>ItemAdded</EventType>
<ItemEventProperties>
<AfterProperties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>somefield</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">14</a:Value>
</a:KeyValueOfstringanyType>
... othter fields omitted for brievety ...
</AfterProperties>
<AfterUrl>Documents partages/myfile.pdf</AfterUrl>
<BeforeProperties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<BeforeUrl i:nil="true"/>
<CurrentUserId>1073741823</CurrentUserId>
<ExternalNotificationMessage i:nil="true"/>
<IsBackgroundSave>false</IsBackgroundSave>
<ListId>96e3b5dc-7e94-4db9-b2cd-f0bbda1a59ab</ListId>
<ListItemId>64</ListItemId>
<ListTitle>Documents</ListTitle>
<UserDisplayName>Compte système</UserDisplayName>
<UserLoginName>SHAREPOINT\system</UserLoginName>
<Versionless>false</Versionless>
<WebUrl>https://mytenant.sharepoint.com/sites/mycoll</WebUrl>
</ItemEventProperties>
<ListEventProperties i:nil="true"/>
<SecurityEventProperties i:nil="true"/>
<UICultureLCID>1033</UICultureLCID>
<WebEventProperties i:nil="true"/>
</properties>
</ProcessOneWayEvent>
</s:Body>
</s:Envelope>
Differences :
- when same site, my actual user account is set in the
UserDisplayName and UserLoginName. When different sites, its system account
- When same site,
ContextToken is provider, no error message. When different sites, ContextToken is empty, but ErrorMessage contains the error
Steps to reproduce
- Implement a RER project that subscrive to some event on host web
- Copy file within the same site collection using Copy file action in the command bar ==> working
- Copy file from another site collection into the library where the RER is set up ==> not working.
A full repro sample is available here : https://github.com/stevebeauge/Repro.MissingContext.
Press F5 from the solution to deploy and add the application to a site, a sample MyList library will be created with RER plugged.
Expected behavior
Remote Event Receivers SOAP payloads should contains a valid context token when triggerd by a user.
Whether the action is executed from the site collection or not.
Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
SharePoint Add-ins
Developer environment
Windows
What browser(s) / client(s) have you tested
Additional environment details
SP Addin built with .Net 4.8 and VS 2022
Describe the bug / error
Remote Event Receivers allows to intercept item updating or item adding event, and item updated or item added event.
However, these event has empty context token when action is issued from another site collection, especially using the standard OOB "Copy to action" from a document library. These leads to issues when some operation has to be made on the target site collection.
I have two site collections (let call them
srcanddest)In the
destsite collection I have a remote event receiver that triggers whenever a document is updated in the default document library (ItemAdded, ItemAdding, ItemUpdated and ItemUpdating event are tracked).This works perfectly when I work whithin the site collection
dest(drag and drop file from windows explorer or using the "copy to" action within the same site collection.However, if I copy a file from
srctodestusing the OOB copy to action, the RER fails, having in the payload this error:After some tests, I land to the conclusion this is due to the browser session creating an auth token for the site
srcto call the copy file api.Then the RER triggers using the context token for site
srcnot sitedestand fails because of that.How to overcome this issue ?
Some details:
the RER is registered using an application. It handles
AppInstalledevent to register the receivers onto the host site's document library under the RER app context.the error is taken from the incoming payload, in the
SPRemoteEventProperties.ErrorMessagenodeThe RER is built using the addin model (
.apppackage), uploaded in the site collection's app catalog, then activated (from add an app menu)the manifest declare this permissions request :
As I said, it's working perfectly when working within the
destsite.sample SOAP payloads:
Payload of the ItemAdded event, if file copy within the same site collection :
Payload when copied from different site collections :
Differences :
UserDisplayNameandUserLoginName. When different sites, its system accountContextTokenis provider, no error message. When different sites,ContextTokenis empty, butErrorMessagecontains the errorSteps to reproduce
A full repro sample is available here : https://github.com/stevebeauge/Repro.MissingContext.
Press F5 from the solution to deploy and add the application to a site, a sample MyList library will be created with RER plugged.
Expected behavior
Remote Event Receivers SOAP payloads should contains a valid context token when triggerd by a user.
Whether the action is executed from the site collection or not.