feat: add Azure AD token-based authentication support #4019
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: add Azure AD token-based authentication support
Summary
This PR adds support for Azure AD token-based authentication in the Azure AI Inference provider, addressing issue #4018. Users can now authenticate using Azure AD tokens instead of API keys, which is required by organizations that have deprecated API key usage.
The implementation adds two new parameters to
AzureCompletion:azure_ad_token_provider: A callable (typically fromazure.identity.get_bearer_token_provider()) that returns tokenscredential: ATokenCredentialinstance (e.g.,DefaultAzureCredential,ManagedIdentityCredential)Authentication priority:
credential>azure_ad_token_provider>api_keyExample usage:
Review & Testing Checklist for Human
_TokenProviderCredentialwrapper behavior: The wrapper assumes token providers are zero-arg callables and assigns a 1-hour default expiry for string tokens. Confirm this aligns withazure.identity.get_bearer_token_provider()behavior.DefaultAzureCredentialorManagedIdentityCredentialin an Azure environment.Recommended test plan:
DefaultAzureCredentialusing thecredentialparameterget_bearer_token_providerusing theazure_ad_token_providerparameterNotes
Fixes #4018
Link to Devin run: https://app.devin.ai/sessions/760e5d73df0c449db4afd2506026d78e
Requested by: João ([email protected])