Skip to content

Commit 3dbde01

Browse files
authored
Merge branch 'main' into chrisda
2 parents f859bae + 900fcc6 commit 3dbde01

File tree

9 files changed

+67
-54
lines changed

9 files changed

+67
-54
lines changed

CloudAppSecurityDocs/api-authentication-application.md

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,43 @@ This article explains how to create a Microsoft Entra application, get an access
2828
1. To enable your app to access Defender for Cloud Apps and assign it **'Read all alerts'** permission, on your application page, select **API Permissions** > **Add permission** > **APIs my organization uses** >, type **Microsoft Cloud App Security**, and then select **Microsoft Cloud App Security**.
2929

3030
> [!NOTE]
31-
> *Microsoft Cloud App Security* does not appear in the original list. Start writing its name in the text box to see it appear. Make sure to type this name, even though the product is now called Defender for Cloud Apps.
31+
> *Microsoft Cloud App Security* doesn't appear in the original list. Start writing its name in the text box to see it appear. Make sure to type this name, even though the product is now called Defender for Cloud Apps.
3232
33-
![Screenshot of adding permission.](media/add-permission.png)
3433

35-
- Select **Application permissions** > **Investigation.Read**, and then select **Add permissions**.
34+
:::image type="content" source="media/api-authentication-application/add-app-permissions.png" alt-text="Screenshot showing how to configure API permissions for your application." lightbox="media/api-authentication-application/add-app-permissions.png":::
3635

37-
:::image type="content" source="media/application-permissions.png" alt-text="Screenshot of adding app permission." lightbox="media/application-permissions.png":::
3836

39-
You need to select the relevant permissions. **Investigation.Read** is only an example. For other permission scopes, see [Supported permission scopes](#supported-permission-scopes)
37+
1. Select **Application permissions** > **Investigation.Read**, and then select **Add permissions**.
4038

41-
- To determine which permission you need, look at the **Permissions** section in the API you're interested to call.
39+
:::image type="content" source="media/api-authentication-application/request-permissions.png" alt-text="Screenshot that shows which API permissions to request for your application." lightbox="media/api-authentication-application/request-permissions.png":::
40+
41+
1. You need to select the relevant permissions. **Investigation.Read** is only an example. For other permission scopes, see [Supported permission scopes](#supported-permission-scopes)
42+
43+
1. To determine which permission you need, look at the **Permissions** section in the API you're interested to call.
4244

4345
1. Select **Grant admin consent**.
4446

4547
> [!NOTE]
4648
> Every time you add a permission, you must select **Grant admin consent** for the new permission to take effect.
4749
48-
![Screenshot of granting admin permissions.](media/grant-consent.png)
4950

50-
1. To add a secret to the application, select **Certificates & secrets**, select **New client secret**, add a description to the secret, and then select **Add**.
51+
:::image type="content" source="media/api-authentication-application/grant-consent.png" alt-text="Screenshot that shows the option to grant admin consent." lightbox="media/api-authentication-application/grant-consent.png":::
52+
53+
54+
1. To add a secret to the application, select **Certificates & secrets**, select **New client secret**. Add a description to the secret, and then select **Add**.
5155

5256
> [!NOTE]
5357
> After you select **Add**, select **copy the generated secret value**. You won't be able to retrieve this value after you leave.
5458
55-
![Screenshot of creating an app key.](media/webapp-create-key2.png)
59+
:::image type="content" source="media/api-authentication-application/webapp-create-key2.png" alt-text="Screenshot that shows how to create an app key." lightbox="media/api-authentication-application/webapp-create-key2.png":::
60+
5661

5762
1. Write down your application ID and your tenant ID. On your application page, go to **Overview** and copy the **Application (client) ID** and the **Directory (tenant) ID**.
5863

59-
![Screenshot of the created app ID.](media/app-and-tenant-ids.png)
64+
:::image type="content" source="media/api-authentication-application/app-and-tenant-ids.png" alt-text="Screenshot that shows the created app ID." lightbox="media/api-authentication-application/app-and-tenant-ids.png":::
6065

61-
1. **For Microsoft Defender for Cloud Apps Partners only**. Set your app to be multitenanted (available in all tenants after consent). This is **required** for third-party apps (for example, if you create an app that is intended to run in multiple customers' tenant). This is **not required** if you create a service that you want to run in your tenant only (for example, if you create an application for your own usage that will only interact with your own data). To set your app to be multitenanted:
66+
67+
1. **For Microsoft Defender for Cloud Apps Partners only**. Set your app to be multitenant (available in all tenants after consent). This is **required** for third-party apps (for example, if you create an app that is intended to run in multiple customers' tenant). This is **not required** if you create a service that you want to run in your tenant only (for example, if you create an application for your own usage that will only interact with your own data). To set your app to be multitenant:
6268

6369
- Go to **Authentication**, and add `https://portal.azure.com` as the **Redirect URI**.
6470

@@ -161,45 +167,46 @@ See [Microsoft Authentication Library (MSAL) for Python](https://github.com/Azur
161167
1. Set TENANT_ID to the Azure tenant ID of the customer that wants to use your app to access Defender for Cloud Apps.
162168
1. Run the following command:
163169
164-
```curl
165-
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "grant_type=client_credentials" -d "client_id=%CLIENT_ID%" -d "scope=05a65629-4c1b-48c1-a78b-804c4abdd4af/.default" -d "client_secret=%CLIENT_SECRET%" "https://login.microsoftonline.com/%TENANT_ID%/oauth2/v2.0/token" -k
166-
```
170+
```curl
171+
curl -i -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "grant_type=client_credentials" -d "client_id=%CLIENT_ID%" -d "scope=05a65629-4c1b-48c1-a78b-804c4abdd4af/.default" -d "client_secret=%CLIENT_SECRET%" "https://login.microsoftonline.com/%TENANT_ID%/oauth2/v2.0/token" -k
172+
```
167173

168-
You get an answer in the following form:
174+
You get an answer in the following form:
169175

170-
```output
171-
{"token_type":"Bearer","expires_in":3599,"ext_expires_in":0,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIn <truncated> aWReH7P0s0tjTBX8wGWqJUdDA"}
172-
```
176+
```output
177+
{"token_type":"Bearer","expires_in":3599,"ext_expires_in":0,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIn <truncated> aWReH7P0s0tjTBX8wGWqJUdDA"}
178+
```
173179

174180
## Validate the token
175181

176182
Ensure that you got the correct token:
177183

178184
1. Copy and paste the token you got in the previous step into [JWT](https://jwt.ms) in order to decode it.
179-
1. Validate that you get a 'roles' claim with the desired permissions
185+
1. Validate that you get a 'roles' claim with the desired permissions.
180186
1. In the following image, you can see a decoded token acquired from an app with permissions to all Microsoft Defender for Cloud Apps roles:
181187

182-
![Screenshot of token validation.](media/webapp-decoded-token.png)
188+
:::image type="content" source="media/api-authentication-application/webapp-decoded-token.png" alt-text="Screenshot that shows the decoded token.":::
189+
183190

184191
## Use the token to access Microsoft Defender for Cloud Apps API
185192

186193
1. Choose the API you want to use. For more information, see [Defender for Cloud Apps APIs](api-introduction.md).
187194
1. Set the authorization header in the http request you send to "Bearer {token}" (Bearer is the authorization scheme).
188195
1. The expiration time of the token is one hour. You can send more than one request with the same token.
189196

190-
The following is an example of sending a request to get a list of alerts **using C#**:
191-
192-
```C#
193-
var httpClient = new HttpClient();
194-
195-
var request = new HttpRequestMessage(HttpMethod.Get, "https://portal.cloudappsecurity.com/cas/api/v1/alerts/");
196-
197-
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
198-
199-
var response = httpClient.SendAsync(request).GetAwaiter().GetResult();
200-
201-
// Do something useful with the response
202-
```
197+
The following is an example of sending a request to get a list of alerts **using C#**:
198+
199+
```C#
200+
var httpClient = new HttpClient();
201+
202+
var request = new HttpRequestMessage(HttpMethod.Get, "https://portal.cloudappsecurity.com/cas/api/v1/alerts/");
203+
204+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
205+
206+
var response = httpClient.SendAsync(request).GetAwaiter().GetResult();
207+
208+
// Do something useful with the response
209+
```
203210

204211
## See also
205212

CloudAppSecurityDocs/api-authentication-user.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ In general, you need to take the following steps to use the APIs:
2525
This page explains how to create a Microsoft Entra application, get an access token to Microsoft Defender for Cloud Apps and validate the token.
2626

2727
>[!NOTE]
28-
> When accessing Microsoft Defender for Cloud Apps API on behalf of a user, you will need the correct Application permission and user permission.
29-
> If you are not familiar with user permissions on Microsoft Defender for Cloud Apps, see [Manage admin access](manage-admins.md).
28+
> When accessing Microsoft Defender for Cloud Apps API on behalf of a user, you'll need the correct Application permission and user permission.
29+
> If you aren't familiar with user permissions on Microsoft Defender for Cloud Apps, see [Manage admin access](manage-admins.md).
3030
3131
>[!TIP]
3232
> If you have the permission to perform an action in the portal, you have the permission to perform the action in the API.
@@ -57,31 +57,37 @@ This page explains how to create a Microsoft Entra application, get an access to
5757

5858
1. Allow your Application to access Microsoft Defender for Cloud Apps and assign it 'Read alerts' permission:
5959

60-
- On your application page, select **API Permissions** > **Add permission** > **APIs my organization uses** > type *Microsoft Cloud App Security* and then select **Microsoft Cloud App Security**.
60+
1. On your application page, select **API Permissions** > **Add permission** > **APIs my organization uses** > type *Microsoft Cloud App Security* and then select **Microsoft Cloud App Security**.
6161

62-
- **Note**: *Microsoft Cloud App Security* doesn't appear in the original list. Start writing its name in the text box to see it appear. Make sure to type this name, even though the product is now called Defender for Cloud Apps.
62+
> [!NOTE]
63+
> *Microsoft Cloud App Security* doesn't appear in the original list. Start writing its name in the text box to see it appear. Make sure to type this name, even though the product is now called Defender for Cloud Apps.
6364
64-
![Screenshot of adding permissions.](media/add-permission.png)
65+
:::image type="content" source="media/add-permission.png" alt-text="Screenshot that shows how to add permissions.":::
6566

66-
- Choose **Delegated permissions** > **Investigation.Read** > select **Add permissions**
67+
1. Choose **Delegated permissions** > **Investigation.Read** > select **Add permissions**
6768

68-
![Screenshot of adding application permissions.](media/application-permissions-public-client.png)
69+
:::image type="content" source="media/application-permissions-public-client.png" alt-text="Screenshot showing how to add application permissions.":::
6970

70-
- **Important note**: Select the relevant permissions. **Investigation.Read** is only an example. For other permission scopes, see [Supported permission scopes](#supported-permission-scopes)
7171

72-
- To determine which permission you need, view the **Permissions** section in the API you're interested to call.
72+
> [!NOTE]
73+
> Select the relevant permissions. **Investigation.Read** is only an example. For other permission scopes, see [Supported permission scopes](#supported-permission-scopes)
7374
74-
- Select **Grant admin consent**
75+
1. To determine which permission you need, view the **Permissions** section in the API you're interested to call.
7576

76-
**Note**: Every time you add permission you must select **Grant admin consent** for the new permission to take effect.
77+
1. Select **Grant admin consent**
7778

78-
![Screenshot of of granting admin permissions.](media/grant-consent.png)
79+
> [!NOTE]
80+
> Every time you add permission you must select **Grant admin consent** for the new permission to take effect.
7981
80-
1. Write down your application ID and your tenant ID:
82+
:::image type="content" source="media/api-authentication-application/grant-consent.png" alt-text="Screenshot that shows the option to grant admin consent." lightbox="media/api-authentication-application/grant-consent.png":::
8183

82-
- On your application page, go to **Overview** and copy the following information:
8384

84-
![Screenshot of the created app ID.](media/app-and-tenant-ids.png)
85+
1. Write down your application ID and your tenant ID.
86+
87+
1. On your application page, go to **Overview** and copy the following information:
88+
89+
:::image type="content" source="media/api-authentication-application/app-and-tenant-ids.png" alt-text="Screenshot that shows the created app ID." lightbox="media/api-authentication-application/app-and-tenant-ids.png":::
90+
8591

8692
## Supported permission scopes
8793

@@ -152,19 +158,19 @@ namespace MDA
152158

153159
Verify to make sure you got a correct token:
154160

155-
- Copy/paste into [JWT](https://jwt.ms) the token you got in the previous step in order to decode it
156-
- Validate that you get a 'scp' claim with the desired app permissions
161+
- Copy/paste into [JWT](https://jwt.ms) the token you got in the previous step in order to decode it.
162+
- Validate that you get a 'scp' claim with the desired app permissions.
157163
- In the screenshot below you can see a decoded token acquired from the app in the tutorial:
158164

159-
![Screenshot of token validation.](media/webapp-decoded-token.png)
165+
:::image type="content" source="media/api-authentication-application/webapp-decoded-token.png" alt-text="Screenshot that shows the decoded token.":::
160166

161167
## Use the token to access the Microsoft Defender for Cloud Apps API
162168

163169
- Choose the API you want to use. For more information, see [Defender for Cloud Apps API](api-introduction.md).
164-
- Set the Authorization header in the HTTP request you send to "Bearer {token}" (Bearer is the Authorization scheme)
165-
- The Expiration time of the token is 1 hour (you can send more than one request with the same token)
170+
- Set the Authorization header in the HTTP request you send to "Bearer {token}" (Bearer is the Authorization scheme).
171+
- The Expiration time of the token is 1 hour (you can send more than one request with the same token).
166172

167-
- Example of sending a request to get a list of alerts **using C#**
173+
- Example of sending a request to get a list of alerts **using C#**:
168174

169175
```csharp
170176
var httpClient = new HttpClient();
73.9 KB
Loading
File renamed without changes.
File renamed without changes.
56.3 KB
Loading
File renamed without changes.
File renamed without changes.
-44.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)