0% found this document useful (0 votes)
8 views2 pages

Azure REST API Authentication & Usage Guide

The document provides detailed instructions on using the Azure Cloud REST API, including authentication, finding data source servers, and retrieving data sources. It outlines the necessary curl commands for various API endpoints and explains how to set up an application in Azure AD to obtain client credentials. Additionally, it describes the process for adding custom roles in the Azure Portal to enable access to data source servers and databases.

Uploaded by

sthakur.official
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Azure REST API Authentication & Usage Guide

The document provides detailed instructions on using the Azure Cloud REST API, including authentication, finding data source servers, and retrieving data sources. It outlines the necessary curl commands for various API endpoints and explains how to set up an application in Azure AD to obtain client credentials. Additionally, it describes the process for adding custom roles in the Azure Portal to enable access to data source servers and databases.

Uploaded by

sthakur.official
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Azure Cloud REST API Details

1. Authentication API to get access token. (authenticate())

curl --location --request GET


'[Link]
\
--header 'Content-Type: application/x-www-form-urlencoded' \
--form 'client_id="<CLIENT_ID>"' \
--form 'client_secret="<CLIENT-SECRET>"' \
--form 'scope="[Link] "' \
--form 'grant_type="client_credentials"'

2. Find data source servers by Subscription Id.


(findDataSourceServers())

curl --location --request GET


'[Link]
resources? api-version=2022-12-01&$filter= resourceGroup eq
<RESOURCE_GROUP> and (resourceType eq
'[Link]/servers' or resourceType eq
'[Link]/flexibleServers' or resourceType eq
'[Link]/servers or resourceType eq
'[Link]/servers' or resourceType eq
'[Link]/flexibleServers' or resourceType eq
'[Link]/servers' or resourceType eq
'[Link]/databaseAccounts' or resourceType eq
'[Link]/storageAccounts')' ' \
--header 'Authorization: Bearer <ACCESS_TOKEN>'

3. Find data sources API. (findDataSources())

1) To get list of databases

curl --location
'[Link]
resourceGroups/<RESOURCE_GROUP>/providers/<PROVIDER>/
<DATABASE_SERVER_NAME>/databases?api-version=2023-06-30' \
--header Bearer <ACCESS_TOKEN>'

2) To get list of containers or bucket

curl --location
'[Link]
resourceGroups/<RESOURCE_GROUP>/providers/
[Link]/storageAccounts/<STORAGE_ACCOUNT_NAME>/
blobServices/default/containers?api-version=2023-01-01' \
--header Bearer <ACCESS_TOKEN>'
Setup in Azure Portal for getting Client-Id and Client-Secret

1. Follow the below document and create an app (e.g., TestApp) in Azure AD.
[Link]

2. Get the Application (client) ID, Directory (tenant) ID, and Secret Value for this App.

3. Login to the [Link] and get the value of Subscription ID and Resource Group.

Add Custom Role to list Data Source Servers from REST API

1. In the Azure Portal go to Subscription > Pay-As-You-Go > Access


control (IAM).

2. Click on +Add > Add custom role.

3. Select the check box “Read : Get Subscription Resources” under


“[Link]/subscriptions/resources”. Click on Add.
Click on Next.

Add Custom Role to list Data Sources from REST API

1. In the Azure Portal go to Subscription > Pay-As-You-Go > Access


control (IAM).

2. Click on +Add > Add custom role.

3. Select the checkbox “Read : List/Get MySQL Server Database(s)” for


“[Link]/flexibleServers/databases”

Common questions

Powered by AI

In Azure, custom roles facilitate specific access permissions for APIs. To create a role that allows listing data sources, navigate to Subscription > Pay-As-You-Go > Access control (IAM) in the Azure Portal, click '+Add' > 'Add custom role', and select permissions like 'Read: Get Subscription Resources'. Follow prompts for role customization and assign it accordingly .

The 'api-version' parameter in Azure Cloud REST API requests specifies which version of the API to use for the interaction, ensuring compatibility and access to specific features and updates. It influences the interaction by aligning the client's API requests with Azure's supported functionalities and service updates, which can prevent deprecated operations and maintain consistent API behaviors across different development cycles .

To list all databases on a specified database server via Azure Cloud REST API, a GET request must be made to the endpoint 'https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/<PROVIDER>/<DATABASE_SERVER_NAME>/databases'. Ensure the API version parameter is set, for example, 'api-version=2023-06-30'. The request requires an 'Authorization' header with a 'Bearer <ACCESS_TOKEN>' .

To obtain an access token for Azure Cloud REST API, you must authenticate using the OAuth 2.0 client credentials flow. The necessary details for successful authentication include the Tenant ID, Client ID, and Client Secret, which are submitted via a POST request to the 'https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token' endpoint. This request also requires setting the 'Content-Type' as 'application/x-www-form-urlencoded' and specifying the 'scope' as 'https://management.azure.com/.default'. The 'grant_type' is set to 'client_credentials' .

Setting up an application in Azure AD involves creating and configuring an app registration. Follow Microsoft's documentation on registering an application, providing essential information, and obtaining the Application (Client) ID, Directory (Tenant) ID, and Secret Value for the app. After setting up, log in to the Azure portal to retrieve the Subscription ID and Resource Group required for making API calls .

To retrieve a list of containers or buckets in a specified Storage Account, you use the endpoint 'https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Storage/storageAccounts/<STORAGE_ACCOUNT_NAME>/blobServices/default/containers', ensuring the 'api-version=2023-01-01' parameter is set. The request requires an 'Authorization' header with a 'Bearer <ACCESS_TOKEN>' .

To retrieve a list of data source servers using Azure Cloud REST API, you must execute a GET request at 'https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resources', appending the query parameters for API version and resource filtering. You must specify '$filter= resourceGroup eq <RESOURCE_GROUP> and' followed by your desired resource types using 'resourceType eq'. Include valid resource types such as 'Microsoft.DBforMySQL/servers' or 'Microsoft.Sql/servers'. The request needs an 'Authorization' header with a 'Bearer <ACCESS_TOKEN>' .

In the Azure OAuth 2.0 token retrieval process, the 'scope' parameter defines the resources the token should access. It is set to 'https://management.azure.com/.default' to authorize resource management operations. The 'grant_type', set to 'client_credentials', specifies the authorization method, in this case providing server-to-server communication authentication without user intervention. Both parameters are pivotal for defining and limiting API access policies securely .

The Client Secret is essential in the Azure AD app registration process as it acts as a password for the client application, ensuring that only authenticated clients can access the API. During app registration, generating the Client Secret is crucial for authentication with OAuth 2.0 protocol. This secret is securely stored and utilized during API token requests, impacting how secure and controlled interactions with Azure APIs are carried out .

Finding data source servers involves using a GET request to a generalized endpoint filtering by subscription and resource type across potentially multiple types, using '$filter' directives. In contrast, listing databases is a more specific process directed at a particular database server, requiring access to a detailed endpoint that provides information on databases only. Both processes necessitate appropriate OAuth2 authentication, with endpoints requiring the 'Bearer <ACCESS_TOKEN>' in the HTTP header for authorization .

You might also like