3

In a SharePoint app I want to perform a search in the context of an app instead of the user. But, when I create a new app context

var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientContext = spContext.CreateAppOnlyClientContextForSPHost())

it throws an error when I want to execute the query

SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();

Is there a possibility to launch a search query in the context of an app user instead of the current user?

  • What error is being thrown? And have you tried revoking the QueryAsUserIgnoreApPrincipal permission? – wjervis Jul 7 '15 at 17:32
  • The QueryAsUserIgnoreApPrincipal will do the search in the context of the currently logged in user not in the context of the app user. – Davy Jul 8 '15 at 14:31
  • Which is why I said make sure it's not being granted... – wjervis Jul 8 '15 at 23:53
  • Yes, I already did. But I get the same error. "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs." I think it is not possible at this moment. I also don't find any examples on the internet that have the same scenario. – Davy Jul 10 '15 at 7:23
2

A prerequisite of the AppOnlyContext is the setting in AppManifest:

<AppPermissionRequests AllowAppOnlyPolicy="true">
...snip...
</AppPermissionRequests>

However, there is a special permission request designed for your scenario. So you may not need AppOnly.

<AppPermissionRequest Scope="http://sharepoint/search" Right="QueryAsUserIgnoreAppPrincipal" />
  • 1
    The QueryAsUserIgnoreApPrincipal will do the search in the context of the currently logged in user not in the context of the app user. – Davy Jul 8 '15 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.