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-security-rbac.md
+25-77Lines changed: 25 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,103 +201,51 @@ Make sure that you [register your client application with Microsoft Entra ID](se
201
201
202
202
### [**REST API**](#tab/test-rest)
203
203
204
-
This approach assumes Postman as the REST client and uses a Postman collection and variables to provide the bearer token. Use Azure CLI or another tool to create a security principal for the REST client.
204
+
This approach assumes Visual Studio Code with a REST client extension.
205
205
206
206
1. Open a command shell for Azure CLI and sign in to your Azure subscription.
207
207
208
208
```azurecli
209
209
az login
210
210
```
211
211
212
-
1. Get your subscription ID. The ID is used as a variable in a future step.
212
+
1. Get your tenant ID and subscription ID. The ID is used as a variable in a future step.
213
213
214
214
```azurecli
215
-
az account show --query id -o tsv
216
-
````
215
+
az account show
216
+
```
217
217
218
-
1. Create a resource group for your security principal. This example uses the West US region. You provide this value as a variable in a future step. The role that you create is scoped to the resource group.
218
+
1.Get an access token.
219
219
220
220
```azurecli
221
-
az group create -l westus -n MyResourceGroup
221
+
az account get-access-token --query accessToken --output tsv
222
222
```
223
223
224
-
1. Create the service principal, replacing the placeholder values with valid values for a security principal name, subscription ID, and resource group name. This example uses the "Search Index Data Reader" (quote enclosed) role.
225
-
226
-
```azurecli
227
-
az ad sp create-for-rbac --name mySecurityPrincipalName --role "Search Index Data Reader" --scopes /subscriptions/mySubscriptionID/resourceGroups/myResourceGroupName
228
-
```
229
-
230
-
A successful response includes "appId", "password", and "tenant". You use these values for the variables "clientId", "clientSecret", and "tenant".
231
-
232
-
1. Start a new Postman collection and edit its properties. In the Variables tab, create the following variables:
233
-
234
-
| Variable | Description |
235
-
|----------|-------------|
236
-
| clientId | Provide the previously generated "appID" that you created in Microsoft Entra ID. |
237
-
| clientSecret | Provide the "password" that was created for your client. |
238
-
| tenantId | Provide the "tenant" that was returned in the previous step. |
239
-
| subscriptionId | Provide the subscription ID for your subscription. |
240
-
| resource | Enter `https://search.azure.com`. |
241
-
| bearerToken | (leave blank; the token is generated programmatically) |
242
-
243
-
1. In the Authorization tab, select **Bearer Token** as the type.
244
-
245
-
1. In the **Token** field, specify the variable placeholder `{{bearerToken}}`.
246
-
247
-
1. In the Pre-request Script tab, paste in the following script:
248
-
249
-
```javascript
250
-
pm.test("Check for collectionVariables", function () {
251
-
let vars = ['clientId', 'clientSecret', 'tenantId', 'subscriptionId'];
252
-
vars.forEach(function (item, index, array) {
253
-
console.log(item, index);
254
-
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.undefined;
255
-
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.empty;
256
-
});
257
-
258
-
if (!pm.collectionVariables.get("bearerToken") || Date.now() > new Date(pm.collectionVariables.get("bearerTokenExpiresOn") * 1000)) {
1. In a new text file in Visual Studio Code, paste in these variables:
284
225
285
-
1. Save the collection.
226
+
```http
227
+
@baseUrl = PASTE-YOUR-SEARCH-SERVICE-URL-HERE
228
+
@index-name = PASTE-YOUR-INDEX-NAME-HERE
229
+
@token = PASTE-YOUR-TOKEN-HERE
230
+
```
286
231
287
-
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). You can use any [supported API version](/rest/api/searchservice/search-service-api-versions).
232
+
1.Paste in and then send a request that uses the variables you've specified. For the "Search Index Data Reader" role, you can send a query. You can use any [supported API version](/rest/api/searchservice/search-service-api-versions).
288
233
289
234
```http
290
-
POST https://<service-name>.search.windows.net/indexes/hotels-quickstart/docs/search?api-version=2020-06-30
291
-
{
292
-
"queryType": "simple",
293
-
"search": "motel",
294
-
"filter": "",
295
-
"select": "HotelName,Description,Category,Tags",
296
-
"count": true
297
-
}
235
+
POST https://{{baseUrl}}/indexes/{{indexName}}/docs/search?api-version=2023-11-01 HTTP/1.1
236
+
Content-type: application/json
237
+
Authorization: Bearer {{token}}
238
+
239
+
{
240
+
"queryType": "simple",
241
+
"search": "motel",
242
+
"filter": "",
243
+
"select": "HotelName,Description,Category,Tags",
244
+
"count": true
245
+
}
298
246
```
299
247
300
-
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).
248
+
For more information on how to acquire a token for a specific environment, see [Manage a Azure AI Search service with REST APIs](search-manage-rest.md) and [Microsoft identity platform authentication libraries](../active-directory/develop/reference-v2-libraries.md).
0 commit comments