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-api-keys.md
+16-7Lines changed: 16 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ author: HeidiSteen
8
8
ms.author: heidist
9
9
ms.service: cognitive-search
10
10
ms.topic: how-to
11
-
ms.date: 01/10/2023
11
+
ms.date: 01/14/2023
12
12
---
13
13
14
14
# Connect to Cognitive Search using key authentication
@@ -47,21 +47,30 @@ Best practices for using hard-coded keys in source files include:
47
47
48
48
### [**Portal**](#tab/portal-use)
49
49
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.
51
51
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.
53
53
54
54
### [**PowerShell**](#tab/azure-ps-use)
55
55
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
+
56
65
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).
57
66
58
67
### [**REST API**](#tab/rest-use)
59
68
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.
61
70
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":::
63
72
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]`
65
74
66
75
### [**C#**](#tab/dotnet-use)
67
76
@@ -101,7 +110,7 @@ You can view and manage API keys in the [Azure portal](https://portal.azure.com)
0 commit comments