Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Unable to access Search Service Application using CreateAppOnlyClientContextForSPHost

$
0
0

Hi All,

I'm developing a Provided-Hosted app for SharePoint 2013. I got items from a list using App Only Policy. Everything works fine.

My problem occurs when I try to use the Search Service Application to execute a query under the context of the app (Elevated privileges).

My code is the following:

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

                KeywordQuery keywordQuery = new KeywordQuery(ctx);
                SearchExecutor searchExecutor = new SearchExecutor(ctx);
                keywordQuery.QueryText = "path:http://intranet";
                var resultItems = searchExecutor.ExecuteQuery(keywordQuery);
                ctx.ExecuteQuery();

}

I get the following exception in ULS:

An exception occurred when trying to issue security token

STS Call: Failed to issue new security token. Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object.   
 at Microsoft.SharePoint.IdentityModel.SPSecurityTokenService.SPRequestInfo.InitializeForFederationAuthType(SPRequestSecurityToken request)    
 at Microsoft.SharePoint.IdentityModel.SPSecurityTokenService.GetTokenLifetime(Lifetime requestLifetime)    
 at Microsoft.IdentityModel.SecurityTokenService.SecurityTokenService.Issue(IClaimsPrincipal principal, RequestSecurityToken request)    
 at Microsoft.SharePoint.IdentityModel.SPSecurityTokenService.Issue(IClaimsPrincipal principal, RequestSecurityToken request)

----------------------------------------------

If I change my code to use the security context of the user, CreateUserClientContextForSPHostit works. However, I need the app security context to execute this search.

Any clues why I get the error?


Saludos,

Alejandro Perez
Caracas, Venezuela
MCSD MCDBA MCT


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>