Skip to content

Commit 2371f6b

Browse files
committed
keyless auth
1 parent 81c2a17 commit 2371f6b

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

articles/search/includes/quickstarts/full-text-csharp.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,23 +623,41 @@ In *Program.cs*, you created two clients:
623623
624624
Both clients need the search service endpoint and credentials described previously in the [resource information](#retrieve-resource-information) section.
625625
626-
Because the code builds out the URI for you, you only specify the search service name in the `serviceName` property.
626+
The sample code in this quickstart uses Microsoft Entra ID for authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with a `AzureKeyCredential` object.
627+
628+
#### [Microsoft Entra ID](#tab/keyless)
629+
630+
```csharp
631+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
632+
DefaultAzureCredential credential = new();
633+
```
634+
635+
#### [API key](#tab/api-key)
636+
637+
```csharp
638+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
639+
AzureKeyCredential credential = new AzureKeyCredential("<Your search service admin key>");
640+
```
641+
---
627642
628643
```csharp
629644
static void Main(string[] args)
630645
{
631-
string serviceName = "<your-search-service-name>";
632-
string apiKey = "<your-search-service-admin-api-key>";
633-
string indexName = "hotels-quickstart";
646+
// Your search service endpoint
647+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
648+
649+
// Use the recommended keyless credential instead of the AzureKeyCredential credential.
650+
DefaultAzureCredential credential = new();
651+
//AzureKeyCredential credential = new AzureKeyCredential("Your search service admin key");
634652
635653
// Create a SearchIndexClient to send create/delete index commands
636-
Uri serviceEndpoint = new Uri($"https://{serviceName}.search.windows.net/");
637-
AzureKeyCredential credential = new AzureKeyCredential(apiKey);
638654
SearchIndexClient adminClient = new SearchIndexClient(serviceEndpoint, credential);
639655
640656
// Create a SearchClient to load and query documents
657+
string indexName = "hotels-quickstart";
641658
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
642-
. . .
659+
660+
// REDACTED FOR BREVITY . . .
643661
}
644662
```
645663

0 commit comments

Comments
 (0)