Hi,
I have created a provider hosted app and a web job. I wanted to create Taxonomy group, term set and terms using web job. The web job gets app only context and it doesn't contain user context. It gets app context using below snippet.
accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
The app also requests for writing in taxonomy with below app manifest file.
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/taxonomy" Right="Write" />
</AppPermissionRequests>
I have below code in my web job that tries to create a Group in Term Store.
using (context = this.CreateClientContext(SiteUrl)) { TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(context); context.Load(taxonomySession); context.ExecuteQuery(); if (taxonomySession != null) { TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore(); context.Load(termStore); context.ExecuteQuery(); if (termStore != null) { TermGroup termGroup = termStore.CreateGroup(this.GroupName, Guid.NewGuid()); //termStore.CommitAll(); context.ExecuteQuery(); } }
The app is added in Office 365 site. When I execute above code, it throws be access denied error as below.
Access denied. You do not have permission to perform this action or access this resource.
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()