How to Make Azure API Calls with Managed Identity in VSCode — A Complete Guide
In today’s cloud-first world, securing API calls is more important than ever. Azure provides a powerful solution with Managed Identity…
How to Make Azure API Calls with Managed Identity in VSCode — A Complete Guide
In today’s cloud-first world, securing API calls is more important than ever. Azure provides a powerful solution with Managed Identity, which lets you authenticate securely without needing any credentials stored in your code. If you’re a developer or IT professional working with Azure, you’ll be excited to know that you can use Managed Identity to make secure API calls directly from VSCode — and the best part is, it’s easy to set up.
In this guide, we’ll show you how to:
- Set up Managed Identity in Azure.
- Retrieve an access token with no credentials needed.
- Make GET API calls securely using VSCode.
- Manage Azure resources effectively using API calls.
Let’s dive in!
What is Managed Identity and Why Should You Care?
Azure Managed Identity is a service that helps you authenticate your applications without managing credentials. Whether you’re using a Virtual Machine (VM), an App Service, or other Azure services, you can assign a Managed Identity to access Azure resources securely and efficiently.
Why use Managed Identity?
- No need for managing credentials manually.
- Automatic token generation with Azure’s built-in security.
- Seamless authentication across services without additional setup.
If you want to make Azure API calls or access Azure resources securely, Managed Identity is the way to go.
Setting Up Managed Identity in Azure:
To make API calls to your Azure Subscription, first ensure that Managed Identity is enabled for your Azure service.
Here’s how you can set it up:
- Create or Use an Existing Managed Identity:
- Deploy a user assigned Managed Identity.
2. Assign Permissions:
- In the Azure Portal, go to Access Control (IAM) and assign the Owner role (HPA used here for demo purpose) to the Managed Identity for your Azure Subscription.
3. Obtain the Azure Subscription ID:
- Go to Azure Portal > Subscriptions and get the Subscription ID. This ID is required to make API calls targeting your subscription’s resources.
Making API Calls to Azure Subscription Using Managed Identity in VSCode
Once your Managed Identity is set up and permissions are assigned, you’re ready to make secure API calls to your Azure Subscription using VSCode.
- Install REST Client Extension in VSCode:
- Open VSCode.
- Go to Extensions, search for REST Client, and click Install.

2. Get the Access Token Using PowerShell: Open PowerShell to obtain the access token needed for authentication. Use the following PowerShell command to retrieve the token for Azure Subscription API calls:
$tokenUrl = "http://localhost:50342/oauth2/token"
$resource = "https://management.azure.com/"
$token = (Invoke-RestMethod -Uri $tokenUrl -Method Post -Headers @{Metadata="true"} -Body "resource=$resource").access_token
This command will retrieve the token you need to authenticate your API requests securely using Managed Identity.
3. Create a .http File in VSCode:
- In your VSCode workspace, create a new file with the
.httpextension. - Add the following GET request to retrieve resources from your Azure Subscription:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups?api-version=2021-04-01 HTTP/1.1
Authorization: Bearer {access_token}
Replace {subscriptionId} with your actual Subscription ID and {access_token} with the token you retrieved.
4. Send the Request:
- Hover over the GET request in VSCode and click Send Request.
- You will see the response below the request, showing resource groups from your Azure Subscription.

Handling Token Expiry and Refresh
Tokens are time-limited and need to be refreshed periodically. To handle token expiration automatically:
- Use Delegated Handlers to auto-renew tokens in your HttpClient requests if you’re using .NET or other programming languages.
- You can also use Microsoft Authentication Library (MSAL) or DefaultAzureCredential for token renewal in your scripts.
Call to Action:
Try it out yourself! Follow the steps outlined in this guide to start making Azure Subscription API calls using Managed Identity. If you face any issues or have any questions, feel free to drop them in the comments below — I’m here to help!
메타데이터
- post_id
- b48bfccfdd4b
- slug
- how-to-make-azure-api-calls-with-managed-identity-in-vscode-a-complete-guide-b48bfccfdd4b
- url
- https://medium.com/@subhashvasarapu/how-to-make-azure-api-calls-with-managed-identity-in-vscode-a-complete-guide-b48bfccfdd4b
- canonical_url
- https://medium.com/@subhashvasarapu/how-to-make-azure-api-calls-with-managed-identity-in-vscode-a-complete-guide-b48bfccfdd4b
- author_url
- https://medium.com/@subhashvasarapu
- status
- ok
- fetched_at
- 2026-08-24 02:58:13