title: The issuer of the token is not a trusted issuer Sharepoint Provider Hosted App
body: <p>I created an app by using the following tutorial:</p>
  
  <p><a href="http://www.luisevalencia.com/2014/07/23/prepare-environments-sharepoint-provider-hosted-apps/" rel="nofollow">http://www.luisevalencia.com/2014/07/23/prepare-environments-sharepoint-provider-hosted-apps/</a></p>
  
  <p>The app works perfectly if there are no sharepoint calls, I meant a response.write with hello world works.</p>
  
  <p>But, if I add some sharepoint stuff like printing out the name of the user, I got a The remote server returned an error: (401) Unauthorized.</p>
  
  <pre><code>Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
  
              using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, Request.LogonUserIdentity))
              {
                  clientContext.Load(clientContext.Web, web =&gt; web.Title);
                  clientContext.ExecuteQuery();
                  Response.Write(clientContext.Web.Title);
                  Response.Write("Hello World");
  
              }
  </code></pre>
  
  <p>I get the following error on the logs.</p>
  
  <pre><code>SPApplicationAuthenticationModule: Failed to authenticate request, unknown error. Exception details: System.IdentityModel.Tokens.SecurityTokenException: The issuer of the token is not a trusted issuer.    
   at Microsoft.SharePoint.IdentityModel.SPTrustedIssuerNameRegistry`1.GetIssuerName(SecurityToken securityToken, String requestedIssuerName)    
   at Microsoft.SharePoint.IdentityModel.SPJsonWebSecurityBaseTokenHandler.GetIssuerNameFromIssuerToken(JsonWebSecurityToken token)    
   at Microsoft.SharePoint.IdentityModel.SPJsonWebSecurityBaseTokenHandler.GetIssuerName(JsonWebSecurityToken token)    
   at Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ValidateTokenCore(SecurityToken token, Boolean isActorToken)    
   at Microsoft.IdentityModel.S2S.Tokens.JsonWebSecurityTokenHandler.ValidateTokenCore(SecurityToken token, Boolean isActorToken)    
   at Microsoft.SharePoint.IdentityModel.SPJsonWebSecurityBaseTokenHandler.ValidateToken(SecurityToken token)    
   at Microsoft.SharePoint.IdentityModel.SPJsonWebSecurityTokenHandler.ValidateToken(SecurityToken token)    
   at Microsoft.SharePoint.IdentityModel.SPApplicationAuthenticationModule.TryExtractAndValidateToken(HttpContext httpContext, SPIncomingTokenContext&amp; tokenContext)    
   at Microsoft.SharePoint.IdentityModel.SPApplicationAuthenticationModule.ConstructIClaimsPrincipalAndSetThreadIdentity(HttpApplication httpApplication, HttpContext httpContext, SPFederationAuthenticationModule fam)    
   at Microsoft.SharePoint.IdentityModel.SPApplicationAuthenticationModule.AuthenticateRequest(Object sender, EventArgs e)
  </code></pre>