In this article, We learn how to create get access token for azure management API. I will show how to do it, and just follow the steps clearly.
For more updates please do Subscribe via Email:
Azure?
Azure is a cloud computing platform and an online portal that allows you to access and manage cloud services and resources provided by Microsoft. These services and resources include storing your data and transforming it, depending on your requirements
Access Token
In computer systems, an access token contains the security credentials for a login session and identifies the user, the user’s groups, the user’s privileges, and, in some cases, a particular application. In some instances, one may be asked to enter an access token rather than the usual password.
or
Access tokens are used in token-based authentication to allow an application to access an API. The application receives an access token after a user successfully authenticates and authorizes access, then passes the access token as a credential when it calls the target API.
Implementation
public async Task<string> GetAccessTokenForAzureManagementAPI()
{
// Get configurations
var tenantId = "Azure Active Directory Tenant ID";
var azureManagementScope = "Azure Management API Endpoint Scope";
string activeDirectoryClientId = "Active Directory Client Id";
string activeDirectoryClientSecret = "Active Directory Client Secret";
string accessToken = string.Empty;
string accessTokenURL = $"https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token";
// Build request body
var requestBody = new Dictionary<string, string>();
requestBody.Add("grant_type", "client_credentials");
requestBody.Add("client_id", activeDirectoryClientId);
requestBody.Add("client_secret", activeDirectoryClientSecret);
requestBody.Add("scope", azureManagementScope);
// Requesting a bearer token
var httpContent = new FormUrlEncodedContent(requestBody);
using (HttpClient httpClient = new HttpClient())
{
var response = await httpClient.PostAsync(new Uri(accessTokenURL), httpContent);
var content = response?.Content?.ReadAsStringAsync().Result;
if (response?.StatusCode == HttpStatusCode.OK || response?.StatusCode == HttpStatusCode.Created)
{
JObject joResponse = JObject.Parse(content.ToString());
JValue ojObject = (JValue)joResponse["access_token"];
accessToken = ojObject.Value.ToString();
}
}
return accessToken;
}
Happy Learning..
Thank you for visiting my blog site. Hoping you learn more here. please feel free to comment and suggest if there is need to enhance and update. thank you.
Related Topics
What is Microsoft Power Automate
In this article, I will know what is power automate, And Microsoft Power Automate, formerly known as Microsoft Flow, is a cloud-based service that allows […]
What is Microsoft Power Apps
In this article, I will know what is power apps, And Microsoft Power Apps is a low-code development platform that allows users to easily create […]
What is Microsoft Power Platform
In this article, I will introduce the new technology powered by Microsoft product which is Microsoft Power Platform. Microsoft Power Platform is a line of […]
How to create a personal access token in Azure DevOps
In this article, We learn how to create a Personal Access Token in Azure DevOps. I will show how to do it, and just follow […]
How to save the composed mail into outlook draft using HTTP request in Power Automate
In this article, We learn how to saved the composed mail into outlook draft using HTTP request in Power Automate. I will show how to […]
How to save the composed mail into outlook draft using http request in logic apps
In this article, We learn how to saved the composed mail into outlook draft using HTTP request in Logic Apps. I will show how to […]
How to create logic apps in Azure
In this article, We learn how to create logic apps in Azure. I will show how to do it, and just follow the steps clearly. […]
How to get access token for Azure Management API
Get access token for Azure Management API […]
How to Ingest Data in Azure Kusto Database
In this article, We learn how to Create Table in Azure Kusto Database. I will show how to do it, and just follow the steps […]
How to Create Table in Azure Kusto Database
In this article, We learn how to Create Table in Azure Kusto Database. I will show how to do it, and just follow the steps […]
How to use Web UI in Azure Kusto Database
In this article, We learn how to use Web UI in Azure Kusto Database. I will show how to do it, and just follow the […]
How to get value from local.settings.json in Azure Function App
Get value from local.settings.json in Azure Function App […]
How to implement Azure Function App
Implementation of in Azure Function App […]
UTC to PST conversion with daylight saving time
In this article, We learn how to convert UTC to PST with daylight time saving using azure maps API. I will show you how and […]
Pulling IcM data using kusto query in C#
In this article, We learn about IcM and kusto. I will try to discuss further as much as I can, and just follow clearly. For […]
Join table in Kusto Query Language (KQL)
In this article, We learn how to join two or more tables in Kusto Query Language (KQL). I will show how to do it, and […]
Kusto Query Language (KQL)
In this article, We learn about Kusto Query Language (KQL), I will explain furthered and detailed as I can. Just follow and read clearly about […]
Create Function App Project
In this article, We learn how to create Function App (FA) project in Visual Studio. I will show how to do it, and just follow […]
Create Resource Group in Azure
Create Resource Group in Azure. […]
Azure Active Directory get access token using Postman
In this article, We learn how to get access token in AAD using Postman. I will show how to do it, and just follow the […]