pnp / pnp/pnpframework

Authentication issue on ApplyProvisioningTemplate with PnP.Framework and Site.Selected permissions

Open
#736 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
259
Forks
161
Avg merge
10h 33m
Merged PRs (30d)
1

Description

Hi,

I may found have a strange issue related to Site.Selected permissions and applying a site template via PnP.Framework.

My setup:

  1. I registered an AAD app with Site.Selected permissions and role = fullcontrol
  2. I grant access to this app on a SharePoint site
  3. Then I connect in C# to this SP site:
var cert = new X509Certificate2(Convert.FromBase64String(_configuration["AppPermissions"]), string.Empty, X509KeyStorageFlags.MachineKeySet);
var authManager = new AuthenticationManager(
   "MYCLIENTID",
   cert,
    "MYTENANT");

using (var context = authManager.GetContext("MYSITE"))
{...

  1. Then I load my template and apply it
var dir = AppDomain.CurrentDomain.BaseDirectory;
XMLTemplateProvider sitesProvider = new XMLFileSystemTemplateProvider(dir, "");
ProvisioningTemplate provisoingTemplate = sitesProvider.GetTemplate("TemplateMid.xml");
web.ApplyProvisioningTemplate(provisoingTemplate);
  1. Then I get an exception with an 'Access is denied.'
  2. After some research I found out that the template works fine when I remove the language settings.
<pnp:SupportedUILanguages>
   <pnp:SupportedUILanguage LCID="1031"/>
   <pnp:SupportedUILanguage LCID="1033"/>
 </pnp:SupportedUILanguages>
  1. The strange thing is that it works when I apply the template (with the language settings) via PowerShell
Connect-PnPOnline -ClientId MYCLIENTID -Url "MYSITE" -Tenant MYTENANT -CertificatePath .\MYCERT.pfx
Invoke-PnPSiteTemplate -Path .\TemplateMid.xml

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the C# ApplyProvisioningTemplate call and the XMLTemplateProvider loading TemplateMid.xml, focusing on the SupportedUILanguages section and the Access is denied exception under Site.Selected permissions. Compare this path with the working Invoke-PnPSiteTemplate PowerShell flow; done means the C# template application succeeds with both language settings and the granted permissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
authorization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.