Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: community: fix AzureSearch Oauth with azure_ad_access_token #26995

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions libs/community/langchain_community/vectorstores/azuresearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ def _get_search_client(
VectorSearchProfile,
)

class AzureBearerTokenCredential(TokenCredential):
def __init__(self, token: str):
# set the expiry to an hour from now.
self._token = AccessToken(token, int(time.time()) + 3600)

def get_token(
self,
*scopes: str,
claims: Optional[str] = None,
tenant_id: Optional[str] = None,
enable_cae: bool = False,
**kwargs: Any,
) -> AccessToken:
return self._token

additional_search_client_options = additional_search_client_options or {}
default_fields = default_fields or []
credential: Union[AzureKeyCredential, TokenCredential, InteractiveBrowserCredential]
Expand All @@ -131,11 +146,7 @@ def _get_search_client(
else:
credential = AzureKeyCredential(key)
elif azure_ad_access_token is not None:
credential = TokenCredential(
lambda *scopes, **kwargs: AccessToken(
azure_ad_access_token, int(time.time()) + 3600
)
)
credential = AzureBearerTokenCredential(azure_ad_access_token)
else:
credential = DefaultAzureCredential()
index_client: SearchIndexClient = SearchIndexClient(
Expand Down
Loading