Skip to content

Commit 36ff966

Browse files
committed
Merge branch 'main' into QuarRR-chrisda
2 parents 7f8dced + fb40541 commit 36ff966

9 files changed

+204
-141
lines changed

defender-endpoint/api/exposed-apis-create-app-partners.md

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.service: defender-endpoint
66
ms.author: siosulli
77
author: siosulli
88
ms.localizationpriority: medium
9-
ms.date: 01/25/2023
9+
ms.date: 06/28/2024
1010
manager: deniseb
1111
audience: ITPro
1212
ms.collection:
@@ -46,13 +46,19 @@ Microsoft Defender for Endpoint exposes much of its data and actions through a s
4646

4747
In general, you need to take the following steps to use the APIs:
4848

49-
- Create a **multi-tenant** Microsoft Entra application.
50-
- Get authorized(consent) by your customer administrator for your application to access Defender for Endpoint resources it needs.
51-
- Get an access token using this application.
52-
- Use the token to access Microsoft Defender for Endpoint API.
49+
1. Create a multi-tenant Microsoft Entra application.
50+
51+
2. Get authorized(consent) by your customer administrator for your application to access Defender for Endpoint resources it needs.
52+
53+
3. Get an access token using this application.
54+
55+
4. Use the token to access Microsoft Defender for Endpoint API.
5356

5457
The following steps guide you how to create a Microsoft Entra application, get an access token to Microsoft Defender for Endpoint and validate the token.
5558

59+
> [!IMPORTANT]
60+
> Microsoft recommends that you use roles with the fewest permissions. This helps improve security for your organization. Global Administrator is a highly privileged role that should be limited to emergency scenarios when you can't use an existing role.
61+
5662
## Create the multitenant app
5763

5864
1. Sign in to your [Azure tenant](https://portal.azure.com) with user that has **Global Administrator** role.
@@ -75,34 +81,34 @@ The following steps guide you how to create a Microsoft Entra application, get a
7581

7682
- On your application page, select **API Permissions** \> **Add permission** \> **APIs my organization uses** > type **WindowsDefenderATP** and select on **WindowsDefenderATP**.
7783

78-
- Note that *WindowsDefenderATP* doesn't appear in the original list. Start writing its name in the text box to see it appear.
84+
- `WindowsDefenderATP` doesn't appear in the original list. Start writing its name in the text box to see it appear.
7985

8086
:::image type="content" source="../media/add-permission.png" alt-text="The Add a permission option" lightbox="../media/add-permission.png":::
8187

8288
### Request API permissions
8389

84-
To determine which permission you need, review the **Permissions** section in the API you're interested to call. For instance:
90+
To determine which permission you need, review the **Permissions** section in the API you want to call. For instance:
8591

86-
- To [run advanced queries](run-advanced-query-api.md), select 'Run advanced queries' permission
87-
- To [isolate a device](isolate-machine.md), select 'Isolate machine' permission
92+
- To [run advanced queries](run-advanced-query-api.md), select the **Run advanced queries** permission.
93+
- To [isolate a device](isolate-machine.md), select the **Isolate machine** permission.
8894

89-
In the following example we use **'Read all alerts'** permission:
95+
In the following example we use **Read all alerts** permission:
9096

9197
1. Choose **Application permissions** \> **Alert.Read.All** > select on **Add permissions**
9298

9399
:::image type="content" source="../media/application-permissions.png" alt-text="The option that allows to add a permission" lightbox="../media/application-permissions.png":::
94100

95101
2. Select **Grant consent**
96102

97-
- **Note**: Every time you add permission you must select on **Grant consent** for the new permission to take effect.
103+
- Every time you add permission you must select on **Grant consent** for the new permission to take effect.
98104

99105
:::image type="content" source="../media/grant-consent.png" alt-text="The option that allows consent to be granted" lightbox="../media/grant-consent.png":::
100106

101107
3. Add a secret to the application.
102108

103109
- Select **Certificates & secrets**, add description to the secret and select **Add**.
104110

105-
**Important**: After you select **Add**, make sure to copy the generated secret value. You won't be able to retrieve it after you leave!
111+
After you select **Add**, make sure to copy the generated secret value. You won't be able to retrieve it after you leave!
106112

107113
:::image type="content" source="../media/webapp-create-key2.png" alt-text="The create app key" lightbox="../media/webapp-create-key2.png":::
108114

@@ -124,9 +130,9 @@ In the following example we use **'Read all alerts'** permission:
124130
https://login.microsoftonline.com/common/oauth2/authorize?prompt=consent&client_id=00000000-0000-0000-0000-000000000000&response_type=code&sso_reload=true
125131
```
126132

127-
Where 00000000-0000-0000-0000-000000000000 should be replaced with your Application ID
133+
Where `00000000-0000-0000-0000-000000000000` should be replaced with your Application ID.
128134

129-
After clicking on the consent link, sign in with the Global Administrator of the customer's tenant and consent the application.
135+
After selecting the consent link, sign in as the Global Administrator of the customer's tenant and consent the application.
130136

131137
:::image type="content" source="../media/app-consent-partner.png" alt-text="The Accept button" lightbox="../media/app-consent-partner.png":::
132138

@@ -136,7 +142,7 @@ In the following example we use **'Read all alerts'** permission:
136142

137143
## Get an access token example
138144

139-
**Note:** To get access token on behalf of your customer, use the customer's tenant ID on the following token acquisitions.
145+
To get access token on behalf of your customer, use the customer's tenant ID on the following token acquisitions.
140146

141147
For more information on Microsoft Entra token, see [Microsoft Entra tutorial](/azure/active-directory/develop/active-directory-v2-protocols-oauth-client-creds).
142148

@@ -166,61 +172,63 @@ return $token
166172

167173
### Using C#
168174

169-
> The below code was tested with Nuget Microsoft.Identity.Client
170-
171175
> [!IMPORTANT]
172-
> The [Microsoft.IdentityModel.Clients.ActiveDirectory](https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory) NuGet package and Azure AD Authentication Library (ADAL) have been deprecated. No new features have been added since June 30, 2020. We strongly encourage you to upgrade, see the [migration guide](/azure/active-directory/develop/msal-migration) for more details.
176+
> The [Microsoft.IdentityModel.Clients.ActiveDirectory](https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory) NuGet package and Azure AD Authentication Library (ADAL) have been deprecated. No new features have been added since June 30, 2020. To upgrade, see the [migration guide](/azure/active-directory/develop/msal-migration).
177+
178+
1. Create a new Console Application.
173179

174-
- Create a new Console Application
175-
- Install NuGet [Microsoft.Identity.Client](https://www.nuget.org/packages/Microsoft.Identity.Client/)
176-
- Add the below using
180+
2. Install NuGet [Microsoft.Identity.Client](https://www.nuget.org/packages/Microsoft.Identity.Client/).
177181

178-
```console
182+
3. Add the following using code:
183+
184+
```console
179185
using Microsoft.Identity.Client;
180-
```
186+
```
181187

182-
- Copy/Paste the below code in your application (don't forget to update the three variables: `tenantId`, `appId`, and `appSecret`)
188+
This code was tested with NuGet `Microsoft.Identity.Client`.
183189

184-
```csharp
185-
string tenantId = "00000000-0000-0000-0000-000000000000"; // Paste your own tenant ID here
186-
string appId = "11111111-1111-1111-1111-111111111111"; // Paste your own app ID here
187-
string appSecret = "22222222-2222-2222-2222-222222222222"; // Paste your own app secret here for a test, and then store it in a safe place!
188-
const string authority = https://login.microsoftonline.com;
189-
const string audience = https://api.securitycenter.microsoft.com;
190+
4. Copy/Paste the following code in your application (don't forget to update the three variables: `tenantId`, `appId`, and `appSecret`).
190191

191-
IConfidentialClientApplication myApp = ConfidentialClientApplicationBuilder.Create(appId).WithClientSecret(appSecret).WithAuthority($"{authority}/{tenantId}").Build();
192+
```csharp
193+
string tenantId = "00000000-0000-0000-0000-000000000000"; // Paste your own tenant ID here
194+
string appId = "11111111-1111-1111-1111-111111111111"; // Paste your own app ID here
195+
string appSecret = "22222222-2222-2222-2222-222222222222"; // Paste your own app secret here for a test, and then store it in a safe place!
196+
const string authority = https://login.microsoftonline.com;
197+
const string audience = https://api.securitycenter.microsoft.com;
192198
193-
List<string> scopes = new List<string>() { $"{audience}/.default" };
199+
IConfidentialClientApplication myApp = ConfidentialClientApplicationBuilder.Create(appId).WithClientSecret(appSecret).WithAuthority($"{authority}/{tenantId}").Build();
194200

195-
AuthenticationResult authResult = myApp.AcquireTokenForClient(scopes).ExecuteAsync().GetAwaiter().GetResult();
201+
List<string> scopes = new List<string>() { $"{audience}/.default" };
196202

197-
string token = authResult.AccessToken;
198-
```
203+
AuthenticationResult authResult = myApp.AcquireTokenForClient(scopes).ExecuteAsync().GetAwaiter().GetResult();
204+
205+
string token = authResult.AccessToken;
206+
```
199207

200208
### Using Python
201209

202-
Refer to [Get token using Python](run-advanced-query-sample-python.md#get-token).
210+
See [Get token using Python](run-advanced-query-sample-python.md#get-token).
203211

204212
### Using Curl
205213

206214
> [!NOTE]
207-
> The below procedure supposed Curl for Windows is already installed on your computer
215+
> The following procedure supposed Curl for Windows is already installed on your computer
208216
209217
1. Open a command window.
210218

211-
2. Set CLIENT_ID to your Azure application ID.
219+
2. Set `CLIENT_ID` to your Azure application ID.
212220

213-
3. Set CLIENT_SECRET to your Azure application secret.
221+
3. Set `CLIENT_SECRET` to your Azure application secret.
214222

215-
4. Set TENANT_ID to the Azure tenant ID of the customer that wants to use your application to access Microsoft Defender for Endpoint application.
223+
4. Set `TENANT_ID` to the Azure tenant ID of the customer that wants to use your application to access Microsoft Defender for Endpoint application.
216224

217225
5. Run the following command:
218226

219227
```curl
220228
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "grant_type=client_credentials" -d "client_id=%CLIENT_ID%" -d "scope=https://securitycenter.onmicrosoft.com/windowsatpservice/.default" -d "client_secret=%CLIENT_SECRET%" "https://login.microsoftonline.com/%TENANT_ID%/oauth2/v2.0/token" -k
221229
```
222230

223-
You get an answer of the form:
231+
You get an answer that resembles the following code snippet:
224232

225233
```console
226234
{"token_type":"Bearer","expires_in":3599,"ext_expires_in":0,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIn <truncated> aWReH7P0s0tjTBX8wGWqJUdDA"}
@@ -232,21 +240,22 @@ Confirm you received a correct token.
232240

233241
1. Copy/paste into [JWT](https://jwt.ms) the token you get in the previous step in order to decode it.
234242

235-
2. Confirm you get a 'roles' claim with the desired permissions.
243+
2. Confirm you get a roles claim with the appropriate permissions.
236244

237245
In the following screenshot, you can see a decoded token acquired from an Application with multiple permissions to Microsoft Defender for Endpoint:
238246

247+
:::image type="content" source="../media/webapp-decoded-token.png" alt-text="The token validation page" lightbox="../media/webapp-decoded-token.png":::
248+
239249
The "tid" claim is the tenant ID the token belongs to.
240250

241-
:::image type="content" source="../media/webapp-decoded-token.png" alt-text="The token validation page" lightbox="../media/webapp-decoded-token.png":::
242251

243252
## Use the token to access Microsoft Defender for Endpoint API
244253

245254
1. Choose the API you want to use. For more information, see [Supported Microsoft Defender for Endpoint APIs](exposed-apis-list.md).
246255

247-
2. Set the Authorization header in the Http request you send to "Bearer {token}" (Bearer is the Authorization scheme). The Expiration time of the token is 1 hour (you can send more than one request with the same token).
256+
2. Set the Authorization header in the Http request you send to `Bearer {token}` (Bearer is the Authorization scheme). The Expiration time of the token is one hour (you can send more than one request with the same token).
248257

249-
Here's an example of sending a request to get a list of alerts **using C#**
258+
Here's an example of sending a request to get a list of alerts using C#:
250259

251260
```csharp
252261
var httpClient = new HttpClient();

0 commit comments

Comments
 (0)