-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
AzureSearch Oauth with azure_ad_access_token
not working: TokenCredential
cannot be instantiated
#26216
Comments
This also fails in the same manner when attempting to use Managed Service Identity, which is preferable from a security perspective as it removes the weakness of persistent secrets which could be compromised and used by a malicious actor. For reference the issue also exists on: |
**Description:** AzureSearch vector store: create a wrapper class on `azure.core.credentials.TokenCredential` (which is not-instantiable) to fix Oauth usage with `azure_ad_access_token` argument **Issue:** [the issue it fixes](#26216) **Dependencies:** None - [x] **Lint and test** --------- Co-authored-by: Erick Friis <[email protected]>
Hi @efriis the fix introduced will most probably fail in the async scenario, as the asyncSearchClient expects an AsyncTokenCredential (one with an async version of get_token). Additionally, the approach of providing an ad_token has a limitation on long running processes where the token will expire and the only way is to recreate from outside the whole AzureSearch object. But there are some cases where DefaultAzureCredentials doesn't work and you need to use a special configuration to get the credentials. The problem with sync/async will also be present in the fallback case and in this new one |
would recommend using the sync implementation for now; if you find a failure feel free to contribute a unit test showing the issue, as well as a fix! in general AzureSearch should be migrated to https://github.com/langchain-ai/langchain-azure |
Checked other resources
Example Code
The following code fails to instantiate an AzureSearch instance:
Error Message and Stack Trace (if applicable)
Description
instantiating
AzureSearch
withazure_ad_access_token
!= None is trying to create an instance ofTokenCredential
which is an interface and not instantiable. (see https://python.langchain.com/v0.2/api_reference/_modules/langchain_community/vectorstores/azuresearch.html#AzureSearch.__init__ )Additional Notes:
azure_search_key
&azure_ad_access_token
toNone
but setting the following env var: (authentification will then use thefrom azure.identity import DefaultAzureCredential
class. see Azure doc about thisos.environ["AZURE_TENANT_ID"] = TENANTID
os.environ["AZURE_CLIENT_ID"] = APPID
os.environ["AZURE_CLIENT_SECRET"] = APPSECRET
System Info
langchain-community==0.2.16
platform: mac
python 3.9
The text was updated successfully, but these errors were encountered: