pnp / pnp/pnpframework

SharePoint 2013 On-Prem Issue

Open
#441 4 comments 0 reactions 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

My goal is to create a Web API project using:

  1. Visual Studio 2019
  2. .Net 5.0
  3. PnP.Framework 1.6
  4. C#

in order create a GET method to read a list in SharePoint2013 On-Prem using app permissions & then return the results in the response. I am logged onto the same domain as the On-Prem server.

This is a hybrid, temporary solution to read On-Prem list data from a single list from Azure until the community is migrated to SPO. The list data is read once every minute & the data is mission critical, so replicating the list in SPO is not an option.

My Code

using PnP.Framework;
using Microsoft.SharePoint.Client;

...

ListItemCollection allItems = null;

// Connect to site collection
using (var ctx = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret))
{
// Get list
List list = ctx.Web.Lists.GetByTitle("MyListname");

CamlQuery caml = new CamlQuery();

allItems = list.GetItems(caml);

ctx.Load(allItems);
ctx.ExecuteQuery();

}
`

Things I have tried:

  1. Create app permissions for the site collection w/ the following XML:

<AppPermissionRequests AllowAppOnlyPolicy="true"><AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Read"/></AppPermissionRequests>

  1. Running the code locally in VS2019, the code runs successfully against SharePoint Online.

  2. Running the code locally in VS2019, against SharePoint 2013 On-Prem, I get the following error message using the these project templates:

a) Web API
b) Console app
c) Function app

The remote server returned an error: (400) Bad Request. - {"error":"invalid_request","error_description":"AADSTS90002: Tenant '{MyTenantId}' not found. This may happen if there are no active subscriptions for the tenant. Check to make sure you have the correct tenant ID. Check with your subscription administrator.\r\nTrace ID: 480ae8b4-20ca-47cb-b4a0-9736110a5e02\r\nCorrelation ID: 77ccf203-2fb6-46a0-9c20-597106fe1e8f\r\nTimestamp: 2021-08-10 13:54:35Z","error_codes":[90002],"timestamp":"2021-08-10 13:54:35Z","trace_id":"480ae8b4-20ca-47cb-b4a0-9736110a5e02","correlation_id":"77ccf203-2fb6-46a0-9c20-597106fe1e8f","error_uri":"https://accounts.accesscontrol.windows.net/error?code=90002"}

Even this simple snippet of code fails against On-Prem:

using (var ctx = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret)) { ctx.ExecuteQuery(); }

So I'm asking for direction what is the proper way to use VS2019, C#, PnP.Framework, & app permissions to connect to a SharePoint 2013 On-Prem site collection to read list items?

I've created a working solution using Logic Apps & On-Prem Data Gateway, but the enterprise infrastructure team does not want to support this solution. If a Function App is a better solution than Web API, then that is fine.

Please advise.

Thanks,
Rob

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 at AuthenticationManager.GetACSAppOnlyContext and the minimal ctx.ExecuteQuery() snippet, then trace the reported AADSTS90002 response for the SharePoint 2013 target. Done means establishing whether the shown app-only approach is supported and documenting a confirmed way to read the list, or clearly identifying the missing compatibility or configuration requirement.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, authentication, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.