I have a Sharepoint provider hosted app and it get the term store in Office 365, It worked well for all users until a few days ago. Now fot the site collection administrators work fine but the others users dont, It throw the following exception:

Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access denied. You don't have permission to perform this action or access this resource.

This is the code:

    public ActionResult Index()
        var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
        using (var cc = spContext.CreateUserClientContextForSPHost())
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(cc);
            TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
                termStoreArg => termStoreArg.WorkingLanguage,
                termStoreArg => termStoreArg.Id,
                termStoreArg => termStoreArg.Groups.Include(
                    groupArg => groupArg.Id,
                    groupArg => groupArg.Name


<?xml version="1.0" encoding="utf-8" ?>
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest"

    <RemoteWebApplication ClientId="*" />
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
    <AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="FullControl" />
    <AppPermissionRequest Scope="http://sharepoint/taxonomy" Right="Write" />

1 Answer 1


The code works fine. Can you confirm if the "AllowAppOnlyPolicy" is set to true in your AppManifest.xml? (AppPermissionRequests AllowAppOnlyPolicy="true").

When using "CreateAppOnlyClientContextForSPHost", AllowAppOnlyPolicy is the only thing that matters and if set to false, will cause the ServerUnauthorizedAccessException.

If it is already set to "true", there is a chance that either VS or SharePoint might be referring to a stale version of AppManifest.xml.

  • I update the code in the question, the AppManifest does not have AllowAppOnlyPolicy="true") Oct 27, 2015 at 13:35
  • I set AllowAppOnlyPolicy="true" in the AppManifest and change de spContext and It works perfectly, thank you. Oct 27, 2015 at 16:16

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.