Hi @Andy Casey ,
I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.
By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:
[How can I create a Microsoft Graph Client using an AccessToken in C#?]
Issue Symptom:
In my C# code I am trying to write a helper class, which does all of the GraphClient stuff we need to get done. I am using the ClientCredentials flow, but I keep getting an error "Either scp or roles claim need to be present in the token."
Solution:
public GraphServiceClient InitializeGraphClientAsync()
{
var MyConfig = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
// Values from app registration
var clientId = MyConfig.GetValue<string>("AzureAd:ClientId");
var clientSecret = MyConfig.GetValue<string>("AzureAd:ClientSecret");
//var scopes = new[] { "https://graph.microsoft.com/.default" };
var scopes = new[] { ".default" };
//// Multi-tenant apps can use "common",
//// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = MyConfig.GetValue<string>("AzureAd:TenantId");
//// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential,scopes);
return graphClient;
}
You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread.
Thanks for your understanding!