Calling Azure REST API from .Net Core native application by displaying the Azure Login Popup from C#

David Downing 701 Reputation points

Is it possible to initiate the Azure Login Popup from a native windows application?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,225 questions
{count} votes

Accepted answer
  1. David Downing 701 Reputation points

    I was able to get the Azure REST APIs working using the following code from the Fluent NuGet Packages:

        private static string TestAuth()  
            // AzureCredentials credentials = new AzureCredentials(spLogin, TenantID, AzureEnvironment.AzureGlobalCloud);  
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(  
            var client = RestClient  
            CancellationToken cancellationToken = new CancellationToken();  
            var request = new HttpRequestMessage(HttpMethod.Get, $"{SubscriptionID}/resourcegroups/{ResourceGroupName}?api-version=2019-10-01");  
            client.Credentials.ProcessHttpRequestAsync(request, cancellationToken).GetAwaiter().GetResult();  
            var httpClient = new HttpClient();  
            var response = httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).GetAwaiter().GetResult();  
            return response.Content.ReadAsStringAsync().GetAwaiter().GetResult();  
    3 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Mehmet Seckin 6 Reputation points

    If I'm understanding this correctly, you want to make calls to the Azure Resource Management APIs from a native application. It is certainly possible to authenticate against Azure from a native windows application through Azure Active Directory.

    You can create an Azure AD application with user_impersonation permissions, and use that application to authenticate against your tenant using MSAL.NET libraries.

    There is a quickstart application that uses a similar approach to access Microsoft Graph APIs.

    Hope this helps.

    1 person found this answer helpful.