Thursday, 27 June 2024

Get Microsoft Entra ID (formerly Azure Active Directory) Client Token From Postman

Let's learn step by step How to get the AD Client Token.

Step 1: Go to Azure Portal

Step 2: Search Microsoft Entra ID and click it.

Step 3: Go to App Registrations











Step 4: Click on the application and copy TenantId, Client Id and Client Secret







Step  5: Below are the parameters we required for the postman request

Parameter        Description
Tenant Id               The (tenant) ID for the related application is registered in Microsoft Entra ID.
client_id                 The (client) ID for the related application registered in Microsoft Entra ID.
client_secret           Client secret value for the related application registered in Microsoft Entra ID.
grant_type              client_credentials
scope                      https://graph.microsoft.com/.default 


Step 6: Add a new Post request in the Postman with the below URL and above parameters, you will get token as shown in the snapshot below.

https://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/token


























Here you can see the token.

C# Create Dynamic JSON With Dynamic Keys

 In this article, we will create a dynamic JSON.

When you have a requirement where you are not sure how many nodes/keys you need to create in the JSON then follow the below approach.


Step 1: Declare a dictionary

            var fileData = new Dictionary<string, object>();


Step 2: Add dynamic data, in my example, I have an array of nodes and values. So, I am adding values to each.

 foreach (DocumentKeyValuePair kvp in result.KeyValuePairs)

 {

             fileData[kvp.Key.Content] = kvp.Value.Content;     

 }


Step 3: Searlize Object using Newtonsoft.Json;


 string json = JsonConvert.SerializeObject(fileData, Formatting.Indented);

 System.IO.File.WriteAllText(@"D:\file.json", json);



I am also saving the JSON in D drive, you can specify your path.

Your file will be saved in the specific directory and you can see I have dynamic keys and values.




Azure - The attempt to publish website and failed with HTTP status code 'Unauthorized'

OR

The attempt to publish the ZIP file through failed with HTTP status code Unauthorized.


When you get this error while publishing the Website, App Services, or Azure Function in Azure Portal. You need to update the settings in Azure Portal.



By default, the publish website is restricted for App Services and Azure Function from Visual Studio, we need to enable the settings.


SCM Basic Auth Publishing Credentials


Go to Azure Portal --> Go to App Services/Azure Functions --> Click Configuration --> Enable SCM Basic Auth Publishing Credentials.























Once you enable the settings, you can publish the website from Visual Studio.






Implement Authorization in Swagger with Static Value in Header .Net 8

If you want an anonymous user should not run the APIs. To run your API Endpoints From Swagger / Postman / Code the user should pass the head...