You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-howto-aad.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ ms.date: 1/05/2022
11
11
ms.custom: subject-rbac-steps
12
12
---
13
13
14
-
# Authorize access to a search apps using Azure Active Directory
14
+
# Authorize access to a search app using Azure Active Directory
15
15
16
16
> [!IMPORTANT]
17
17
> Role-based access control for data plane operations, such as creating or querying an index, is currently in public preview and available under [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/). This functionality is only available in public cloud regions and may impact the latency of your operations while the functionality is in preview. For more information on preview limitations, see [RBAC preview limitations](search-security-rbac.md#preview-limitations).
Copy file name to clipboardExpand all lines: articles/search/search-security-rbac.md
+95-5Lines changed: 95 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -216,19 +216,109 @@ When testing roles, remember that roles are cumulative and inherited roles that
216
216
217
217
### [**REST API**](#tab/test-rest)
218
218
219
-
+ Register your REST client with Azure Active Directory.
219
+
This approach assumes Postman as the REST client and uses a Postman collection and variables to provide the bearer token. You'll need Azure CLI or another tool to create a security principal for the REST client.
220
220
221
-
+ Revise your code to use a [Search REST API](/rest/api/searchservice/) (any supported version) and set the **Authorization** header on requests, replacing the **api-key** header.
221
+
1. Open a command shell for Azure CLI and sign in to your Azure subscription.
222
222
223
-
:::image type="content" source="media/search-security-rbac/rest-authorization-header.png" alt-text="Screenshot of an HTTP request with an Authorization header" border="true":::
223
+
```azurecli
224
+
az login
225
+
```
226
+
227
+
1. Get your subscription ID. You'll provide this value as variable in a future step.
228
+
229
+
```azurecli
230
+
az account show --query id -o tsv
231
+
````
232
+
233
+
1. Create a resource group for your security principal, specifying a location and name. This example uses the West US region. You'll provide this value as variable in a future step.
234
+
235
+
```azurecli
236
+
az group create -l westus -n MyResourceGroup
237
+
```
238
+
239
+
1. Create the service principal, replacing the placeholder values with valid values. You'll need a descriptive security principal name, subscription ID, and resource group name. This example uses the "Search Index Data Reader" (quote enclosed) role.
240
+
241
+
```azurecli
242
+
az ad sp create-for-rbac --name mySecurityPrincipalName --role "Search Index Data Reader" --scopes /subscriptions/mySubscriptionID/resourceGroups/myResourceGroupName
243
+
```
244
+
245
+
A successful response includes "appId", "password", and "tenant". You'll use these values for the variables "clientId", "clientSecret", and "tenant".
246
+
247
+
1. Start a new Postman collection and edit its properties. In the Variables tab, create the following variables:
248
+
249
+
| Variable | Description |
250
+
|----------|-------------|
251
+
| clientId | Provide the previously generated "appID" that you created in Azure AD. |
252
+
| clientSecret | Provide the "password" that was created for your client. |
253
+
| tenantId | Provide the "tenant" that was returned in the previous step. |
254
+
| subscriptionId | Provide the subscription ID for your subscription. |
255
+
| resource | Enter `https://search.azure.com`. |
256
+
| bearerToken | (leave blank; the token is generated programmatically) |
257
+
258
+
1. In the Authorization tab, select **Bearer Token** as the type.
259
+
260
+
1. In the **Token** field, specify the variable placeholder `{{bearerToken}}`.
261
+
262
+
1. In the Pre-request Script tab, paste in the following script:
263
+
264
+
```javascript
265
+
pm.test("Check for collectionVariables", function () {
266
+
let vars = ['clientId', 'clientSecret', 'tenantId', 'subscriptionId'];
267
+
vars.forEach(function (item, index, array) {
268
+
console.log(item, index);
269
+
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.undefined;
270
+
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.empty;
271
+
});
272
+
273
+
if (!pm.collectionVariables.get("bearerToken") || Date.now() > new Date(pm.collectionVariables.get("bearerTokenExpiresOn") * 1000)) {
1. Send a request that uses the variables you've specified. For the "Search Index Data Reader" role, you can query an index (remember to provide a valid search service name on the URI):
303
+
304
+
```http
305
+
POST https://<service-name>.search.windows.net/indexes/hotels-quickstart/docs/search?api-version=2020-06-20
306
+
{
307
+
"queryType": "simple",
308
+
"search": "motel",
309
+
"filter": "",
310
+
"select": "HotelName,Description,Category,Tags",
311
+
"count": true
312
+
}
313
+
```
224
314
225
315
For more information on how to acquire a token for a specific environment, see [Microsoft identity platform authentication libraries](../active-directory/develop/reference-v2-libraries.md).
226
316
227
317
### [**.NET SDK**](#tab/test-csharp)
228
318
229
-
The Azure SDK for .NET supports an authorization header in the [NuGet Gallery | Azure.Search.Documents 11.4.0-beta.2](https://www.nuget.org/packages/Azure.Search.Documents/11.4.0-beta.2) package.
319
+
See [Authorize access to a search app using Azure Active Directory](/search-howto-aad.md)for instructions that create an identity for your client app, assign a role, and call [DefaultAzureCredential()](/dotnet/api/azure.identity.defaultazurecredential).
230
320
231
-
Configuration is required to register an application with Azure Active Directory, and to obtain and pass authorization tokens:
321
+
The Azure SDK for .NET supports an authorization header in the [NuGet Gallery | Azure.Search.Documents 11.4.0-beta.2](https://www.nuget.org/packages/Azure.Search.Documents/11.4.0-beta.2) package. Configuration is required to register an application with Azure Active Directory, and to obtain and pass authorization tokens:
232
322
233
323
+ When obtaining the OAuth token, the scope is "https://search.azure.com/.default". The SDK requires the audience to be "https://search.azure.com". The ".default" is an Azure AD convention.
0 commit comments