Hi @Tobias Ask
I can't reproduce your issue locally, but as I said in a comment, there are many reasons for a 401 error, not necessarily due to token expiration. The best practice is to capture the full error message to find your issue.
I have used the graph C# SDK to call the /licensedetails
endpoint many times and it works fine, please refer to my sample code:
using Azure.Identity;
using Microsoft.Graph;
using Newtonsoft.Json;
try
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "tenant id";
// Values from app registration
var clientId = "client id";
var clientSecret = "client secret";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var licenseDetails = await graphClient.Users["user id"].LicenseDetails.Request().GetAsync();
Console.WriteLine("licenseDetails:" + JsonConvert.SerializeObject(licenseDetails));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.