Apr
17
2013

SharePoint Provider-Hosted App - 401 Unauthorized error on clientContext.ExecuteQuery()

So you are ready to develop a SharePoint app and have followed this MSDN article to get everything set up. F5 in visual studio, clicked Trust It to "Do you trust <name of your app>?" from SharePoint, and then you are getting 

The remote server returned an error: (401) Unauthorized

image

Chances are the IssuerId in provider-hosted application web.config is listed as a UPPER CASE Guid string. 

For example 

<add key="IssuerId" value="983802AC-C7A9-4B50-8100-2C6E2773B9CF" />

To resolve above issue, all you needed to do is to make it a lowercase Guid string

<add key="IssuerId" value="983802ac-c7a9-4b50-8100-2c6e2773b9cf" />

Also, make sure the IssuerID in web.config match the one you see from Get-SPTrustedSecurityTokenIssuer SharePoint Powershell command. (If you don't see anything listed from this command, go back to steps in MSDN article)

I hope this helps

James

blog comments powered by Disqus

James Tsai

Blog Disclaimer