@Petchiammal Rajumayandi To add to what Ben has shared, to authenticate the Azure App Services with the Microsoft Entra ID in UWP app, you can use the Microsoft Authentication Library (MSAL) for authentication purposes. MSAL is a library that enables you to acquire tokens from Azure Active Directory (Azure AD) for your UWP app.
Here is a sample code that demonstrates how to authenticate a user and obtain an access token using MSAL:
using Microsoft.Identity.Client;
public async Task<string> GetAccessTokenAsync()
{
string clientId = "your-client-id";
string tenantId = "your-tenant-id";
string clientSecret = "your-client-secret";
string authority = $"https://login.microsoftonline.com/{tenantId}";
var app = ConfidentialClientApplicationBuilder.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
string[] scopes = new string[] { "https://your-api-url/.default" };
AuthenticationResult result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
return result.AccessToken;
}
In this code, you need to replace the placeholders with your own values:
-
your-client-id
: The client ID of your Azure AD app registration. -
your-tenant-id
: The tenant ID of your Azure AD directory. -
your-client-secret
: The client secret of your Azure AD app registration. -
https://your-api-url/.default
: The scope of the API that you want to access.
This code uses the ConfidentialClientApplicationBuilder
class to create a confidential client that can authenticate with Azure AD using a client secret. It then uses the AcquireTokenForClient
method to obtain an access token for the API.
Once you have obtained the access token, you can use it to authenticate the Azure App Services in your UWP app. You can pass the access token in the Authorization
header of your HTTP requests to the API.