added interactive login for azure cognitive search vector store (#11360)

**Description:** Previously if the access to Azure Cognitive Search was
not done via an API key, the default credential was called which doesn't
allow to use an interactive login. I simply added the option to use
"INTERACTIVE" as a key name, and this will launch a login window upon
initialization of the AzureSearch object.
pull/11443/head
adrienohana 11 months ago committed by GitHub
parent 53d4f1554a
commit ca346011b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -77,7 +77,7 @@ def _get_search_client(
) -> SearchClient: ) -> SearchClient:
from azure.core.credentials import AzureKeyCredential from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import ResourceNotFoundError from azure.core.exceptions import ResourceNotFoundError
from azure.identity import DefaultAzureCredential from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
from azure.search.documents import SearchClient from azure.search.documents import SearchClient
from azure.search.documents.indexes import SearchIndexClient from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import ( from azure.search.documents.indexes.models import (
@ -93,6 +93,9 @@ def _get_search_client(
default_fields = default_fields or [] default_fields = default_fields or []
if key is None: if key is None:
credential = DefaultAzureCredential() credential = DefaultAzureCredential()
elif key.upper() == "INTERACTIVE":
credential = InteractiveBrowserCredential()
credential.get_token("https://search.azure.com/.default")
else: else:
credential = AzureKeyCredential(key) credential = AzureKeyCredential(key)
index_client: SearchIndexClient = SearchIndexClient( index_client: SearchIndexClient = SearchIndexClient(

Loading…
Cancel
Save