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
+97-5Lines changed: 97 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -216,19 +216,111 @@ 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 provided 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. If you don't have Azure CLI installed, you can open [Create a service principal](/cli/azure/create-an-azure-service-principal-azure-cli#1-create-a-service-principal), select **Try It**.
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
+
1. Sign in to your Azure subscription.
224
+
225
+
```azurecli
226
+
az login
227
+
```
228
+
229
+
1. First, get your subscription ID. In the console, enter the following command:
230
+
231
+
```azurecli
232
+
az account show --query id -o tsv
233
+
````
234
+
235
+
1. Create a resource group for your security principal, specifying a location and name. This example uses the West US region.
236
+
237
+
```azurecli
238
+
az group create -l westus -n MyResourceGroup
239
+
```
240
+
241
+
1. Create the service principal, replacing the placeholder values with valid values. You'll need a descriptive security principal name, subscription ID, resource group name. This example uses the "Search Service Contributor" (quote enclosed) role.
242
+
243
+
```azurecli
244
+
az ad sp create-for-rbac --name mySecurityPrincipalName --role "Search Service Contributor" --scopes /subscriptions/mySubscriptionID/resourceGroups/myResourceGroupName
245
+
```
246
+
247
+
A successful response includes "appId", "password", and "tenant". You'll use these values for the variables "clientId", "clientSecret", and "tenant".
248
+
249
+
1. Start a new Postman collection and edit its properties. In the Variables tab, create the following variables:
250
+
251
+
| Variable | Description |
252
+
|----------|-------------|
253
+
| clientId | Provide the previously generated "appID" that you created in Azure AD. |
254
+
| clientSecret | Provide the "password" that was created for your client. |
255
+
| tenantId | Provide the "tenant" that was returned in the previous step. |
256
+
| subscriptionId | Provide the subscription ID for your subscription. |
257
+
| resource | Enter `https://search.azure.com`. |
258
+
| bearerToken | (leave blank; the token is generated programmatically) |
259
+
260
+
1. In the Authorization tab, select **Bearer Token** as the type.
261
+
262
+
1. In the **Token** field, specify the variable placeholder `{{bearerToken}}`.
263
+
264
+
1. In the Pre-request Script tab, paste in the following script:
265
+
266
+
```javascript
267
+
pm.test("Check for collectionVariables", function () {
268
+
let vars = ['clientId', 'clientSecret', 'tenantId', 'subscriptionId'];
269
+
vars.forEach(function (item, index, array) {
270
+
console.log(item, index);
271
+
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.undefined;
272
+
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.empty;
273
+
});
274
+
275
+
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):
305
+
306
+
```http
307
+
POST https://<service-name>.search.windows.net/indexes/hotels-quickstart/docs/search?api-version=2020-06-20
308
+
{
309
+
"queryType": "simple",
310
+
"search": "motel",
311
+
"filter": "",
312
+
"select": "HotelName,Description,Category,Tags",
313
+
"count": true
314
+
}
315
+
```
224
316
225
317
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
318
227
319
### [**.NET SDK**](#tab/test-csharp)
228
320
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.
321
+
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
322
231
-
Configuration is required to register an application with Azure Active Directory, and to obtain and pass authorization tokens:
323
+
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
324
233
325
+ 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