How to get an Azure AD access token programmatically from a MAUI application, to access a secured Web API in .NET6?

Gerardo Melendrez 21 Reputation points
2022-07-02T00:12:00.183+00:00

I have a secured Web API written in .NET 6 using minimal API which is hosted in a Linux App Service plan in Azure.

I setup an Azure AD app registration, and I can successfully get an access token using Postman, and authenticating with my Azure credentials.

To get that token, in Postman, I use:

Authorization URL: https://login.microsoftonline.com/my-tentant-id/oauth2/v2.0/authorize
Access Token URL: https://login.microsoftonline.com/my-tentant-id/oauth2/v2.0/token
Client ID: my-client-id
Client Secret: my-client secret
Scope: api://my-client-id/access_as_user

Then, I use that token to call the secured Web API and works well.

If I use that same token, when I call the Web API from my MAUI application, it does work as well.

My problem, is I haven't been able to find the correct documentation, to get the access token programmatically, from the MAUI app.

Several examples seem to work, but in .NET Core applications, Web Applications, etc. but nothing I have tried, has worked from the MAUI app.

Any help will be appreciated.

Thanks.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,900 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,909 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,652 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,562 questions
{count} votes