Skip to content

Commit 81c2a17

Browse files
committed
keyless auth
1 parent d6ed280 commit 81c2a17

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
5353
dotnet add package Azure.Identity
5454
```
5555

56+
1. For the **recommended** keyless authentication with Microsoft Entra ID, sign in to Azure with the following command:
57+
58+
```console
59+
az login
60+
```
61+
62+
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.
63+
64+
#### [Microsoft Entra ID](#tab/keyless)
65+
66+
```csharp
67+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
68+
DefaultAzureCredential credential = new();
69+
```
70+
71+
#### [API key](#tab/api-key)
72+
73+
```csharp
74+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
75+
AzureKeyCredential credential = new AzureKeyCredential("<Your search service admin key>");
76+
```
77+
---
78+
5679

5780
## Create, load, and query a search index
5881

@@ -76,17 +99,19 @@ In this section, you add code to create a search index, load it with documents,
7699
class Program
77100
{
78101
static void Main(string[] args)
79-
{
80-
string serviceName = "<Put your search service NAME here>";
81-
string apiKey = "<Put your search service ADMIN API KEY here>";
82-
string indexName = "hotels-quickstart";
102+
{
103+
// Your search service endpoint
104+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
105+
106+
// Use the recommended keyless credential instead of the AzureKeyCredential credential.
107+
DefaultAzureCredential credential = new();
108+
//AzureKeyCredential credential = new AzureKeyCredential("Your search service admin key");
83109
84110
// Create a SearchIndexClient to send create/delete index commands
85-
Uri serviceEndpoint = new Uri($"https://{serviceName}.search.windows.net/");
86-
AzureKeyCredential credential = new AzureKeyCredential(apiKey);
87111
SearchIndexClient adminClient = new SearchIndexClient(serviceEndpoint, credential);
88112
89113
// Create a SearchClient to load and query documents
114+
string indexName = "hotels-quickstart";
90115
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
91116
92117
// Delete index if it exists

0 commit comments

Comments
 (0)