I am developing a Sharepoint provider hosted app. the Sharepoint app web is only used as a repository for storing documents in document libraries and The web application use O365 multitenant app to authenticate users by using ADAL Tokens.So all the CSOM calls are executed using app only access token because acquiring the share point user access token is not always possible since user can directly access our web application with out redirecting via sharepoint
I need to provide functionality to the user to search the documents in the document library which is in the app web via Sharepoint search. I'm using CSOM to execute search queries.
The access privileges of the sharepoint app only token is not sufficient to access sharepoint serach.
What i have tired
Since getting the user access token is not an option i tried asking more permission in the app manifest.
Querying SharePoint search is possible if the app is granted "Scope:Tenant, Permission : Read".
A Sample Code that i used to test the search functionality
Uri targetWeb = new Uri("AppWebUrl"); var responseToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, targetWeb.Authority, targetRealm); var ctx = TokenHelper.GetClientContextWithAccessToken("AppWebUrl", responseToken.AccessToken); KeywordQuery keywordQuery = new KeywordQuery(ctx); keywordQuery.QueryText = keywordQueryValue; keywordQuery.RowLimit = 500; keywordQuery.StartRow = 0; keywordQuery.SelectProperties.Add("Title"); keywordQuery.SelectProperties.Add("UniqueId"); SearchExecutor searchExec = new SearchExecutor(ctx); ClientResult<ResultTableCollection> results = searchExec.ExecuteQuery("keywordQuery"); ctx.ExecuteQuery();
Is it feasible to ask this level of permission from a customer when they are installing the app?
Is there any way to access share point search in my scenario other than asking Tenant Read permission?
If any one can shed some light on this it will be highly appreciated