EntraIdResourceExtensions Methods

ClassMethods46 members
Provides extension methods for adding Microsoft Entra ID resources to the application model.
AddEntraIdApplication(IDistributedApplicationBuilder, string)Section titled AddEntraIdApplication(IDistributedApplicationBuilder, string)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a Microsoft Entra ID application registration resource to the application model.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> AddEntraIdApplication(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource.
IResourceBuilder<EntraIdApplicationResource>A reference to the ApplicationModel.IResourceBuilder`1.

The Entra ID application resource injects configuration as environment variables into consuming services. For .NET programs, the variables default to the AzureAd 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 AddExistingEntraIdApplication 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>
Adds a reference to an existing Microsoft Entra ID application registration without enabling Azure provisioning.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> AddExistingEntraIdApplication(
this IDistributedApplicationBuilder builder,
string name,
IResourceBuilder<ParameterResource> tenantId,
IResourceBuilder<ParameterResource> clientId)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource.
tenantIdIResourceBuilder<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.
clientIdIResourceBuilder<ParameterResource> A parameter containing the application (client) ID, shown as "Application (client) ID" on the app registration's Overview page.
IResourceBuilder<EntraIdApplicationResource>A reference to the ApplicationModel.IResourceBuilder`1.

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.onmicrosoft.com, and the client ID must be a GUID. When a value is missing or malformed, the resource reports FailedToStart and logs the reason.

The registration is used only for configuration. Aspire does not deploy Bicep or query Microsoft Graph for this resource. Use EntraIdResourceExtensions.AddEntraIdApplication 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>
Adds a reference to an existing Microsoft Entra ID application registration without enabling Azure provisioning.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> AddExistingEntraIdApplication(
this IDistributedApplicationBuilder builder,
string name,
string tenantId,
string clientId)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource.
tenantIdstring 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.
clientIdstring The application (client) ID, shown as "Application (client) ID" on the app registration's Overview page.
IResourceBuilder<EntraIdApplicationResource>A reference to the ApplicationModel.IResourceBuilder`1.
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.

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 EntraIdResourceExtensions.WithSignInAudience.

The registration is used only for configuration. Aspire does not deploy Bicep or query Microsoft Graph for this resource. Use EntraIdResourceExtensions.AddEntraIdApplication 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>
Configures this resource to reference an existing Microsoft Entra ID application registration.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> AsExistingApplication(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<ParameterResource> tenantId,
IResourceBuilder<ParameterResource> clientId)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
tenantIdIResourceBuilder<ParameterResource>A parameter containing the registration's home tenant ID.
clientIdIResourceBuilder<ParameterResource>A parameter containing the registration's application (client) ID.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionRegistration-only configuration is already applied to this resource.

Parameter values are validated when the application starts. The tenant ID must be a GUID or a domain such as contoso.onmicrosoft.com, and the client ID must be a GUID.

EntraIdResourceExtensions.AddEntraIdApplication 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 EntraIdResourceExtensions.AddExistingEntraIdApplication.

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>
Configures this resource to reference an existing Microsoft Entra ID application registration.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> AsExistingApplication(
this IResourceBuilder<EntraIdApplicationResource> builder,
string tenantId,
string clientId)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
tenantIdstringThe registration's home tenant ID, as a GUID or a domain such as contoso.onmicrosoft.com.
clientIdstringThe registration's application (client) ID.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentExceptionA tenant ID or client ID is empty or invalid.
InvalidOperationExceptionRegistration-only configuration is already applied to this resource.

Pass the home tenant ID, not a sign-in keyword such as organizations. Use EntraIdResourceExtensions.WithSignInAudience to allow accounts from other tenants to sign in.

EntraIdResourceExtensions.AddEntraIdApplication 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 EntraIdResourceExtensions.AddExistingEntraIdApplication.

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>
When published, assigns application roles of this API to a user-assigned managed identity.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> PublishWithAppRoleAssignment(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<AzureUserAssignedIdentityResource> identity,
params string[] roleValues)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The API registration builder.
identityIResourceBuilder<AzureUserAssignedIdentityResource>The managed identity receiving the roles. Workloads attach it with WithAzureUserAssignedIdentity.
roleValuesstring[]The values of enabled roles declared with WithAppRole that allow Application members.
IResourceBuilder<EntraIdApplicationResource>The API registration builder for chaining.
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.

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 AppRoleAssignment.ReadWrite.All and Application.Read.All (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.

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>
When published, assigns application roles of this API to a compute resource's user-assigned managed identity.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> PublishWithAppRoleAssignment<T>(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<T> computeResource,
params string[] roleValues)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The API registration builder.
computeResourceIResourceBuilder<T>The compute resource whose managed identity receives the roles.
roleValuesstring[]The values of enabled roles declared with WithAppRole that allow Application members.
IResourceBuilder<EntraIdApplicationResource>The API registration builder for chaining.
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.
The Azure environment reuses the compute resource's attached identity or creates one during deployment preparation. The identity is resolved after preparation; the compute resource need not reference this registration. An excluded compute resource receives no assignment. This does not configure federation or token acquisition. Like the explicit-identity overload, this is publish-only, requires directory assignment privileges, and does not revoke assignments when a call is removed.
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>
When published, authenticates this Entra ID application as each referencing resource's own user-assigned managed identity, without a client secret or certificate.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential(
this IResourceBuilder<EntraIdApplicationResource> builder)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.

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 EntraIdResourceExtensions.PublishWithFederatedManagedIdentityCredential 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 WithReference is given a managed identity when published, and the application trusts it. The identity is the one the resource already has, for example from WithAzureUserAssignedIdentity 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 ManagedIdentityClientId.

This is only for registrations that Aspire creates. For an existing registration ( AddExistingEntraIdApplication), which Aspire never modifies, this method throws; use EntraIdResourceExtensions.WithFederatedManagedIdentityCredential 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.

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>
When published, authenticates this Entra ID application as a compute resource's user-assigned managed identity, without a client secret or certificate.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential<T>(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<T> computeResource)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
computeResourceIResourceBuilder<T> The compute resource to trust. It must reference this application with WithReference. Only this resource receives the managed identity credential.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationException Thrown when the registration is existing or computeResource does not reference this application.
Only 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.
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>
When published, authenticates this Entra ID application as a specific user-assigned managed identity, without a client secret or certificate.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<AzureUserAssignedIdentityResource> identity)
{
// ...
}
}
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.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
The federated identity credential uses the identity's principal ID as the subject and consumers receive its client ID. Throws for an existing registration, which Aspire never modifies. The credential is not used when running locally.
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>
Creates and provisions a short-lived certificate credential for local development.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> RunWithLocalDeveloperCertificateCredential(
this IResourceBuilder<EntraIdApplicationResource> builder)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is an existing application, which Aspire never modifies.

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 Base64EncodedValue in Microsoft.Identity.Web's ClientCredentials configuration. Aspire replaces the registration's entire keyCredentials 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 AsExistingApplication.

Renewal is checked at AppHost startup, not in the background. Restart long-running development sessions before the certificate expires. Use PublishWithFederatedManagedIdentityCredential for deployed workloads.

// 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>
Grants tenant-wide consent to delegated permissions that this registration declared for another registration in the AppHost.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithAdminConsent(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<EntraIdApplicationResource> api,
params string[] scopeNames)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The calling registration, which must be created by Aspire.
apiIResourceBuilder<EntraIdApplicationResource>The registration that exposes the scopes.
scopeNamesstring[]The names of scopes already declared with EntraIdResourceExtensions.WithApiPermissions.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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.

This creates a delegated permission grant for all users ( consentType: AllPrincipals) 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 DelegatedPermissionGrant.ReadWrite.All. 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 WithAdminConsent 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>
Grants tenant-wide consent to permissions that this registration declared for an API that is not an Aspire resource.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithAdminConsent(
this IResourceBuilder<EntraIdApplicationResource> builder,
EntraIdApi api,
params EntraIdApiPermission[] permissions)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The calling registration, which must be created by Aspire.
apiEntraIdApiThe API, for example EntraIdApi.MicrosoftGraph.
permissionsEntraIdApiPermission[]Permissions already declared with EntraIdResourceExtensions.WithApiPermissions.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe calling registration is existing, or a permission was not declared first.

A delegated permission becomes a delegated permission grant for all users ( consentType: AllPrincipals). 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 WithAdminConsent 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 DelegatedPermissionGrant.ReadWrite.All 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 AppRoleAssignment.ReadWrite.All 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.Read.All 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>
Enables ACL-based authorization for daemon-to-API scenarios.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithAllowWebApiToBeAuthorizedByACL(
this IResourceBuilder<EntraIdApplicationResource> builder)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])Section titled WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource>
Declares that this registration requires delegated permissions to scopes of another registration in the AppHost.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithApiPermissions(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<EntraIdApplicationResource> api,
params string[] scopeNames)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The calling registration.
apiIResourceBuilder<EntraIdApplicationResource>The registration that exposes the scopes.
scopeNamesstring[]The names of the scopes, added with EntraIdResourceExtensions.WithScope to api.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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.

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 ( EntraIdResourceExtensions.WithAdminConsent) or api pre-authorizes the caller ( EntraIdResourceExtensions.WithPreAuthorizedApplication).

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>
Declares that this registration requires permissions to an API that is not an Aspire resource, such as Microsoft Graph.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithApiPermissions(
this IResourceBuilder<EntraIdApplicationResource> builder,
EntraIdApi api,
params EntraIdApiPermission[] permissions)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The calling registration.
apiEntraIdApiThe API, for example EntraIdApi.MicrosoftGraph.
permissionsEntraIdApiPermission[]The permissions to require.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentExceptionA permission is unknown for the API and has no ID, or no permission was given.

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 EntraIdResourceExtensions.WithAdminConsent to opt in to consent. For an existing caller, only consumer DownstreamApis configuration is emitted; configure its API permissions manually.

Delegated permissions ( EntraIdApiPermission.Delegated) let the application act for a signed-in user. Application permissions ( EntraIdApiPermission.Application) 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>
Exposes the registration as an API identified by the default application ID URI, api://{clientId}.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithApplicationIdUri(
this IResourceBuilder<EntraIdApplicationResource> builder)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Supply its registered URI explicitly instead.

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://{clientId} 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 EntraIdResourceExtensions.WithScope uses this URI unless EntraIdResourceExtensions.WithApplicationIdUri sets another one.

This setting only affects registrations created by Aspire. For an existing registration, call EntraIdResourceExtensions.WithApplicationIdUri with the URI it already has.

WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>, string)Section titled WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource>
Exposes the registration as an API identified by a custom application ID URI.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithApplicationIdUri(
this IResourceBuilder<EntraIdApplicationResource> builder,
string applicationIdUri)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
applicationIdUristringThe URI, such as api://contoso-orders or https://contoso.onmicrosoft.com/orders.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentExceptionapplicationIdUri is not an absolute URI without a query string or fragment.

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 requestedAccessTokenVersion is 2, which Aspire always sets, so a name such as api://contoso-orders 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 EntraIdApplicationResource.GetScopeUri uses the URI to build scope names for callers.

WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])Section titled WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource>
Adds explicit owners to the application registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithApplicationOwners(
this IResourceBuilder<EntraIdApplicationResource> builder,
params string[] ownerObjectIds)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
ownerObjectIdsstring[]The object IDs (GUIDs) of the Microsoft Entra users or service principals to add as owners.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its owners manually.
ArgumentNullExceptionThrown when builder or ownerObjectIds is null.
ArgumentExceptionThrown when an owner ID is not a GUID.

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.ReadWrite.All Microsoft Graph permission or a directory role such as Application Administrator).

Application and service principal ownership are separate; use EntraIdResourceExtensions.WithServicePrincipalOwners for the enterprise application. Throws for existing registrations; configure their owners manually in the Microsoft Entra admin center.

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>
Adds explicit owners, supplied by parameters, to the application registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithApplicationOwners(
this IResourceBuilder<EntraIdApplicationResource> builder,
params IResourceBuilder<ParameterResource>[] ownerObjectIds)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
ownerObjectIdsIResourceBuilder<ParameterResource>Parameters whose values are the object IDs of the users or service principals to add as owners.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its owners manually.
ArgumentNullExceptionThrown when builder or ownerObjectIds is null.
See EntraIdResourceExtensions.WithApplicationOwners for permission and append semantics.
WithAppRole(IResourceBuilder<EntraIdApplicationResource>, EntraIdAppRole)Section titled WithAppRole(IResourceBuilder<EntraIdApplicationResource>, EntraIdAppRole)extensionIResourceBuilder<EntraIdApplicationResource>
Declares an application role on the registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithAppRole(
this IResourceBuilder<EntraIdApplicationResource> builder,
EntraIdAppRole role)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
roleEntraIdAppRoleThe application role to declare.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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.

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 appRoles 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 AddExistingEntraIdApplication.

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>
Adds an accepted audience for this application.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithAudience(
this IResourceBuilder<EntraIdApplicationResource> builder,
string audience)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
audiencestringThe audience value (e.g., api://<client-id>).
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
Configures consumer token validation only. It does not change application ID URIs on created or existing registrations.
WithCertificateDistinguishedName(IResourceBuilder<EntraIdApplicationResource>, string, string)Section titled WithCertificateDistinguishedName(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a certificate credential from the certificate store by distinguished name.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithCertificateDistinguishedName(
this IResourceBuilder<EntraIdApplicationResource> builder,
string storePath,
string distinguishedName)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
storePathstringThe certificate store path (e.g., "CurrentUser/My").
distinguishedNamestringThe certificate distinguished name (e.g., "CN=MyCert").
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, string, string)Section titled WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a certificate credential from Azure Key Vault to this Entra ID application.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithCertificateFromKeyVault(
this IResourceBuilder<EntraIdApplicationResource> builder,
string keyVaultUrl,
string certificateName)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
keyVaultUrlstringThe URL of the Key Vault (e.g., "https://myvault.vault.azure.net").
certificateNamestringThe name of the certificate in Key Vault.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureKeyVaultResource>, string)Section titled WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureKeyVaultResource>, string)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a certificate credential from an Azure Key Vault resource to this Entra ID application.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithCertificateFromKeyVault(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<AzureKeyVaultResource> keyVault,
string certificateName)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
keyVaultIResourceBuilder<AzureKeyVaultResource>The Key Vault containing the certificate.
certificateNamestringThe name of the certificate in Key Vault.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentNullExceptionThrown when builder or keyVault is null.
ArgumentExceptionThrown when certificateName is null or empty.
The vault URI remains a resource reference during run and publish. The Key Vault Certificate User role is added to the vault's default roles when running, and assigned to each resource referencing this application when publishing, which requires an environment that supports role assignments. The certificate must already exist, and its public key must be registered with the Entra application. Microsoft.Identity.Web loads the latest certificate version.
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>
Adds a certificate credential from the certificate store by thumbprint.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithCertificateThumbprint(
this IResourceBuilder<EntraIdApplicationResource> builder,
string storePath,
string thumbprint)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
storePathstringThe certificate store path (e.g., "CurrentUser/My").
thumbprintstringThe certificate thumbprint.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithClientCapability(IResourceBuilder<EntraIdApplicationResource>, string)Section titled WithClientCapability(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a client capability (e.g., "cp1" for Continuous Access Evaluation).
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithClientCapability(
this IResourceBuilder<EntraIdApplicationResource> builder,
string capability)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
capabilitystringThe capability identifier.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithClientSecret(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)Section titled WithClientSecret(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a client secret credential to this Entra ID application.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithClientSecret(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<ParameterResource> clientSecret)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
clientSecretIResourceBuilder<ParameterResource>A secret parameter containing the client secret.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentException Thrown when clientSecret is not marked as a secret parameter.

This adds an entry to the ClientCredentials array in the Microsoft.Identity.Web configuration with SourceType set to "ClientSecret".

WithCredential(IResourceBuilder<EntraIdApplicationResource>, EntraIdClientCredential)Section titled WithCredential(IResourceBuilder<EntraIdApplicationResource>, EntraIdClientCredential)extensionIResourceBuilder<EntraIdApplicationResource>
Adds a raw credential entry for advanced scenarios not covered by convenience methods.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithCredential(
this IResourceBuilder<EntraIdApplicationResource> builder,
EntraIdClientCredential credential)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithExtraQueryParameter(IResourceBuilder<EntraIdApplicationResource>, string, string)Section titled WithExtraQueryParameter(IResourceBuilder<EntraIdApplicationResource>, string, string)extensionIResourceBuilder<EntraIdApplicationResource>
Adds an extra query parameter to send to the identity provider.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithExtraQueryParameter(
this IResourceBuilder<EntraIdApplicationResource> builder,
string key,
string value)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
keystringThe query parameter key.
valuestringThe query parameter value.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
WithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, string)Section titled WithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, string)extensionIResourceBuilder<EntraIdApplicationResource>
Configures the app to authenticate as this Entra ID application using a managed identity that you specify by client ID, without a client secret or certificate.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithFederatedManagedIdentityCredential(
this IResourceBuilder<EntraIdApplicationResource> builder,
string managedIdentityClientId)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
managedIdentityClientIdstring 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.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentException Thrown when managedIdentityClientId is empty or is not a GUID.

This only configures the consuming app: it adds a SignedAssertionFromManagedIdentity entry to the ClientCredentials 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 ( AddExistingEntraIdApplication), 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://login.microsoftonline.com/{tenant}/v2.0 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://AzureADTokenExchange in the Azure public cloud). Otherwise, token requests fail with AADSTS700213.

For a registration that Aspire creates, use EntraIdResourceExtensions.PublishWithFederatedManagedIdentityCredential 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.

var entraWeb = builder.AddExistingEntraIdApplication("entra-web", tenantId, clientId)
.WithFederatedManagedIdentityCredential("00001111-aaaa-2222-bbbb-3333cccc4444");
WithIdTokenIssuance(IResourceBuilder<EntraIdApplicationResource>)Section titled WithIdTokenIssuance(IResourceBuilder<EntraIdApplicationResource>)extensionIResourceBuilder<EntraIdApplicationResource>
Enables ID-token issuance through implicit and hybrid flows for a registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithIdTokenIssuance(
this IResourceBuilder<EntraIdApplicationResource> builder)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its ID-token issuance manually.
ArgumentNullExceptionThrown when builder is null.

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>
Configures the Entra ID instance URL. Defaults to https://login.microsoftonline.com/.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithInstance(
this IResourceBuilder<EntraIdApplicationResource> builder,
string instance)
{
// ...
}
}
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.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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>
Adds explicit owners to both the application registration and the service principal created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithOwners(
this IResourceBuilder<EntraIdApplicationResource> builder,
params string[] ownerObjectIds)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
ownerObjectIdsstring[]The object IDs (GUIDs) of the Microsoft Entra users or service principals to add as owners.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its owners manually.
WithOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)Section titled WithOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<EntraIdApplicationResource>
Adds explicit owners, supplied by parameters, to both the application registration and the service principal created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithOwners(
this IResourceBuilder<EntraIdApplicationResource> builder,
params IResourceBuilder<ParameterResource>[] ownerObjectIds)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
ownerObjectIdsIResourceBuilder<ParameterResource>Parameters whose values are the object IDs of the users or service principals to add as owners.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its owners manually.
WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])Section titled WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])extensionIResourceBuilder<EntraIdApplicationResource>
Pre-authorizes a client application to request some of this registration's scopes without any consent prompt.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithPreAuthorizedApplication(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<EntraIdApplicationResource> client,
params string[] scopeNames)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The registration that exposes the scopes, which must be created by Aspire.
clientIResourceBuilder<EntraIdApplicationResource>The client application to pre-authorize.
scopeNamesstring[]The names of the scopes, added with EntraIdResourceExtensions.WithScope, that the client may request.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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.

Pre-authorization is separate from the client's declaration of the permission ( EntraIdResourceExtensions.WithApiPermissions) and from consent ( EntraIdResourceExtensions.WithAdminConsent). 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 WithAdminConsent 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>
Adds web redirect URIs to a registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
this IResourceBuilder<EntraIdApplicationResource> builder,
params string[] redirectUris)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
redirectUrisstring[]The redirect URIs to register for browser sign-in and sign-out callbacks.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its redirect URIs manually.
ArgumentNullExceptionThrown when builder or redirectUris is null.
ArgumentExceptionThrown when a redirect URI is empty.
URIs are written directly into the generated infrastructure; endpoints are not discovered automatically. Throws for existing registrations. Configure their redirect URIs in the Microsoft Entra admin center instead.
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>
Adds parameters whose values supply web redirect URIs to a registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
this IResourceBuilder<EntraIdApplicationResource> builder,
params IResourceBuilder<ParameterResource>[] redirectUris)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
redirectUrisIResourceBuilder<ParameterResource>Parameters whose values are the redirect URIs. Each value may contain several URIs separated by commas.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
InvalidOperationExceptionThe registration is existing. Configure its redirect URIs manually.
ArgumentNullExceptionThrown when builder, redirectUris, or one of its elements is null.

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 EntraIdResourceExtensions.WithRedirectUris; URIs are registered in call order.

Endpoints are not discovered automatically. Throws for existing registrations; configure their redirect URIs manually.

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>
Adds redirect URIs for a resource's endpoint to a registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
this IResourceBuilder<EntraIdApplicationResource> builder,
EndpointReference endpoint,
params string[] callbackPaths)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
endpointEndpointReferenceThe endpoint that serves the callbacks.
callbackPathsstring[]The callback paths on that endpoint, such as /signin-oidc.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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 /.

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 WithRedirectUris 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.

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>
Adds redirect URIs for a host supplied by a parameter to a registration created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
this IResourceBuilder<EntraIdApplicationResource> builder,
IResourceBuilder<ParameterResource> host,
string callbackPath,
params string[] additionalCallbackPaths)
{
// ...
}
}
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.
callbackPathstringThe first callback path on that host, such as /signin-oidc.
additionalCallbackPathsstring[]Further callback paths on that host.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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 /.

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://{host}{path}, so the scheme is always https.

The first path is a separate parameter so that a call with only a parameter still binds to EntraIdResourceExtensions.WithRedirectUris. Throws for existing registrations; configure their redirect URIs manually.

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>
Injects Entra ID authentication configuration into a consuming resource.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<T> WithReference<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<EntraIdApplicationResource> source,
string? connectionName = null,
string? downstreamApisPrefix = null)
{
// ...
}
}
builderIResourceBuilder<T>The resource that will receive the authentication configuration.
sourceIResourceBuilder<EntraIdApplicationResource>The Entra ID application resource to reference.
connectionNamestring?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 __.
downstreamApisPrefixstring?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.
IResourceBuilder<T>The resource builder for chaining.

.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_API_CLIENT_ID and ENTRA_API_CLIENT_CREDENTIALS_0_SOURCE_TYPE. Configuration values retain their original casing. The default names, such as AzureAd__TenantId and AzureAd__ClientId, map to the AzureAd 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 downstreamApisPrefix prefix: {prefix}__{name}__Scopes__{index}. 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>
Exposes a delegated permission scope that clients can request to call this registration as an API.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithScope(
this IResourceBuilder<EntraIdApplicationResource> builder,
string name,
string description,
Action<EntraIdScope>? configure = null)
{
// ...
}
}
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.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentException The name is invalid or already used by another scope, or the explicit EntraIdScope.Id is already used by another scope.

Scopes are declared explicitly. Aspire does not derive them from the permissions that callers request. Unless an application ID URI is set with EntraIdResourceExtensions.WithApplicationIdUri, the registration uses api://{clientId}.

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 EntraIdScope.IsEnabled 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 EntraIdScope.Id 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>
Sends the x5c claim (the public key of the certificate) with token requests.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithSendX5C(
this IResourceBuilder<EntraIdApplicationResource> builder)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
Sending 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>
Adds explicit owners to the service principal (enterprise application) created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithServicePrincipalOwners(
this IResourceBuilder<EntraIdApplicationResource> builder,
params string[] ownerObjectIds)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
ownerObjectIdsstring[]The object IDs (GUIDs) of the Microsoft Entra users or service principals to add as owners.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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.
Service principal ownership is independent of application registration ownership and has the same append semantics and permission requirements as 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>
Adds explicit owners, supplied by parameters, to the service principal (enterprise application) created by Aspire.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithServicePrincipalOwners(
this IResourceBuilder<EntraIdApplicationResource> builder,
params IResourceBuilder<ParameterResource>[] ownerObjectIds)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
ownerObjectIdsIResourceBuilder<ParameterResource>Parameters whose values are the object IDs of the users or service principals to add as owners.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
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>
Configures which accounts can sign in to this application.
public static class EntraIdResourceExtensions
{
public static IResourceBuilder<EntraIdApplicationResource> WithSignInAudience(
this IResourceBuilder<EntraIdApplicationResource> builder,
EntraIdSignInAudience signInAudience)
{
// ...
}
}
builderIResourceBuilder<EntraIdApplicationResource>The resource builder.
signInAudienceEntraIdSignInAudience The accounts that can sign in. It must match the "Supported account types" setting of the app registration.
IResourceBuilder<EntraIdApplicationResource>The resource builder for chaining.
ArgumentOutOfRangeException Thrown when signInAudience is not a defined EntraIdSignInAudience value.

By default only accounts in the app's home tenant can sign in, and referencing services receive the home tenant as TenantId. For the other audiences they receive the keyword that Microsoft.Identity.Web uses to accept those accounts ( organizations, common or consumers) as TenantId, and the home tenant as AppHomeTenantId, 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.

Let work or school accounts from any organization sign in:
var entraWeb = builder.AddExistingEntraIdApplication(
"entra-web",
tenantId,
clientId)
.WithSignInAudience(EntraIdSignInAudience.AzureADMultipleOrgs);