You can also get the access token by executing normal HTTP request using HttpClient.
This answer is for someone who tries to use pure HTTP request to get the access token instead of using MS libraries like MSAL.net or ADAL.NET (like the above answer).
And in case you don't know how to send form url content using HttpClient.
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://login.microsoftonline.com/<your_tenant_id>/oauth2/v2.0/token"),
Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "client_id", "<your_client_id>" },
{ "scope", "https://analysis.windows.net/powerbi/api/.default" },
{ "client_secret", "<your_client_secret>" },
{ "grant_type", "client_credentials" },
}),
};
Reference: https://kalcancode.wordpress.com/2025/02/18/powerbiclient-how-to-get-access-token/