Hi @Landry, Alexandre ,
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:
[Query sharepoint online api with azureAD user]
Issue Symptom:
access/consume sharepoint online by calling the rest api, using c#
Current status:
Using following code to achieve requirement:
https://github.com/Azure-Samples/ms-identity-dotnet-desktop-tutorial/tree/master/2-TokenCache
https://www.c-sharpcorner.com/article/calling-graph-api-via-console-application-using-net-5/
var redirectUri = "http://localhost";
var authority = $"https://login.microsoftonline.com/{tenantId}/v2.0";
List<string> scopes = new List<string>();
scopes.Add("https://graph.microsoft.com/.default");
var cca = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.Build();
return new MsalAuthenticationProvider(cca, scopes.ToArray());
var client = new GraphServiceClient(authenticationProvider);
var graphRequest = client.Users.Request();
var results = graphRequest.GetAsync().Result;
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!