{
    "id": "66386ffd-63b0-498b-a624-d78ac17409cb",
    "name": "Access the Azure REST API",
    "slug": "access-the-azure-rest-api",
    "status": "published",
    "lab_type": "azure",
    "is_sample": false,
    "duration_in_seconds": 1200,
    "metadata": {},
    "session": null,
    "company": "a491bc32-c056-4946-9169-cc053387bada",
    "created": "2020-08-11T12:14:13.040376Z",
    "modified": "2023-10-03T18:58:43.932581Z",
    "is_beta": false,
    "lab_objectives": [],
    "main_learning_area": null,
    "learning_areas": [],
    "categories": [],
    "tags": [],
    "difficulty": null,
    "is_web_access": false,
    "is_lab_experience": false,
    "is_featured": false,
    "cve": null,
    "severity": null,
    "year": null,
    "classification": null,
    "is_trackable": false,
    "cpe_credits": null,
    "is_skill_check": false,
    "external_url": "https://portal.azure.com/",
    "solution_video": "735ab708-b03a-490d-9037-475a8dcf4191",
    "explanation_video": null,
    "description": "# Task: Access the Azure REST API\n\n## Video: Manage API Access to Azure Subscriptions and Resources\n\n**Estimated time:** 15 minutes\n\n## Goal\n\nIn this task you will create an application registration in Azure AD and verify that it works by using the Azure management REST API to create a resource group.\n\n## Pre-requisites\n\n1. Non-production Azure subscription\n\n**Note: This task requires forming and sending HTTP requests to the Azure management endpoint.  It is possible to do this through tools such as the wget command (available in Linux and current Windows 10 versions) but is much easier with the Postman application.  If possible, I recommend downloading and installing Postman. If you cannot install Postman locally, consider provisioning a Windows virtual machine in Azure and using it for the task.**\n\n## Requirements\n\n1. Create a service principal\n2. Generate a token\n3. Provision a resource group\n\n---\n\n## Requirement 1: Create a service principal\n\nTo begin this task you need to provision a service principal named **task-sp** in your Azure AD tenant. The service principal needs contributor rights in your subscription.  Record the client ID, secret, tenant id, and subscription id.  These will be required later.\n\n***Note: The easiest way to set up a service principal is with the Azure CLI command \"az ad sp create-for-rbac\".**\n\n## Requirement 2: Generate a token\n\nCalls to the Azure REST API require a valid bearer token.  This token is created via a POST request sent to the Azure AD authentication endpoint.  Generate a POST request with the following settings:\n\n|  Setting | Value                                                             |\n| -------: | ----------------------------------------------------------------- |\n|     Verb | **POST**                                                          |\n|      URI | **<https://login.microsoftonline.com/{{TenantID}}/oauth2/token>** |\n| **Body** |                                                                   |\n|          | **grant_type:client_credentials**                                 |\n|          | **client_id:&lt;service principal id&gt;**                    |\n|          | **client_secret:&lt;service principal secret&gt;**                |\n|          | **resource:<https://management.azure.com/>**                      |\n\n**NOTE: The format of the input depends on the encoding selected.**\n\nRecord the access_token that is returned from the request.\n\n## Requirement 3: Provision a resource group\n\nFinally, you will provision a new resource group named **task-restapi-rg** via the Azure management REST API. You will use an HTTP PUT request with the following settings:\n\n|     Setting | Value                                                                                                                       |\n| ----------: | --------------------------------------------------------------------------------------------------------------------------- |\n|        Verb | **PUT**                                                                                                                     |\n|         URI | **PUT <https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/task-restapi-rg?api-version=2019-10-01>** |\n| **Headers** ||\n|| **Authorization:Bearer &lt;token from requirement 2&gt;**|\n|**Body**||\n\n  ```json\n  {\n    \"location\": \"eastus\"\n  }\n  ```\n\n## Clean up\n\n- Delete the **task-restapi-rg** resource group.\n- Delete the **task-sp** service principal.\n\n## Solution\n\nHaving trouble completing this task?  View the demonstration video to see how to do it.",
    "description_html": "<h1>Task: Access the Azure REST API</h1>\n<h2>Video: Manage API Access to Azure Subscriptions and Resources</h2>\n<p><strong>Estimated time:</strong> 15 minutes</p>\n<h2>Goal</h2>\n<p>In this task you will create an application registration in Azure AD and verify that it works by using the Azure management REST API to create a resource group.</p>\n<h2>Pre-requisites</h2>\n<ol>\n<li>Non-production Azure subscription</li>\n</ol>\n<p><strong>Note: This task requires forming and sending HTTP requests to the Azure management endpoint.  It is possible to do this through tools such as the wget command (available in Linux and current Windows 10 versions) but is much easier with the Postman application.  If possible, I recommend downloading and installing Postman. If you cannot install Postman locally, consider provisioning a Windows virtual machine in Azure and using it for the task.</strong></p>\n<h2>Requirements</h2>\n<ol>\n<li>Create a service principal</li>\n<li>Generate a token</li>\n<li>Provision a resource group</li>\n</ol>\n<hr />\n<h2>Requirement 1: Create a service principal</h2>\n<p>To begin this task you need to provision a service principal named <strong>task-sp</strong> in your Azure AD tenant. The service principal needs contributor rights in your subscription.  Record the client ID, secret, tenant id, and subscription id.  These will be required later.</p>\n<p><em>*</em>Note: The easiest way to set up a service principal is with the Azure CLI command \"az ad sp create-for-rbac\".**</p>\n<h2>Requirement 2: Generate a token</h2>\n<p>Calls to the Azure REST API require a valid bearer token.  This token is created via a POST request sent to the Azure AD authentication endpoint.  Generate a POST request with the following settings:</p>\n<table>\n<thead>\n<tr>\n<th align=\"right\">Setting</th>\n<th>Value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"right\">Verb</td>\n<td><strong>POST</strong></td>\n</tr>\n<tr>\n<td align=\"right\">URI</td>\n<td><strong><a href=\"https://login.microsoftonline.com/{{TenantID}}/oauth2/token\">https://login.microsoftonline.com/{{TenantID}}/oauth2/token</a></strong></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>Body</strong></td>\n<td></td>\n</tr>\n<tr>\n<td align=\"right\"></td>\n<td><strong>grant_type:client_credentials</strong></td>\n</tr>\n<tr>\n<td align=\"right\"></td>\n<td><strong>client_id:&lt;service principal id&gt;</strong></td>\n</tr>\n<tr>\n<td align=\"right\"></td>\n<td><strong>client_secret:&lt;service principal secret&gt;</strong></td>\n</tr>\n<tr>\n<td align=\"right\"></td>\n<td><strong>resource:<a href=\"https://management.azure.com/\">https://management.azure.com/</a></strong></td>\n</tr>\n</tbody>\n</table>\n<p><strong>NOTE: The format of the input depends on the encoding selected.</strong></p>\n<p>Record the access_token that is returned from the request.</p>\n<h2>Requirement 3: Provision a resource group</h2>\n<p>Finally, you will provision a new resource group named <strong>task-restapi-rg</strong> via the Azure management REST API. You will use an HTTP PUT request with the following settings:</p>\n<table>\n<thead>\n<tr>\n<th align=\"right\">Setting</th>\n<th>Value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"right\">Verb</td>\n<td><strong>PUT</strong></td>\n</tr>\n<tr>\n<td align=\"right\">URI</td>\n<td><strong>PUT <a href=\"https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/task-restapi-rg?api-version=2019-10-01\">https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/task-restapi-rg?api-version=2019-10-01</a></strong></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>Headers</strong></td>\n<td></td>\n</tr>\n<tr>\n<td align=\"right\"></td>\n<td><strong>Authorization:Bearer &lt;token from requirement 2&gt;</strong></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>Body</strong></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<pre class=\"codehilite\"><code class=\"language-json\">{\n  \"location\": \"eastus\"\n}</code></pre>\n\n<h2>Clean up</h2>\n<ul>\n<li>Delete the <strong>task-restapi-rg</strong> resource group.</li>\n<li>Delete the <strong>task-sp</strong> service principal.</li>\n</ul>\n<h2>Solution</h2>\n<p>Having trouble completing this task?  View the demonstration video to see how to do it.</p>",
    "tasks": "",
    "tasks_html": "",
    "published_date": "2020-06-16T15:30:48Z",
    "solutions": "",
    "solutions_html": "",
    "flags": [],
    "min_points_to_pass": null,
    "access_type": "default",
    "user_status": "unstarted",
    "user_lab_status": null,
    "user_status_modified": null,
    "user_flags": []
}