SharePoint Provider-Hosted Add-In and Web Api

This topic has been discussed several times – how do you go about using Web API from within a single page SharePoint Provider-Hosted add-in? Bas Lijten had a great approach, which I emulated with some additions.

Provider-Hosted add-ins rely on OAUTH under the hood, and the technicalities are normally abstracted by SharePointContext and TokenHelper classes. In short, the issue with these classes is that they assume access to both HttpContext.Current and session state, neither which Web API guarantees.

Bas wrote a custom set of classes that perform the same job as the stock classes, but for Web API. I went one step further and provided a set of classes that work for both MVC page rendering and Web API. My custom provider avoids the use of session state and instead uses cookies to pass values between standard MVC SharePoint add-in calls and Web API calls (AJAX).

You can see my code and read a more technical description over at GitHub.