EntraIdResourceExtensions Methods
AddEntraIdApplication(IDistributedApplicationBuilder, string) Section titled AddEntraIdApplication(IDistributedApplicationBuilder, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> AddEntraIdApplication( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder .namestringThe name of the resource.Returns
IResourceBuilder<EntraIdApplicationResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
The Entra ID application resource injects configuration as environment variables into consuming services. For .NET programs, the variables default to the Azure configuration section that Microsoft.Identity.Web reads natively.
By default, Aspire provisions an application and service principal using the Microsoft Graph Bicep extension. This requires Azure provisioning configuration and permission to create registrations in the subscription's tenant. Call Add to reference an existing registration without Azure or Graph access.
var builder = DistributedApplication.CreateBuilder(args);
var entraApi = builder.AddEntraIdApplication("entra-api");
builder.AddDotnetProject("api", "../Api/Api.csproj") .WithReference(entraApi);AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>) Section titled AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> AddExistingEntraIdApplication( this IDistributedApplicationBuilder builder, string name, IResourceBuilder<ParameterResource> tenantId, IResourceBuilder<ParameterResource> clientId) { // ... }}Parameters
builderIDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder .namestringThe name of the resource.tenantId IResourceBuilder<ParameterResource> A parameter containing the ID of the app's home tenant: the directory where the app is registered, shown as "Directory (tenant) ID" on the app registration's Overview page. clientId IResourceBuilder<ParameterResource> A parameter containing the application (client) ID, shown as "Application (client) ID" on the app registration's Overview page. Returns
IResourceBuilder<EntraIdApplicationResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
Both the tenant ID and client ID are required to identify an existing Entra ID application. Unlike ARM resources that can be identified by name and resource group, Entra ID app registrations live in a specific tenant directory and are uniquely identified by their client ID within that tenant.
The parameter values are validated when the application starts. The tenant ID must be a GUID or a domain such as contoso., and the client ID must be a GUID. When a value is missing or malformed, the resource reports Failed and logs the reason.
The registration is used only for configuration. Aspire does not deploy Bicep or query Microsoft Graph for this resource. Use Entra to create a registration instead.
var tenantId = builder.AddParameter("EntraTenantId");var clientId = builder.AddParameter("EntraClientId");var identity = builder.AddExistingEntraIdApplication( "identity", tenantId, clientId);builder.AddDotnetProject("api", "../Api/Api.csproj").WithReference(identity);AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, string, string) Section titled AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, string, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> AddExistingEntraIdApplication( this IDistributedApplicationBuilder builder, string name, string tenantId, string clientId) { // ... }}Parameters
builderIDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder .namestringThe name of the resource.tenantId string The ID of the app's home tenant: the directory where the app is registered, shown as "Directory (tenant) ID" on the app registration's Overview page. A domain such as contoso.onmicrosoft.com is also accepted. clientId string The application (client) ID, shown as "Application (client) ID" on the app registration's Overview page. Returns
IResourceBuilder<EntraIdApplicationResource> A reference to the ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentException Thrown when tenantId is empty, is not a GUID or domain name, or is one of the sign-in audience keywords organizations, common or consumers; or when clientId is empty or is not a GUID. Remarks
Both the tenant ID and client ID are required to identify an existing Entra ID application. Unlike ARM resources that can be identified by name and resource group, Entra ID app registrations live in a specific tenant directory and are uniquely identified by their client ID within that tenant.
To let accounts from other tenants sign in, keep the home tenant here and call Entra.
The registration is used only for configuration. Aspire does not deploy Bicep or query Microsoft Graph for this resource. Use Entra to create a registration instead.
var identity = builder.AddExistingEntraIdApplication( "identity", tenantId: "aaaabbbb-0000-cccc-1111-dddd2222eeee", clientId: "00001111-aaaa-2222-bbbb-3333cccc4444");builder.AddDotnetProject("api", "../Api/Api.csproj").WithReference(identity);AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>) Section titled AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> AsExistingApplication( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<ParameterResource> tenantId, IResourceBuilder<ParameterResource> clientId) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.tenantId IResourceBuilder<ParameterResource> A parameter containing the registration's home tenant ID.clientId IResourceBuilder<ParameterResource> A parameter containing the registration's application (client) ID.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionRegistration-only configuration is already applied to this resource.Remarks
Parameter values are validated when the application starts. The tenant ID must be a GUID or a domain such as contoso., and the client ID must be a GUID.
Entra enables Azure provisioning before this method is called. This method does not disable that setup, so deployment can still require Azure authentication and provisioning configuration. To reference an existing registration without enabling Azure provisioning, use Entra.
var identity = builder.AddEntraIdApplication("identity") .AsExistingApplication( builder.AddParameter("TenantId"), builder.AddParameter("ClientId"));AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, string, string) Section titled AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> AsExistingApplication( this IResourceBuilder<EntraIdApplicationResource> builder, string tenantId, string clientId) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.tenantId stringThe registration's home tenant ID, as a GUID or a domain such as contoso.onmicrosoft.com .clientId stringThe registration's application (client) ID.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentExceptionA tenant ID or client ID is empty or invalid.InvalidOperationExceptionRegistration-only configuration is already applied to this resource.Remarks
Pass the home tenant ID, not a sign-in keyword such as organizations. Use Entra to allow accounts from other tenants to sign in.
Entra enables Azure provisioning before this method is called. This method does not disable that setup, so deployment can still require Azure authentication and provisioning configuration. To reference an existing registration without enabling Azure provisioning, use Entra.
var identity = builder.AddEntraIdApplication("identity") .AsExistingApplication( tenantId: "aaaabbbb-0000-cccc-1111-dddd2222eeee", clientId: "00001111-aaaa-2222-bbbb-3333cccc4444");PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>, string[]) Section titled PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> PublishWithAppRoleAssignment( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<AzureUserAssignedIdentityResource> identity, params string[] roleValues) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The API registration builder.identityIResourceBuilder<AzureUserAssignedIdentityResource> The managed identity receiving the roles. Workloads attach it with WithAzureUserAssignedIdentity .roleValues string[]The values of enabled roles declared with WithAppRole that allow Application members.Returns
IResourceBuilder<EntraIdApplicationResource> The API registration builder for chaining.Exceptions
ArgumentNullExceptionThrown when an argument is null.ArgumentExceptionThrown when no roles are supplied or a role is unknown, disabled, or does not allow application members.InvalidOperationExceptionThrown when the API references an existing registration.Remarks
This explicitly grants access to the identity's service-principal object ID, not its client ID. The caller authenticates directly as its managed identity; no caller registration or federated credential is created. This does not attach the identity to a workload or configure its token acquisition. The API must validate tokens and enforce the required role.
Assignments are published only; this has no effect during local run. Removing this call does not revoke a deployed assignment: remove it explicitly with Microsoft Graph or the Entra admin center. Already-issued tokens remain valid until expiration, and managed-identity token caches can delay revocation.
Deployment requires the Microsoft Graph permissions App and Application. (or a higher permission covering application reads), with administrator consent. Delegated deployments also need a supported Entra directory role. Azure RBAC permissions alone do not authorize directory assignments. See https://learn.microsoft.com/graph/api/serviceprincipal-post-approleassignedto.
Examples
var identity = builder.AddAzureUserAssignedIdentity("worker-identity");var apiRegistration = builder.AddEntraIdApplication("orders-api") .WithApplicationIdUri() .WithAppRole(new EntraIdAppRole("Orders.Read", "Read orders", "Read orders.", ["Application"])) .PublishWithAppRoleAssignment(identity, "Orders.Read");var api = builder.AddDotnetProject("api", "../Api/Api.csproj") .WithReference(apiRegistration);PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>, string[]) Section titled PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> PublishWithAppRoleAssignment<T>( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<T> computeResource, params string[] roleValues) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The API registration builder.computeResource IResourceBuilder<T> The compute resource whose managed identity receives the roles.roleValues string[]The values of enabled roles declared with WithAppRole that allow Application members.Returns
IResourceBuilder<EntraIdApplicationResource> The API registration builder for chaining.Exceptions
ArgumentNullExceptionThrown when an argument is null.ArgumentExceptionThrown when no roles are supplied or a role is unknown, disabled, or does not allow application members.InvalidOperationExceptionThrown when the API references an existing registration or the published compute resource has no user-assigned managed identity.Remarks
Examples
var worker = builder.AddDotnetProject("worker", "../Worker/Worker.csproj");var apiRegistration = builder.AddEntraIdApplication("orders-api") .WithApplicationIdUri() .WithAppRole(new EntraIdAppRole("Orders.Read", "Read orders", "Read orders.", ["Application"]));var api = builder.AddDotnetProject("api", "../Api/Api.csproj") .WithReference(apiRegistration);
apiRegistration.PublishWithAppRoleAssignment(worker, "Orders.Read");PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>) Section titled PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential( this IResourceBuilder<EntraIdApplicationResource> builder) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Remarks
A single call covers every resource that references this application, including resources that reference it after this call, and the application trusts each resource's own identity. Use Entra to trust a single resource instead. The method adds one credential entry to the application's configuration, and Aspire creates one federated identity credential on the registration for each trusted identity.
Every resource that references this application with With is given a managed identity when published, and the application trusts it. The identity is the one the resource already has, for example from With or because it references other Azure resources; otherwise the Azure environment creates one. For an application that Aspire creates, Aspire adds a federated identity credential to the registration for each identity: the issuer is the tenant's v2.0 endpoint, the subject is the identity's object (principal) ID, and the audience is the token exchange audience of the application's cloud. The resource receives the identity's client ID as Managed.
This is only for registrations that Aspire creates. For an existing registration ( Add), which Aspire never modifies, this method throws; use Entra instead.
Managed identities exist only in Azure, so the credential is not used when running locally. Add another credential, such as a client secret, for local development. Supported clouds are Azure public, Azure US Government and Azure China. Only user-assigned managed identities are supported. See https://learn.microsoft.com/entra/workload-id/workload-identity-federation-config-app-trust-managed-identity.
Examples
var entra = builder.AddEntraIdApplication("entra-web") .PublishWithFederatedManagedIdentityCredential();
builder.AddDotnetProject("web", "../Web/Web.csproj") .WithReference(entra);PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>) Section titled PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential<T>( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<T> computeResource) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.computeResource IResourceBuilder<T> The compute resource to trust. It must reference this application with WithReference . Only this resource receives the managed identity credential. Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationException Thrown when the registration is existing or computeResource does not reference this application. Remarks
computeResource 's identity is trusted, and only it receives the managed identity credential. The resource's identity is resolved after the Azure environment has prepared it, as described in EntraIdResourceExtensions.PublishWithFederatedManagedIdentityCredential . Examples
var entra = builder.AddEntraIdApplication("entra-web");var web = builder.AddDotnetProject("web", "../Web/Web.csproj") .WithReference(entra);
entra.PublishWithFederatedManagedIdentityCredential(web);PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>) Section titled PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<AzureUserAssignedIdentityResource> identity) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.identityIResourceBuilder<AzureUserAssignedIdentityResource> The user-assigned managed identity to trust. Every resource that references this application must use it, for example with WithAzureUserAssignedIdentity . Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Remarks
Examples
var identity = builder.AddAzureUserAssignedIdentity("web-identity");var entra = builder.AddEntraIdApplication("entra-web") .PublishWithFederatedManagedIdentityCredential(identity);
builder.AddDotnetProject("web", "../Web/Web.csproj") .WithAzureUserAssignedIdentity(identity) .WithReference(entra);RunWithLocalDeveloperCertificateCredential(IResourceBuilder<EntraIdApplicationResource>) Section titled RunWithLocalDeveloperCertificateCredential(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> RunWithLocalDeveloperCertificateCredential( this IResourceBuilder<EntraIdApplicationResource> builder) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is an existing application, which Aspire never modifies.Remarks
Each application gets a dedicated certificate in the AppHost's local store. Certificates last two days; on a subsequent run, a certificate with one day or less remaining is replaced by overwriting its PFX file. Only the public certificate is provisioned in Entra. Referencing applications receive the private credential as a secret Base64 in Microsoft.Identity.Web's Client configuration. Aspire replaces the registration's entire key collection with the selected certificate. Existing certificate credentials are not retained, so older sessions must restart after renewal.
Development and production must use separate Entra registrations. Never register developer certificates on a production application. Different resource groups do not isolate tenant-scoped registrations: use distinct registration names or tenant-resource suffixes. This method does not provision or emit a credential when publishing; omitting a credential from publish does not revoke a key previously registered against the same application. In either mode, this configuration prevents conversion to an existing registration with As.
Renewal is checked at AppHost startup, not in the background. Restart long-running development sessions before the certificate expires. Use Publish for deployed workloads.
Examples
// Use different Azure:TenantResourceSuffix values for development and production.var entra = builder.AddEntraIdApplication("entra-web") .RunWithLocalDeveloperCertificateCredential() .PublishWithFederatedManagedIdentityCredential();
builder.AddDotnetProject("web", "../Web/Web.csproj").WithReference(entra);WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithAdminConsent( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<EntraIdApplicationResource> api, params string[] scopeNames) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The calling registration, which must be created by Aspire.apiIResourceBuilder<EntraIdApplicationResource> The registration that exposes the scopes.scopeNames string[]The names of scopes already declared with EntraIdResourceExtensions.WithApiPermissions .Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentExceptionA scope is not exposed or is disabled, or no scope was given.InvalidOperationExceptionThe calling registration is existing, or a scope was not declared first.Remarks
This creates a delegated permission grant for all users ( consent) from this registration to api, so nobody is prompted to consent. The identity that deploys needs a directory role such as Privileged Role Administrator, Cloud Application Administrator or Application Administrator, or a privileged Microsoft Graph permission such as Delegated. Deployment fails without it. See https://learn.microsoft.com/entra/identity/enterprise-apps/grant-admin-consent#prerequisites.
A grant is neither a declaration nor a pre-authorization. Throws for an existing caller; grant its consent manually in the Microsoft Entra admin center. A created caller may consent to an existing API.
The grant is declared in full: it is set to exactly the scopes passed to With for this registration and api. A scope that was granted to the pair outside Aspire, or that is removed from the calls while others remain, is revoked by the next deployment. When no call remains for the pair, nothing is sent and the existing grant stays.
WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[]) Section titled WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithAdminConsent( this IResourceBuilder<EntraIdApplicationResource> builder, EntraIdApi api, params EntraIdApiPermission[] permissions) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The calling registration, which must be created by Aspire.apiEntraEntraIdApi.MicrosoftGraph .permissionsEntraIdApiPermission[] Permissions already declared with EntraIdResourceExtensions.WithApiPermissions .Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe calling registration is existing, or a permission was not declared first.Remarks
A delegated permission becomes a delegated permission grant for all users ( consent). An application permission becomes an app role assignment to this registration's service principal, so the application can call the API as itself without a user.
The delegated grant is declared in full: it is set to exactly the delegated permissions passed to With for this registration and api. A permission that was granted to the pair outside Aspire, or that is removed from the calls while others remain, is revoked by the next deployment. When no delegated call remains for the pair, nothing is sent and the existing grant stays. Each application permission is a separate app role assignment: Aspire creates it, but doesn't delete it when its consent is removed from the AppHost, so remove it in the Microsoft Entra admin center.
The identity that deploys needs one of the following, and deployment fails without it. For delegated permissions, a directory role such as Privileged Role Administrator, Cloud Application Administrator or Application Administrator, or the Delegated Microsoft Graph permission. For Microsoft Graph application permissions, Cloud Application Administrator and Application Administrator are not enough: use Privileged Role Administrator or a custom role, or the App Microsoft Graph permission when deploying as an application. See https://learn.microsoft.com/entra/identity/enterprise-apps/grant-admin-consent#prerequisites. Application permissions to broad scopes such as Directory. give the application access to the whole tenant, so grant only what the application needs. Throws for an existing caller; grant its consent manually in the Microsoft Entra admin center.
var entraWeb = builder.AddEntraIdApplication("entra-web") .WithApiPermissions( EntraIdApi.MicrosoftGraph, EntraIdApiPermission.Application("User.Read.All")) .WithAdminConsent( EntraIdApi.MicrosoftGraph, EntraIdApiPermission.Application("User.Read.All"));WithAllowWebApiToBeAuthorizedByACL(IResourceBuilder<EntraIdApplicationResource>) Section titled WithAllowWebApiToBeAuthorizedByACL(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithAllowWebApiToBeAuthorizedByACL( this IResourceBuilder<EntraIdApplicationResource> builder) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithApiPermissions( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<EntraIdApplicationResource> api, params string[] scopeNames) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The calling registration.apiIResourceBuilder<EntraIdApplicationResource> The registration that exposes the scopes.scopeNames string[]The names of the scopes, added with EntraIdResourceExtensions.WithScope to api.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentExceptionA scope is not exposed or is disabled, or no scope was given.InvalidOperationExceptionapi already pre-authorizes this registration, or depends on it in another way. See EntraIdResourceExtensions.WithPreAuthorizedApplication . Remarks
This adds the scopes to the registration's API permissions, the list shown in the portal. It grants nothing: users are prompted to consent the first time they sign in unless an administrator consents ( Entra) or api pre-authorizes the caller ( Entra).
A token request can cover the scopes of only one API. Request the scopes of each API in a separate token request. For an existing caller, only consumer DownstreamApis configuration is emitted; configure its API permissions manually.
var entraApi = builder.AddEntraIdApplication("entra-api") .WithScope( "access_as_user", "Allows the app to call the API on behalf of the signed-in user.");
var entraWeb = builder.AddEntraIdApplication("entra-web") .WithApiPermissions(entraApi, "access_as_user");WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[]) Section titled WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithApiPermissions( this IResourceBuilder<EntraIdApplicationResource> builder, EntraIdApi api, params EntraIdApiPermission[] permissions) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The calling registration.apiEntraEntraIdApi.MicrosoftGraph .permissionsEntraIdApiPermission[] The permissions to require.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentExceptionA permission is unknown for the API and has no ID, or no permission was given.Remarks
This adds the permissions to the registration's API permissions, the list shown in the portal. It grants nothing, and it does not grant tenant-wide consent as a side effect. Use Entra to opt in to consent. For an existing caller, only consumer DownstreamApis configuration is emitted; configure its API permissions manually.
Delegated permissions ( Entra) let the application act for a signed-in user. Application permissions ( Entra) let it act as itself and always need an administrator's consent. The two kinds are separate permissions, even when they have the same name.
var entraWeb = builder.AddEntraIdApplication("entra-web") .WithApiPermissions( EntraIdApi.MicrosoftGraph, EntraIdApiPermission.Delegated("User.Read"));WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>) Section titled WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource> api://{clientId} . public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithApplicationIdUri( this IResourceBuilder<EntraIdApplicationResource> builder) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Supply its registered URI explicitly instead.Remarks
The client ID exists only after Microsoft Graph creates the registration, so the URI is set by a second update of the registration in the same deployment. api: contains the application ID, a form that the tenant's default identifier URI policy accepts, so it needs no verified domain. Adding a scope with Entra uses this URI unless Entra sets another one.
This setting only affects registrations created by Aspire. For an existing registration, call Entra with the URI it already has.
WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>, string) Section titled WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithApplicationIdUri( this IResourceBuilder<EntraIdApplicationResource> builder, string applicationIdUri) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.applicationIdUri stringThe URI, such as api://contoso-orders or https://contoso.onmicrosoft.com/orders .Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentExceptionapplicationIdUri is not an absolute URI without a query string or fragment.Remarks
For a registration created by Aspire, the URI is written to the registration. The URI must be unique in the tenant. A tenant's default policy requires a new URI to contain a verified domain, the tenant ID or the application ID, but it doesn't apply when the registration's requested is 2, which Aspire always sets, so a name such as api: is normally accepted. A tenant can configure a stricter policy, and a deployment fails when the policy rejects the URI. See https://aka.ms/identifier-uri-formatting-error.
For an existing registration, the URI is only configuration: Aspire does not modify the registration, and Entra uses the URI to build scope names for callers.
WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithApplicationOwners( this IResourceBuilder<EntraIdApplicationResource> builder, params string[] ownerObjectIds) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.ownerObjectIds string[]The object IDs (GUIDs) of the Microsoft Entra users or service principals to add as owners.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its owners manually.ArgumentNullExceptionThrown when builder or ownerObjectIds is null.ArgumentExceptionThrown when an owner ID is not a GUID.Remarks
Owners can manage the application registration, so grant ownership deliberately. By default, Aspire sets no owners and Microsoft Entra's default ownership behavior applies. The owners are not necessarily the identity that runs the deployment.
Owners are added with append semantics: existing owners are never removed. The deploying identity needs permission to manage application owners (for example the Application. Microsoft Graph permission or a directory role such as Application Administrator).
Application and service principal ownership are separate; use Entra for the enterprise application. Throws for existing registrations; configure their owners manually in the Microsoft Entra admin center.
Examples
var entraApi = builder.AddEntraIdApplication("entra-api") .WithApplicationOwners("00000000-0000-0000-0000-000000000001");WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>) Section titled WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithApplicationOwners( this IResourceBuilder<EntraIdApplicationResource> builder, params IResourceBuilder<ParameterResource>[] ownerObjectIds) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.ownerObjectIds IResourceBuilder<ParameterResource> Parameters whose values are the object IDs of the users or service principals to add as owners.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its owners manually.ArgumentNullExceptionThrown when builder or ownerObjectIds is null.Remarks
EntraIdResourceExtensions.WithApplicationOwners for permission and append semantics. WithAppRole(IResourceBuilder<EntraIdApplicationResource>, EntraIdAppRole) Section titled WithAppRole(IResourceBuilder<EntraIdApplicationResource>, EntraIdAppRole)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithAppRole( this IResourceBuilder<EntraIdApplicationResource> builder, EntraIdAppRole role) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.roleEntraReturns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentNullExceptionThrown when builder or role is null.ArgumentExceptionThrown when a role with the same value or ID is already declared.InvalidOperationExceptionThrown when the resource references an existing registration.Remarks
Application roles are different from delegated scopes and from Azure RBAC roles. This only declares the role; it does not assign it to any user, group, or application, and it does not grant consent.
Role IDs stay the same across deployments. Changing a role's value, or its ID, creates a different role in the directory; assignments of the previous role are not migrated.
Whenever at least one role is declared, the complete app collection is sent and Microsoft Graph replaces what is stored. Include every role to keep, including roles that were added outside the AppHost: a role that is left out fails the deployment if it is still enabled and is deleted if it is already disabled.
Existing registrations are never modified, so this method cannot be used with Add.
Examples
var entraApi = builder.AddEntraIdApplication("entra-api") .WithAppRole(new EntraIdAppRole("User", "User", "Can use the API.")) .WithAppRole(new EntraIdAppRole("Admin", "Administrator", "Can administer the API.", ["User", "Application"]));WithAudience(IResourceBuilder<EntraIdApplicationResource>, string) Section titled WithAudience(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithAudience( this IResourceBuilder<EntraIdApplicationResource> builder, string audience) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.audiencestringThe audience value (e.g., api://<client-id> ).Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Remarks
WithCertificateDistinguishedName(IResourceBuilder<EntraIdApplicationResource>, string, string) Section titled WithCertificateDistinguishedName(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithCertificateDistinguishedName( this IResourceBuilder<EntraIdApplicationResource> builder, string storePath, string distinguishedName) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.storePath stringThe certificate store path (e.g., "CurrentUser/My" ).distinguishedName stringThe certificate distinguished name (e.g., "CN=MyCert" ).Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, string, string) Section titled WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithCertificateFromKeyVault( this IResourceBuilder<EntraIdApplicationResource> builder, string keyVaultUrl, string certificateName) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.keyVaultUrl stringThe URL of the Key Vault (e.g., "https://myvault.vault.azure.net" ).certificateName stringThe name of the certificate in Key Vault.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureKeyVaultResource>, string) Section titled WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureKeyVaultResource>, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithCertificateFromKeyVault( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<AzureKeyVaultResource> keyVault, string certificateName) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.keyVault IResourceBuilder<AzureKeyVaultResource> The Key Vault containing the certificate.certificateName stringThe name of the certificate in Key Vault.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentNullExceptionThrown when builder or keyVault is null.ArgumentExceptionThrown when certificateName is null or empty.Remarks
Examples
var vault = builder.AddAzureKeyVault("vault");var entra = builder.AddExistingEntraIdApplication("entra", tenantId, clientId) .WithCertificateFromKeyVault(vault, "web-certificate");builder.AddProject<Projects.Web>("web").WithReference(entra);WithCertificateThumbprint(IResourceBuilder<EntraIdApplicationResource>, string, string) Section titled WithCertificateThumbprint(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithCertificateThumbprint( this IResourceBuilder<EntraIdApplicationResource> builder, string storePath, string thumbprint) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.storePath stringThe certificate store path (e.g., "CurrentUser/My" ).thumbprintstringThe certificate thumbprint.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithClientCapability(IResourceBuilder<EntraIdApplicationResource>, string) Section titled WithClientCapability(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource> "cp1" for Continuous Access Evaluation). public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithClientCapability( this IResourceBuilder<EntraIdApplicationResource> builder, string capability) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.capabilitystringThe capability identifier.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithClientSecret(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>) Section titled WithClientSecret(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithClientSecret( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<ParameterResource> clientSecret) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.clientSecret IResourceBuilder<ParameterResource> A secret parameter containing the client secret.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentException Thrown when clientSecret is not marked as a secret parameter. Remarks
This adds an entry to the Client array in the Microsoft.Identity.Web configuration with Source set to "Client.
WithCredential(IResourceBuilder<EntraIdApplicationResource>, EntraIdClientCredential) Section titled WithCredential(IResourceBuilder<EntraIdApplicationResource>, EntraIdClientCredential)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithCredential( this IResourceBuilder<EntraIdApplicationResource> builder, EntraIdClientCredential credential) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.credentialEntraEntraIdClientCredential .Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithExtraQueryParameter(IResourceBuilder<EntraIdApplicationResource>, string, string) Section titled WithExtraQueryParameter(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithExtraQueryParameter( this IResourceBuilder<EntraIdApplicationResource> builder, string key, string value) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.keystringThe query parameter key.valuestringThe query parameter value.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.WithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, string) Section titled WithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithFederatedManagedIdentityCredential( this IResourceBuilder<EntraIdApplicationResource> builder, string managedIdentityClientId) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.managedIdentityClientId string The client ID of the user-assigned managed identity that the consuming app runs as. This is not the identity's object (principal) ID or its Azure resource ID. Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentException Thrown when managedIdentityClientId is empty or is not a GUID. Remarks
This only configures the consuming app: it adds a Signed entry to the Client array of the Microsoft.Identity.Web configuration. Aspire does not create or assign the managed identity, and does not add a federated identity credential to the registration. It applies in run mode as well as when publishing.
Use this method for an existing registration ( Add), which Aspire never modifies, or for a managed identity that Aspire does not manage. Before the app can get a token, the registration must already trust the identity: add a federated identity credential to it whose issuer is the tenant's v2.0 endpoint ( https: in the Azure public cloud), whose subject is the identity's object (principal) ID, and whose audience is the token exchange audience of the cloud ( api: in the Azure public cloud). Otherwise, token requests fail with AADSTS700213.
For a registration that Aspire creates, use Entra instead, which also creates the trust. Only user-assigned managed identities are supported. See https://learn.microsoft.com/entra/workload-id/workload-identity-federation-config-app-trust-managed-identity.
Examples
var entraWeb = builder.AddExistingEntraIdApplication("entra-web", tenantId, clientId) .WithFederatedManagedIdentityCredential("00001111-aaaa-2222-bbbb-3333cccc4444");WithIdTokenIssuance(IResourceBuilder<EntraIdApplicationResource>) Section titled WithIdTokenIssuance(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithIdTokenIssuance( this IResourceBuilder<EntraIdApplicationResource> builder) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its ID-token issuance manually.ArgumentNullExceptionThrown when builder is null.Remarks
ID-token issuance through implicit and hybrid flows is disabled by default. Enable it when the application's OpenID Connect sign-in flow requests an ID token directly from the authorization endpoint. This does not enable implicit access-token issuance and is not required for authorization-code-only flows. For new production applications, prefer authorization code flow with PKCE.
Throws for existing registrations, which Aspire does not modify; enable "ID tokens (used for implicit and hybrid flows)" in their Authentication settings instead.
var entraWeb = builder.AddEntraIdApplication("entra-web") .WithIdTokenIssuance() .WithRedirectUris("https://localhost:7123/signin-oidc");WithInstance(IResourceBuilder<EntraIdApplicationResource>, string) Section titled WithInstance(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource> https://login.microsoftonline.com/ . public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithInstance( this IResourceBuilder<EntraIdApplicationResource> builder, string instance) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.instancestring The Entra ID instance URL, such as https://login.microsoftonline.us/ for Azure Government or https://contoso.ciamlogin.com/ for an external tenant. Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentException Thrown when instance is empty or is not an absolute HTTPS URL without a query string or fragment. WithOwners(IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithOwners(IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithOwners( this IResourceBuilder<EntraIdApplicationResource> builder, params string[] ownerObjectIds) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.ownerObjectIds string[]The object IDs (GUIDs) of the Microsoft Entra users or service principals to add as owners.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its owners manually.Remarks
EntraIdResourceExtensions.WithApplicationOwners and EntraIdResourceExtensions.WithServicePrincipalOwners with the same IDs. WithOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>) Section titled WithOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithOwners( this IResourceBuilder<EntraIdApplicationResource> builder, params IResourceBuilder<ParameterResource>[] ownerObjectIds) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.ownerObjectIds IResourceBuilder<ParameterResource> Parameters whose values are the object IDs of the users or service principals to add as owners.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its owners manually.WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithPreAuthorizedApplication( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<EntraIdApplicationResource> client, params string[] scopeNames) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The registration that exposes the scopes, which must be created by Aspire.clientIResourceBuilder<EntraIdApplicationResource> The client application to pre-authorize.scopeNames string[]The names of the scopes, added with EntraIdResourceExtensions.WithScope , that the client may request.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentExceptionA scope is not exposed or is disabled, or no scope was given.InvalidOperationException The receiving registration is existing, or client already declares permissions for this registration, or depends on it in another way. Pre-authorization needs the client's ID and a declaration needs this registration's ID, so each registration would wait for the other. Remarks
Pre-authorization is separate from the client's declaration of the permission ( Entra) and from consent ( Entra). It lets a trusted client skip the consent prompt, which is intended for first-party clients of the same organization.
Aspire deploys each registration as its own module. Pre-authorization makes this registration wait for the client's ID, while the client's declaration waits for this registration's ID, so two registrations cannot use both. Use a declaration with With on the client, or pre-authorization alone. Throws if this API registration is existing; configure its pre-authorized clients manually. An existing client can still be pre-authorized by a registration Aspire creates.
WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris( this IResourceBuilder<EntraIdApplicationResource> builder, params string[] redirectUris) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.redirectUris string[]The redirect URIs to register for browser sign-in and sign-out callbacks.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its redirect URIs manually.ArgumentNullExceptionThrown when builder or redirectUris is null.ArgumentExceptionThrown when a redirect URI is empty.Remarks
Examples
var entraWeb = builder.AddEntraIdApplication("entra-web") .WithRedirectUris("https://localhost:7123/signin-oidc");WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>) Section titled WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris( this IResourceBuilder<EntraIdApplicationResource> builder, params IResourceBuilder<ParameterResource>[] redirectUris) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.redirectUris IResourceBuilder<ParameterResource> Parameters whose values are the redirect URIs. Each value may contain several URIs separated by commas.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its redirect URIs manually.ArgumentNullExceptionThrown when builder, redirectUris , or one of its elements is null.Remarks
Use this overload when the externally visible callback URIs (for example, behind a gateway, reverse proxy, or custom domain) are supplied per environment at deployment time. The values are split on commas in the generated infrastructure, so a URI supplied through a parameter can't contain a comma and entries must not have surrounding whitespace. Literal URIs can be mixed with parameter-backed URIs by also calling Entra; URIs are registered in call order.
Endpoints are not discovered automatically. Throws for existing registrations; configure their redirect URIs manually.
Examples
var signIn = builder.AddParameter("web-signin-redirect-uri");var signOut = builder.AddParameter("web-signout-redirect-uri");var entraWeb = builder.AddEntraIdApplication("entra-web") .WithRedirectUris(signIn, signOut);WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, EndpointReference, string[]) Section titled WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, EndpointReference, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris( this IResourceBuilder<EntraIdApplicationResource> builder, EndpointReference endpoint, params string[] callbackPaths) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.endpointEndpointReference The endpoint that serves the callbacks.callbackPaths string[]The callback paths on that endpoint, such as /signin-oidc .Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing, or infrastructure generation detects that TLS is disabled for the deployed endpoint.ArgumentNullExceptionThrown when an argument is null.ArgumentExceptionThrown when no path is provided or a path doesn't start with /.Remarks
In run mode the origin comes from the endpoint's finalized browser URLs, including vanity hostnames and URL customization. When publishing or deploying, the origin comes from the resource's compute environment, and the deployed endpoint must have TLS enabled. After endpoint allocation, resolution waits up to 30 seconds for finalized browser URLs. If they are not ready, the allocated origin is used with a warning. Supply explicit redirect URIs if that address differs from the browser URL.
The callback path can't be discovered from the endpoint: it's configured by the consuming application, so it is supplied here and must match that configuration. When the externally visible URL differs from the endpoint (gateway, reverse proxy, or custom domain), supply the full URL with With instead. Throws for existing registrations; configure their redirect URIs manually.
Run-mode resolution waits for all URL customization callbacks to complete and uses the shared browser-origin preference order. Navigation paths are excluded before appending the supplied callback path. If URL customization removes all browser URLs for the endpoint, resolution reports a missing origin.
Examples
var web = builder.AddDotnetProject("web", "../Web/Web.csproj").WithExternalHttpEndpoints();var entraWeb = builder.AddEntraIdApplication("entra-web") .WithRedirectUris(web.GetEndpoint("https"), "/signin-oidc", "/signout-callback-oidc");WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, string, string[]) Section titled WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, string, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris( this IResourceBuilder<EntraIdApplicationResource> builder, IResourceBuilder<ParameterResource> host, string callbackPath, params string[] additionalCallbackPaths) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.hostIResourceBuilder<ParameterResource> A parameter whose value is the host name (optionally with a port) that serves the callbacks, such as app.contoso.com . Don't include a scheme or path.callbackPath stringThe first callback path on that host, such as /signin-oidc .additionalCallbackPaths string[]Further callback paths on that host.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its redirect URIs manually.ArgumentNullExceptionThrown when an argument is null.ArgumentExceptionThrown when a path is empty or doesn't start with /.Remarks
Use this overload when the externally visible host (for example, a custom domain or gateway) is supplied per environment at deployment time but the callback paths are fixed by the application. Each URI is https:, so the scheme is always https.
The first path is a separate parameter so that a call with only a parameter still binds to Entra. Throws for existing registrations; configure their redirect URIs manually.
Examples
var host = builder.AddParameter("web-host");var entraWeb = builder.AddEntraIdApplication("entra-web") .WithRedirectUris(host, "/signin-oidc", "/signout-callback-oidc");WithReference(IResourceBuilder<T>, IResourceBuilder<EntraIdApplicationResource>, string?, string?) Section titled WithReference(IResourceBuilder<T>, IResourceBuilder<EntraIdApplicationResource>, string?, string?)extensionIResourceBuilder<T> public static class EntraIdResourceExtensions{ public static IResourceBuilder<T> WithReference<T>( this IResourceBuilder<T> builder, IResourceBuilder<EntraIdApplicationResource> source, string? connectionName = null, string? downstreamApisPrefix = null) { // ... }}Parameters
builderIResourceBuilder<T> The resource that will receive the authentication configuration.sourceIResourceBuilder<EntraIdApplicationResource> The Entra ID application resource to reference.connectionName string?optional The environment variable prefix. When null, uses "AzureAd" for .NET program resources; otherwise, uses the source resource's name encoded as a portable environment variable name and uppercased. When empty, omits the prefix and its separator, producing ClientId for .NET program resources and CLIENT_ID for other resources. For .NET program resources, : in the name is replaced by __ . downstreamApisPrefix string?optional The configuration prefix of the DownstreamApis entries for the APIs that the application declared permissions to (see WithApiPermissions ). When null, uses "DownstreamApis" . For .NET program resources, : in the prefix is replaced by __ . A .NET program's DownstreamApis section doesn't depend on connectionName , so when a resource references several registrations that declare permissions to the same API, give all but one of them their own prefix, or the model is rejected. Returns
IResourceBuilder<T> The resource builder for chaining.Remarks
.NET program resources use _ between keys and array indexes; other resources use _. Non-.NET environment variable names, including custom connection names, use uppercase snake case, such as ENTRA_ and ENTRA_. Configuration values retain their original casing. The default names, such as Azure and Azure, map to the Azure configuration section in .NET and are compatible with Microsoft.Identity.Web.
The consuming service can then use Microsoft.Identity.Web's standard configuration:
builder.Services.AddAuthentication() .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd")); When the application declared permissions to other APIs, the consumer also receives one entry per API under the downstream prefix: {prefix}_. For an API registration in the AppHost, {name} is the name of each resource that references that registration, like the name used for service discovery.
var entraApi = builder.AddExistingEntraIdApplication("entra-api", tenantId: tenantId, clientId: clientId);
builder.AddDotnetProject("api", "../Api/Api.csproj") .WithReference(entraApi);WithScope(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>) Section titled WithScope(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithScope( this IResourceBuilder<EntraIdApplicationResource> builder, string name, string description, Action<EntraIdScope>? configure = null) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.namestringThe scope's name, which appears in the token's scp claim, such as access_as_user .descriptionstringWhat the scope allows, shown on the consent page.configureAction<EntraIdScope> optionalAn optional callback that sets the scope's other options.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentException The name is invalid or already used by another scope, or the explicit EntraIdScope.Id is already used by another scope. Remarks
Scopes are declared explicitly. Aspire does not derive them from the permissions that callers request. Unless an application ID URI is set with Entra, the registration uses api:.
The scope's ID stays the same across deployments. Microsoft Graph does not let a deployment remove an enabled scope or change its name. To retire a scope, set Entra to false and deploy, and remove the scope in a later deployment.
For an existing registration, the scope is only configuration, which lets callers declare permissions to it. Set Entra to the ID of the scope that the registration defines.
var entraApi = builder.AddEntraIdApplication("entra-api") .WithScope( "access_as_user", "Allows the app to call the API on behalf of the signed-in user.");WithSendX5C(IResourceBuilder<EntraIdApplicationResource>) Section titled WithSendX5C(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource> x5c claim (the public key of the certificate) with token requests. public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithSendX5C( this IResourceBuilder<EntraIdApplicationResource> builder) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Remarks
x5c enables certificate rollover without redeploying the application. It only applies to certificate-based credentials and increases the size of each token request, so it is opt-in. WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, string[]) Section titled WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithServicePrincipalOwners( this IResourceBuilder<EntraIdApplicationResource> builder, params string[] ownerObjectIds) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.ownerObjectIds string[]The object IDs (GUIDs) of the Microsoft Entra users or service principals to add as owners.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its service principal owners manually.ArgumentNullExceptionThrown when builder or ownerObjectIds is null.ArgumentExceptionThrown when an owner ID is not a GUID.Remarks
EntraIdResourceExtensions.WithApplicationOwners . Throws for existing registrations; configure service principal owners manually in the Microsoft Entra admin center. WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>) Section titled WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithServicePrincipalOwners( this IResourceBuilder<EntraIdApplicationResource> builder, params IResourceBuilder<ParameterResource>[] ownerObjectIds) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.ownerObjectIds IResourceBuilder<ParameterResource> Parameters whose values are the object IDs of the users or service principals to add as owners.Returns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
InvalidOperationExceptionThe registration is existing. Configure its service principal owners manually.ArgumentNullExceptionThrown when builder or ownerObjectIds is null.WithSignInAudience(IResourceBuilder<EntraIdApplicationResource>, EntraIdSignInAudience) Section titled WithSignInAudience(IResourceBuilder<EntraIdApplicationResource>, EntraIdSignInAudience)extensionIResourceBuilder<EntraIdApplicationResource> public static class EntraIdResourceExtensions{ public static IResourceBuilder<EntraIdApplicationResource> WithSignInAudience( this IResourceBuilder<EntraIdApplicationResource> builder, EntraIdSignInAudience signInAudience) { // ... }}Parameters
builderIResourceBuilder<EntraIdApplicationResource> The resource builder.signInAudience EntraReturns
IResourceBuilder<EntraIdApplicationResource> The resource builder for chaining.Exceptions
ArgumentOutOfRangeException Thrown when signInAudience is not a defined EntraIdSignInAudience value. Remarks
By default only accounts in the app's home tenant can sign in, and referencing services receive the home tenant as Tenant. For the other audiences they receive the keyword that Microsoft.Identity.Web uses to accept those accounts ( organizations, common or consumers) as Tenant, and the home tenant as App, which Microsoft.Identity.Web uses when the app acquires tokens as itself.
For registrations created by Aspire, this also sets the registration's supported account types. Existing registrations are not modified; configure their supported account types to match manually.
Users from any tenant that the audience allows can then sign in, so check the tenant ID ( tid) claim of incoming tokens before giving access to tenant-specific data. For more information, see Secure applications and APIs by validating claims.
var entraWeb = builder.AddExistingEntraIdApplication( "entra-web", tenantId, clientId) .WithSignInAudience(EntraIdSignInAudience.AzureADMultipleOrgs);