using Microsoft.Identity.Client;
using Microsoft.Rest.Azure.Authentication;
public static async Task<string> GetAccessTokenAsync(string clientId, string clientSecret, string tenantId)
{
var authority = $"https://login.microsoftonline.com/{tenantId}";
var clientApp = ConfidentialClientApplicationBuilder.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
string[] scopes = new string[] { "https://management.azure.com/.default" };
var result = await clientApp.AcquireTokenForClient(scopes).ExecuteAsync();
return result.AccessToken;
}