Authentication issue on ApplyProvisioningTemplate with PnP.Framework and Site.Selected permissions
Open
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:
- I registered an AAD app with Site.Selected permissions and role = fullcontrol
- I grant access to this app on a SharePoint site
- 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"))
{...
- 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);
- Then I get an exception with an 'Access is denied.'
- 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>
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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