I am creating an app for SharePoint online with provider hosted app model. I followed all the steps to create an app and ensured both web.config and appmanifest.xml has same Client id.

Though it contains the same Client id, while accessing the app I am getting this error:

token is empty

Please help me, which settings am I missing? The application code is for showing the current user, that's it.


protected void Page_Load(object sender, EventArgs e)
    String contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
    Response.Write("Token: " + contextToken);

Web App deployed to Azure web site.

2 Answers 2


When developing app aka add-in with Visual Studio 2012/2013, Client ID is being taken care of automatically.

However, at the time of deploying app, you must register it with both Client ID and Client Secret generated using appregnew.aspx. App domain is where your web application is being hosted could be Azure/on-prem server.

The appregnew.aspx should look like this:enter image description here

enter image description here

Once you get the Client ID and Client Secret, you simply register it in app publishing dialog in Visual Studio.

enter image description here

Upload the *.app package file of the app for SharePoint to the organization app catalog.

Publishing the web application part on Azure before testing app (you must enable https between app and remote web application)

Install the app on site collection and you're good to test the app.

P.S. At the time of publishing the app, Publish Profile (.pubxml) will automatically update the Client ID and Client Secret as a part of deployment in both App and web application project.

Happy SharePointing!


Check if https is used to refer remote application in Appmanifest.xml?

<?xml version="1.0" encoding="utf-8"?>
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest" Name="App" ProductID="{76c0e74b-e6f8-4a3c-883e-aee307ff6a33}" Version="" SharePointMinVersion="">
    <RemoteWebApplication ClientId="SomeGuid" />

Why aren't you using new abstract and concrete classes to develop provider hosted apps? Microsoft is taking care of all nitty gritty and encapsulating the details of ACS (a low-trust app) or S2S apps (a high-trust app). Check out the Kirk's blog for more details

  var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
                clientContext.Load(clientContext.Web, web => web.Title);
  • Once done installing app in catalog, you can install this app in any site collection, as long as the catalog and sites are in the same O365 tenant/SPFarm where you created the Id with appregnew. For publishing app for store, you must get client ID and client secret from there. Jun 14, 2015 at 20:30
  • Falak, Thanks for responding! I did all the steps mentioned above. From creating Client Id from appregnew.aspx to publishing. But no luck. The same code works fine, when running in debug mode local.
    – Vimal L
    Jun 15, 2015 at 2:47
  • It means you're not getting the context token from SharePoint. Something is wrong with app registration. Could you do one more registration using appregnew.aspx? Are you hosting web app part in Azure? Once you publish the app using Visual Studio, check the contents of it appmanifest.xml by renaming .app -> .zip to make sure Client ID matches that of web app. Jun 15, 2015 at 4:58
  • Yes, facing issue with Context token. I tried registering new app with client id and secret key. Followed all steps above and deployed. Still the same error.
    – Vimal L
    Jun 15, 2015 at 5:39
  • Could you paste you code above for getting the context token? Are you publishing in Azure? Jun 15, 2015 at 5:41

Finally, got the solution to it. Step 1. In appregnew.aspx page under app domain do not give www. in the url Util otherwise you have the url. You give without www. Step 2. Update the new Client id and secret key in azure site

Now run it, will work for sure!

  • You can provide redirect URI Redirect with https or www for each app registration but for azure websites you don't need to provide www =). Glad it worked out! Jun 16, 2015 at 13:06
  • Hi Falak, in the reference screen shots, www. can be avoided from Microsoft sites. This was working previously. But now, not.
    – Vimal L
    Jun 18, 2015 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.