Skip to content

Make ITokenCredentialProvider public - #17387

Merged
Eric Erhardt (eerhardt) merged 1 commit into
mainfrom
public-token-credential-provider
May 22, 2026
Merged

Eric Erhardt (eerhardt) merged 1 commit into
mainfrom
public-token-credential-provider

Conversation

@eerhardt

@eerhardt Eric Erhardt (eerhardt) commented May 22, 2026 •

Copy link
Copy Markdown
Member

Description

When integrations and app host code outside of Aspire.Hosting.Azure need to call Azure APIs, they need a TokenCredential. Internally, Aspire.Hosting.Azure already builds and caches one — configured by the user's Azure provisioning options (tenant id, credential source, etc.) and matched to the run/publish execution context — but the service that exposes it (ITokenCredentialProvider) is internal, so external callers couldn't reuse it. They had to construct their own credential and risk drifting from the credential Aspire itself uses.

This change makes ITokenCredentialProvider part of the public surface so external callers can resolve the same TokenCredential that Aspire uses for provisioning and Azure API calls.

User-facing usage

Integrations and app host code can resolve the provider from DI in any context that has access to IServiceProvider and use the credential to talk to Azure:

using Aspire.Hosting.Azure;
using Azure.Core;
using Microsoft.Extensions.DependencyInjection;

// e.g. inside a pipeline step, lifecycle hook, or custom resource:
var provider = serviceProvider.GetRequiredService<ITokenCredentialProvider>();
TokenCredential credential = provider.TokenCredential;

// Use the credential with any Azure SDK client.
var armClient = new ArmClient(credential);

The service is registered as a singleton by AddAzureProvisioning, which is also called indirectly by AddAzureEnvironment and the Azure resource extension methods — so anyone using Aspire's Azure hosting integrations already has it registered. Callers can also replace the registration with their own implementation if they want to plug in a custom credential.

Implementation notes

  • Moved ITokenCredentialProvider from Aspire.Hosting.Azure.Provisioning.Internal to Aspire.Hosting.Azure and changed the accessibility to public. Added <remarks /> documentation noting the lifetime, configuration source, and that the concrete credential type is an implementation detail.
  • DefaultTokenCredentialProvider (the implementation) stays internal.
  • The other types in Aspire.Hosting.Azure.Provisioning.Internal remain internal.
  • Removed now-unneeded using Aspire.Hosting.Azure.Provisioning.Internal; directives in AzureContainerRegistryHelpers.cs and AzurePromptAgentResource.cs.

Validation

  • Added TokenCredentialProviderTests with 4 tests:
    • AddAzureProvisioning registers ITokenCredentialProvider and yields a non-null TokenCredential.
    • The registration is a singleton (same instance on repeated resolution, and the same TokenCredential).
    • Adding an Azure resource (e.g. AddAzureInfrastructure) also registers the provider via the indirect AddAzureProvisioning path.
    • Callers can replace ITokenCredentialProvider with a custom implementation.
  • All new tests pass; 15 related existing tests (DefaultTokenCredentialProviderTests, DefaultUserPrincipalProviderTests) still pass.
  • Dependent projects (Aspire.Hosting.Azure.ContainerRegistry, Aspire.Hosting.Foundry) build cleanly with the moved interface.

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Move the ITokenCredentialProvider interface from
Aspire.Hosting.Azure.Provisioning.Internal to the public
Aspire.Hosting.Azure namespace and change its accessibility to public.

This allows integrations and app host code outside of Aspire.Hosting.Azure
to resolve the service from DI and obtain the TokenCredential that Aspire
uses to authenticate against Azure, configured by Aspire's Azure
provisioning options.

The DefaultTokenCredentialProvider implementation remains internal.

Co-authored-by: Copilot <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17387

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17387"

@eerhardt
Eric Erhardt (eerhardt) enabled auto-merge (squash) May 22, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes ITokenCredentialProvider as a public API in Aspire.Hosting.Azure so external integrations and AppHost code can reuse the same cached/configured TokenCredential Aspire uses for Azure provisioning and SDK calls.

Changes:

  • Moves ITokenCredentialProvider out of Aspire.Hosting.Azure.Provisioning.Internal and makes it public in Aspire.Hosting.Azure with XML documentation.
  • Updates internal callers to reference the new public namespace (removes now-unneeded internal using directives).
  • Adds new unit tests validating DI registration, singleton behavior, indirect registration via Azure resources, and replacement via custom implementation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Aspire.Hosting.Azure.Tests/TokenCredentialProviderTests.cs Adds tests for DI registration/singleton behavior and custom replacement of ITokenCredentialProvider.
src/Aspire.Hosting.Foundry/PromptAgent/AzurePromptAgentResource.cs Drops the Provisioning.Internal import now that the provider interface is public.
src/Aspire.Hosting.Azure/Provisioning/Internal/IProvisioningServices.cs Removes the internal ITokenCredentialProvider declaration from the internal services file.
src/Aspire.Hosting.Azure/ITokenCredentialProvider.cs Introduces the new public ITokenCredentialProvider API with documentation.
src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryHelpers.cs Drops the Provisioning.Internal import now that the provider interface is public.

@eerhardt
Eric Erhardt (eerhardt) merged commit 7aee71a into main May 22, 2026
913 of 920 checks passed
@github-actions github-actions Bot added this to the 13.4 milestone May 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❓ CLI E2E Tests unknown — 96 passed, 0 failed, 5 unknown (commit 53e2e4d)

View all recordings
Status Test Recording
✅ AddPackageInteractiveWhileAppHostRunningDetached ✅ ▶️ View recording
✅ AddPackageWhileAppHostRunningDetached ✅ ▶️ View recording
✅ AgentCommands_AllHelpOutputs_AreCorrect ✅ ▶️ View recording
✅ AgentInitCommand_DefaultSelection_InstallsDefaultSkills ✅ ▶️ View recording
✅ AgentInitCommand_MigratesDeprecatedConfig ✅ ▶️ View recording
❔ AgentMcpListStructuredLogsFromStarterAppCore ❔ ▶️ View recording
✅ AllPublishMethodsBuildDockerImages ✅ ▶️ View recording
✅ AspireAddPackageVersionToDirectoryPackagesProps ✅ ▶️ View recording
✅ AspireInitSingleFileAppHostRunsViaDotnetRunAppHost ✅ ▶️ View recording
✅ AspireInitWithExistingAppHostDirRecreatesMissingNuGetConfigAndPreservesFiles ✅ ▶️ View recording
❔ AspireInitWithSolutionFileGeneratesAppHostThatBuildsAgainstChannelHive ❔ ▶️ View recording
✅ AspireStartUpdatesStaleTypeScriptAppHostPath ✅ ▶️ View recording
✅ AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ✅ ▶️ View recording
✅ AspireUpdateRemovesOrphanAppHostPackageVersionWhenSdkAlreadyCurrent ✅ ▶️ View recording
✅ Banner_DisplayedOnFirstRun ✅ ▶️ View recording
✅ Banner_DisplayedWithExplicitFlag ✅ ▶️ View recording
✅ Banner_NotDisplayedWithNoLogoFlag ✅ ▶️ View recording
✅ CertificatesClean_RemovesCertificates ✅ ▶️ View recording
✅ CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ✅ ▶️ View recording
✅ CertificatesTrust_WithUntrustedCert_TrustsCertificate ✅ ▶️ View recording
✅ ConfigSetGet_CreatesNestedJsonFormat ✅ ▶️ View recording
✅ CreateAndRunAspireStarterProject ✅ ▶️ View recording
✅ CreateAndRunAspireStarterProjectWithBundle ✅ ▶️ View recording
✅ CreateAndRunEmptyAppHostProject ✅ ▶️ View recording
✅ CreateAndRunJavaEmptyAppHostProject ✅ ▶️ View recording
✅ CreateAndRunJsReactProject ✅ ▶️ View recording
✅ CreateAndRunPythonReactProject ✅ ▶️ View recording
✅ CreateAndRunTypeScriptEmptyAppHostProject ✅ ▶️ View recording
✅ CreateAndRunTypeScriptStarterProject ✅ ▶️ View recording
✅ CreateJavaAppHostWithViteApp ✅ ▶️ View recording
✅ CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ✅ ▶️ View recording
❔ DashboardRunWithAgentMcpCore ❔ ▶️ View recording
❔ DashboardRunWithOtelTracesReturnsNoTracesCore ❔ ▶️ View recording
✅ DeployK8sBasicApiService ✅ ▶️ View recording
✅ DeployK8sWithExternalHelmChart ✅ ▶️ View recording
✅ DeployK8sWithGarnet ✅ ▶️ View recording
✅ DeployK8sWithMongoDB ✅ ▶️ View recording
✅ DeployK8sWithMySql ✅ ▶️ View recording
✅ DeployK8sWithPostgres ✅ ▶️ View recording
✅ DeployK8sWithRabbitMQ ✅ ▶️ View recording
✅ DeployK8sWithRedis ✅ ▶️ View recording
✅ DeployK8sWithSqlServer ✅ ▶️ View recording
✅ DeployK8sWithValkey ✅ ▶️ View recording
✅ DeployTypeScriptAppToKubernetes ✅ ▶️ View recording
✅ DescribeCommandResolvesReplicaNames ✅ ▶️ View recording
✅ DescribeCommandShowsRunningResources ✅ ▶️ View recording
✅ DetachFormatJsonProducesValidJson ✅ ▶️ View recording
✅ DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ✅ ▶️ View recording
✅ DoListStepsShowsPipelineSteps ✅ ▶️ View recording
✅ DocsCommand_RendersInteractiveMarkdownFromLocalSource ✅ ▶️ View recording
✅ DoctorCommand_DetectsDeprecatedAgentConfig ✅ ▶️ View recording
✅ DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ✅ ▶️ View recording
✅ DoctorCommand_WithSslCertDir_ShowsTrusted ✅ ▶️ View recording
✅ DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ✅ ▶️ View recording
✅ GeneratedAspireDevScript_StartsWatchMode_WithConfiguredToolchain ✅ ▶️ View recording
✅ GlobalMigration_HandlesCommentsAndTrailingCommas ✅ ▶️ View recording
✅ GlobalMigration_HandlesMalformedLegacyJson ✅ ▶️ View recording
✅ GlobalMigration_PreservesAllValueTypes ✅ ▶️ View recording
✅ GlobalMigration_SkipsWhenNewConfigExists ✅ ▶️ View recording
✅ GlobalSettings_MigratedFromLegacyFormat ✅ ▶️ View recording
✅ InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ✅ ▶️ View recording
✅ InteractiveCSharpInitCreatesExpectedFiles ✅ ▶️ View recording
✅ InvalidAppHostPathWithComments_IsHealedOnRun ✅ ▶️ View recording
✅ JavaScriptHostingApisRunFromTypeScriptAppHost ✅ ▶️ View recording
✅ LatestCliCanStartStableChannelAppHost ✅ ▶️ View recording
✅ LatestCliCanStartStableChannelTypeScriptAppHost ✅ ▶️ View recording
✅ LegacySettingsMigration_AdjustsRelativeAppHostPath ✅ ▶️ View recording
✅ LogLevelTrace_ProducesTraceEntriesInCliLogFile ✅ ▶️ View recording
✅ LogsCommandShowsResourceLogs ✅ ▶️ View recording
✅ OtelLogsReturnsStructuredLogsFromStarterApp ✅ ▶️ View recording
✅ OtelLogsReturnsStructuredLogsFromStarterAppIsolated ✅ ▶️ View recording
✅ PsCommandListsRunningAppHost ✅ ▶️ View recording
✅ PsFormatJsonOutputsOnlyJsonToStdout ✅ ▶️ View recording
✅ PublishJavaScriptPatternsGeneratesExpectedDockerComposeArtifacts ✅ ▶️ View recording
✅ PublishWithConfigureEnvFileUpdatesEnvOutput ✅ ▶️ View recording
✅ PublishWithDockerComposeServiceCallbackSucceeds ✅ ▶️ View recording
✅ PublishWithoutOutputPathUsesAppHostDirectoryDefault ✅ ▶️ View recording
✅ ResourceCommand_FailedExecution_DisplaysAppHostLogPathAndLogContainsEntries ✅ ▶️ View recording
✅ ResourceCommand_FailsWhenInteractionServiceIsRequired ✅ ▶️ View recording
✅ ResourceCommand_SetAndDeleteParameterUpdatesDescribeOutput ✅ ▶️ View recording
✅ RestoreGeneratesSdkFiles ✅ ▶️ View recording
✅ RestoreGeneratesSdkFiles_WithConfiguredToolchain ✅ ▶️ View recording
✅ RestoreRefreshesGeneratedSdkAfterAddingIntegration ✅ ▶️ View recording
✅ RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ✅ ▶️ View recording
✅ RunFromParentDirectory_UsesExistingConfigNearAppHost ✅ ▶️ View recording
❔ RunPublishFailureScenarioAsync ❔ ▶️ View recording
✅ RunReportsSyntaxErrorsForDotNetAppHost ✅ ▶️ View recording
✅ RunReportsSyntaxErrorsForTypeScriptAppHost ✅ ▶️ View recording
✅ SecretCrudOnDotNetAppHost ✅ ▶️ View recording
✅ SecretCrudOnTypeScriptAppHost ✅ ▶️ View recording
✅ StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ✅ ▶️ View recording
✅ StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ✅ ▶️ View recording
✅ StartReportsSyntaxErrorsForDotNetAppHost ✅ ▶️ View recording
✅ StartReportsSyntaxErrorsForTypeScriptAppHost ✅ ▶️ View recording
✅ StopAllAppHostsFromAppHostDirectory ✅ ▶️ View recording
✅ StopJavaPolyglotAppHostUsingApphostDirectory ✅ ▶️ View recording
✅ StopNonInteractiveSingleAppHost ✅ ▶️ View recording
✅ StopTypeScriptPolyglotAppHostUsingApphostDirectory ✅ ▶️ View recording
✅ StopWithNoRunningAppHostExitsSuccessfully ✅ ▶️ View recording
✅ UnAwaitedChainsCompileWithAutoResolvePromises ✅ ▶️ View recording
✅ UpdateProjectChannelToStable_TypeScript_PicksUpStablePackages ✅ ▶️ View recording

📹 Recordings uploaded automatically from CI run #26303155864

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

Documentation was authored for ITokenCredentialProvider (triggered signals: new_public_type — +public interface ITokenCredentialProvider in ITokenCredentialProvider.cs; pr_body_has_user_facing_section — PR body contains ### User-facing usage section) but the draft PR could not be created due to a workspace misconfiguration: $GITHUB_WORKSPACE points to microsoft/aspire rather than microsoft/aspire.dev, so the create_pull_request tool could not locate the committed changes in _repos/aspire.dev. A new section "Accessing the provisioning credential" was prepared for src/frontend/src/content/docs/integrations/cloud/azure/local-provisioning.mdx on branch docs/itokencredentialprovider-public-api in the local _repos/aspire.dev checkout. A maintainer can open the docs PR manually.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants