C
C#10mo ago
mitchelldirt

✅ C# Graph API Client

I'm trying to access all of the items in a sharepoint list. I'm just getting an access denied error right now. Using the same site id and list id I can use my account to grab the items, but using the app I can't I think I might need to use the AllowAppOnly flag, but I have no clue how to do that. Anyone go any ideas?
// The request
var result = await client.Sites["siteid"].Lists["listid"].Items.GetAsync();

// How I'm building the graph client
var clientSecretCredential = new ClientSecretCredential(tenantId,clientId,clientSecret);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
// The request
var result = await client.Sites["siteid"].Lists["listid"].Items.GetAsync();

// How I'm building the graph client
var clientSecretCredential = new ClientSecretCredential(tenantId,clientId,clientSecret);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
16 Replies
not guilty
not guilty10mo ago
have you tried with graph explorer
mitchelldirt
mitchelldirt10mo ago
Yes, but I could only do it with my account permissions (which worked). The problem is that the application permission isn't working 😦
not guilty
not guilty10mo ago
how are the app permissions configured
mitchelldirt
mitchelldirt10mo ago
Azure App with Sites.FullControl.All permission enabled Then in the code above I show how I implement the client I am able to query for all users, but not for the items in a list
not guilty
not guilty10mo ago
yeah but for example does it require admin consent? i believe it doesn't so it should be ok from that point of view was it created as delegate or app?
Accord
Accord10mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
mitchelldirt
mitchelldirt10mo ago
I added the permissions as an application permission and got it approved by an admin. When you say "was it created as delegate or app", does that mean that when creating the app you select what kind of app it will be between those two?
not guilty
not guilty10mo ago
no i mean delegate permission or app permission because even if you create an app registration the api permissions needed to do stuff could be those in add permission -> microsoft graph -> delegate permission just be sure to be using the correct ones
mitchelldirt
mitchelldirt10mo ago
,Ahhhh yes I'm definitely using app permissions right now. The reason being is that this is supposed to be an automated process and shouldn't require a user to sign in
Accord
Accord10mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
not guilty
not guilty10mo ago
do you have your access token?
mitchelldirt
mitchelldirt10mo ago
Since I’m using the client secret credential I didn’t find a property on there for access token. I’ll look into it in a bit, but I’m pretty sure it doesn’t provide me with one
not guilty
not guilty10mo ago
Choose a Microsoft Graph authentication provider - Microsoft Graph
Learn how to choose scenario-specific authentication providers for your application.
not guilty
not guilty10mo ago
Build .NET apps with Microsoft Graph and app-only authentication - ...
In this tutorial, you'll build a .NET app that uses the Microsoft Graph API to access data using app-only authentication.
not guilty
not guilty10mo ago
Get access without a user - Microsoft Graph
Learn how an app obtains an access token from the Microsoft identity platform and calls Microsoft Graph with its own identity.
mitchelldirt
mitchelldirt10mo ago
Ooooo thanks for all these resources - you were right about the permissions. After another closer look I had the right name for the permission, but I had the SharePoint API Sites.ReadWrite.All NOT the Graph API one As soon as I added in the Graph API Sites.ReadWrite.All permission it started working Thanks for time and help on this 🙂