Make Azure.Identity optional in AzureFoundry via injectable TokenCredential#9779
Conversation
…ential Removes the hard Azure.Identity/MSAL dependency from the core Microsoft.Testing.Extensions.AzureFoundry package. API-key users no longer pull the managed-identity graph; Entra ID / managed identity is now opt-in by referencing Azure.Identity and passing a TokenCredential to AddAzureOpenAIChatClientProvider. Fixes #9712 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR reworks the Azure OpenAI chat client provider so that it authenticates with an API key by default and only uses Entra ID / managed identity when a TokenCredential is explicitly supplied. This removes the hard dependency on Azure.Identity (and its MSAL graph) from the package, replacing it with a lighter Azure.Core reference and an injectable credential.
Changes:
- Replaced the implicit
DefaultAzureCredentialfallback with an optional, injectableTokenCredential, adding aNoneauthentication mode when neither an API key nor a credential is available. - Added a new
AddAzureOpenAIChatClientProvider(ITestApplicationBuilder, TokenCredential)overload and a newNoAuthenticationConfigurederror resource. - Swapped the
Azure.Identitypackage reference forAzure.Core, and updated public/internal API baselines, docs, and tests accordingly.
Show a summary per file
| File | Description |
|---|---|
OpenAIChatClientProvider.cs |
Core change: injectable credential, None auth mode, API-key-first selection logic, and throw when no auth is configured. |
TestApplicationBuilderExtensions.cs |
Adds a credential-accepting overload and updates XML docs. |
Resources/ExtensionResources.resx |
Adds the NoAuthenticationConfigured error message. |
PublicAPI/PublicAPI.Unshipped.txt |
Declares the new public overload. |
PACKAGE.md |
Documents API-key-by-default and opt-in TokenCredential authentication. |
Microsoft.Testing.Extensions.AzureFoundry.csproj |
Replaces Azure.Identity with Azure.Core. |
InternalAPI/InternalAPI.Unshipped.txt |
Adds new enum members and constructor. |
InternalAPI/InternalAPI.Shipped.txt |
Removes old enum members and updates GetAuthenticationMode signature. |
Directory.Packages.props |
Replaces the Azure.Identity package version with Azure.Core. |
AzureFoundryChatClientProviderTests.cs |
Updates and adds tests for the new authentication behavior. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 1
- Review effort level: Medium
🧪 Test quality grade — PR #977914 changed test methods graded across 1 file (
This advisory comment was generated automatically. Grades are heuristic
|
Fixes #9712
Summary
Implements the
TokenCredential-injection option from #9712 so thatMicrosoft.Testing.Extensions.AzureFoundryno longer carries a hard dependency onAzure.Identity(and its heavyweight MSAL graph). API-key users pull zero managed-identity assemblies; Entra ID / managed identity remains fully supported but is now opt-in — the consumer referencesAzure.Identitythemselves and passes a credential.This reworks the authentication added in #9707. It is not a revert: the managed-identity capability is preserved, only the
Azure.Identityreference and thenew DefaultAzureCredential()call move out of the package and into the caller (the idiomatic Azure SDK pattern thatAzure.AI.OpenAIitself follows).Changes
OpenAIChatClientProvider.cs— removed the staticLazy<DefaultAzureCredential>andusing Azure.Identity. Added an optional injectedTokenCredential(new constructor overload), anAuthenticationModeofNone/ApiKey/TokenCredential, andGetAuthenticationMode(apiKey, credential).IsAvailablenow also requires an API key or an injected credential; when neither is presentCreateChatClientAsyncthrows a clearInvalidOperationException.TestApplicationBuilderExtensions.cs— newAddAzureOpenAIChatClientProvider(this ITestApplicationBuilder, TokenCredential)overload (the parameterless API-key/auto-registered overload is kept)..csproj+Directory.Packages.props— droppedAzure.Identity; addedAzure.Core(1.44.1, already the transitive floor fromAzure.AI.OpenAI) sinceTokenCredentialnow appears in the public API.NoAuthenticationConfiguredstring.PACKAGE.md— documented the opt-in Entra ID model.Behavioral change (needs sign-off)
This drops #9707's zero-config
DefaultAzureCredentialfallback: Entra users now referenceAzure.Identityand pass a credential explicitly. This is exactly the dependency-footprint tradeoff #9712 asks to weigh before GA, surfaced here as a concrete diff for the team to review.Verification
Notes
IsShipping=false, and Arcade'sLocalization.targetsonly wires XliffTasks for shipping assemblies, soUpdateXlfis unavailable and CI does not validate xlf for this project. Per the repo rule against hand-editing xlf, the.xlffiles are left untouched; the loc pipeline will regenerate them when the package flips to shipping.