<p>is it possible to retrieve token to azure aks server (same which is in .kube/config), using Azure Credentials, programatically c#/.net 6.</p>
<p>I know that in powershell to retrieve it i can run &quot;az aks get-credentials&quot; (yaml).</p>

Kotletmeknow
<blockquote>
<p>Yes, it is possible to retrieve a token from an Azure server using Azure credentials programmatically in C#.</p>
</blockquote>
<p>Below is the code snippet, which I have followed and it worked for me.</p>
<pre><code>IConfidentialClientApplication client = ConfidentialClientApplicationBuilder
              .Create(&quot;&lt;Client-Id&gt;&quot;)
              .WithClientSecret(&quot;&lt;Client-Secret&gt;&quot;)
              .WithAuthority(&quot;https://login.microsoftonline.com/Tenant-ID&quot;)
              .Build();

            List&lt;string&gt; scopes = new List&lt;string&gt;
            {
                &quot;https://graph.microsoft.com/.default&quot;
            };

            AuthenticationResult result = await client
                .AcquireTokenForClient(scopes)
                .ExecuteAsync();

            GraphServiceClient graphClient = new GraphServiceClient(
                new DelegateAuthenticationProvider(
                    async (requestMessage) =&gt;
                    {
                        requestMessage.Headers.Authorization =
                            new System.Net.Http.Headers.AuthenticationHeaderValue(&quot;Bearer&quot;, result.AccessToken);
                    }));       

            var res = await client.AcquireTokenForClient(scopes).ExecuteAsync();
            string token = result.AccessToken;

</code></pre>
<p>Retrieving the token</p>
<p><img src="https://i.stack.imgur.com/S5UbT.png" alt="enter image description here" /></p>
