Skip to content

Commit f693486

Browse files
authored
Merge pull request #223990 from HeidiSteen/heidist-rbac
Added a screenshot and better info for usage of api keys
2 parents 0e2dd73 + 7f9aaae commit f693486

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed
33.4 KB
Loading

articles/search/search-security-api-keys.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: HeidiSteen
88
ms.author: heidist
99
ms.service: cognitive-search
1010
ms.topic: how-to
11-
ms.date: 01/10/2023
11+
ms.date: 01/14/2023
1212
---
1313

1414
# Connect to Cognitive Search using key authentication
@@ -47,21 +47,30 @@ Best practices for using hard-coded keys in source files include:
4747

4848
### [**Portal**](#tab/portal-use)
4949

50-
In Cognitive Search, most tasks can be performed in Azure portal, including object creation, indexing through the Import data wizard, and queries through Search explorer.
50+
Key authentication is built in so no action is required. By default, the portal uses API keys to authenticate the request automatically. However, if you [disable API keys](search-security-rbac.md#disable-api-key-authentication) and set up role assignments, the portal uses role assignments instead.
5151

52-
Authentication is built in so no action is required. By default, the portal uses API keys to authenticate the request automatically. However, if you [disable API keys](search-security-rbac.md#disable-api-key-authentication) and set up role assignments, the portal uses role assignments instead.
52+
In Cognitive Search, most tasks can be performed in Azure portal, including object creation, indexing through the Import data wizard, and queries through Search explorer.
5353

5454
### [**PowerShell**](#tab/azure-ps-use)
5555

56+
Set API keys in the request header using the following syntax:
57+
58+
```azurepowershell
59+
$headers = @{
60+
'api-key' = '<YOUR-ADMIN-OR-QUERY-API-KEY>'
61+
'Content-Type' = 'application/json'
62+
'Accept' = 'application/json' }
63+
```
64+
5665
A script example showing API key usage for various operations can be found at [Quickstart: Create an Azure Cognitive Search index in PowerShell using REST APIs](search-get-started-powershell.md).
5766

5867
### [**REST API**](#tab/rest-use)
5968

60-
+ Admin keys are only specified in HTTP request headers. You can't place an admin API key in a URL. See [Connect to Azure Cognitive Search using REST APIs](search-get-started-rest.md#connect-to-azure-cognitive-search) for an example that specifies an admin API key on a REST call.
69+
Set an admin key in the request header using the syntax `api-key` equal to your key. Admin keys are used for most operations, including create, delete, and update. Admin keys are also used on requests issued to the search service itself, such as listing objects or requesting service statistics. see [Connect to Azure Cognitive Search using REST APIs](search-get-started-rest.md#connect-to-azure-cognitive-search) for a more detailed example.
6170

62-
+ Query keys are also specified in an HTTP request header for search, suggestion, or lookup operation that use POST.
71+
:::image type="content" source="media/search-security-api-keys/rest-headers.png" alt-text="Screenshot of the Headers section of a request in Postman." border="true":::
6372

64-
Alternatively, you can pass a query key as a parameter on a URL if you're using GET: `GET /indexes/hotels/docs?search=*&$orderby=lastRenovationDate desc&api-version=2020-06-30&api-key=[query key]`
73+
Query keys are used for search, suggestion, or lookup operations that target the `index/docs` collection. For POST, set `api-key` in the request header. Or, put the key on the URI for a GET: `GET /indexes/hotels/docs?search=*&$orderby=lastRenovationDate desc&api-version=2020-06-30&api-key=[query key]`
6574

6675
### [**C#**](#tab/dotnet-use)
6776

@@ -101,7 +110,7 @@ You can view and manage API keys in the [Azure portal](https://portal.azure.com)
101110

102111
### [**PowerShell**](#tab/azure-ps-find)
103112

104-
1. Install the Az.Search module:
113+
1. Install the `Az.Search` module:
105114

106115
```azurepowershell
107116
Install-Module Az.Search

0 commit comments

Comments
 (0)