# EntraIdResourceExtensions Methods

- Package: [Aspire.Hosting.Azure.EntraId](/reference/api/csharp/aspire.hosting.azure.entraid.md)
- Type: [EntraIdResourceExtensions](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions.md)
- Kind: `Methods`
- Members: `46`

Provides extension methods for adding Microsoft Entra ID resources to the application model.

<a id="addentraidapplication"></a>
<a id="addentraidapplication-idistributedapplicationbuilder-string"></a>

## AddEntraIdApplication(IDistributedApplicationBuilder, string)

- Name: `AddEntraIdApplication(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L63-L74)

Adds a Microsoft Entra ID application registration resource to the application model.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> AddEntraIdApplication(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The 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 `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.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var entraApi = builder.AddEntraIdApplication("entra-api");

builder.AddDotnetProject("api", "../Api/Api.csproj")
    .WithReference(entraApi);
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="addexistingentraidapplication"></a>
<a id="addexistingentraidapplication-idistributedapplicationbuilder-string-iresourcebuilder-parameterresource-iresourcebuilder-parameterresource"></a>

## AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)

- Name: `AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds a reference to an existing Microsoft Entra ID application registration without enabling Azure provisioning.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> AddExistingEntraIdApplication(
        this IDistributedApplicationBuilder builder,
        string name,
        IResourceBuilder<ParameterResource> tenantId,
        IResourceBuilder<ParameterResource> clientId)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The 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.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(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#addentraidapplication-idistributedapplicationbuilder-string) to create a registration instead.

```csharp
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);
```

## ATS metadata

### Ignored by ATS

- Reason: The addExistingEntraIdApplication export accepts literal or parameter IDs independently.

<a id="addexistingentraidapplication-idistributedapplicationbuilder-string-string-string"></a>

## AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, string, string)

- Name: `AddExistingEntraIdApplication(IDistributedApplicationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds a reference to an existing Microsoft Entra ID application registration without enabling Azure provisioning.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> AddExistingEntraIdApplication(
        this IDistributedApplicationBuilder builder,
        string name,
        string tenantId,
        string clientId)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The 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 [EntraIdResourceExtensions.WithSignInAudience(IResourceBuilder<EntraIdApplicationResource>, EntraIdSignInAudience)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withsigninaudience-iresourcebuilder-entraidapplicationresource-entraidsigninaudience).

The registration is used only for configuration. Aspire does not deploy Bicep or query Microsoft Graph for this resource. Use [EntraIdResourceExtensions.AddEntraIdApplication(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#addentraidapplication-idistributedapplicationbuilder-string) to create a registration instead.

```csharp
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);
```

## ATS metadata

### Ignored by ATS

- Reason: The addExistingEntraIdApplication export accepts literal or parameter IDs independently.

<a id="asexistingapplication"></a>
<a id="asexistingapplication-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource-iresourcebuilder-parameterresource"></a>

## AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)

- Name: `AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Configures this resource to reference an existing Microsoft Entra ID application registration.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> AsExistingApplication(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<ParameterResource> tenantId,
        IResourceBuilder<ParameterResource> clientId)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- Registration-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.onmicrosoft.com`, and the client ID must be a GUID.

[EntraIdResourceExtensions.AddEntraIdApplication(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#addentraidapplication-idistributedapplicationbuilder-string) 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(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#addexistingentraidapplication-idistributedapplicationbuilder-string-iresourcebuilder-parameterresource-iresourcebuilder-parameterresource).

```csharp
var identity = builder.AddEntraIdApplication("identity")
    .AsExistingApplication(builder.AddParameter("TenantId"), builder.AddParameter("ClientId"));
```

## ATS metadata

### Ignored by ATS

- Reason: The asExistingApplication export accepts literal or parameter IDs independently.

<a id="asexistingapplication-iresourcebuilder-entraidapplicationresource-string-string"></a>

## AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, string, string)

- Name: `AsExistingApplication(IResourceBuilder<EntraIdApplicationResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Configures this resource to reference an existing Microsoft Entra ID application registration.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> AsExistingApplication(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string tenantId,
        string clientId)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `tenantId` (`string`)
  The registration's home tenant ID, as a GUID or a domain such as `contoso.onmicrosoft.com`.
- `clientId` (`string`)
  The registration's application (client) ID.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentException` -- A tenant ID or client ID is empty or invalid.
- `InvalidOperationException` -- Registration-only configuration is already applied to this resource.

## Remarks

Pass the home tenant ID, not a sign-in keyword such as `organizations`. Use [EntraIdResourceExtensions.WithSignInAudience(IResourceBuilder<EntraIdApplicationResource>, EntraIdSignInAudience)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withsigninaudience-iresourcebuilder-entraidapplicationresource-entraidsigninaudience) to allow accounts from other tenants to sign in.

[EntraIdResourceExtensions.AddEntraIdApplication(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#addentraidapplication-idistributedapplicationbuilder-string) 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(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#addexistingentraidapplication-idistributedapplicationbuilder-string-iresourcebuilder-parameterresource-iresourcebuilder-parameterresource).

```csharp
var identity = builder.AddEntraIdApplication("identity")
    .AsExistingApplication(
        tenantId: "aaaabbbb-0000-cccc-1111-dddd2222eeee",
        clientId: "00001111-aaaa-2222-bbbb-3333cccc4444");
```

## ATS metadata

### Ignored by ATS

- Reason: The asExistingApplication export accepts literal or parameter IDs independently.

<a id="publishwithapproleassignment"></a>
<a id="publishwithapproleassignment-iresourcebuilder-entraidapplicationresource-iresourcebuilder-azureuserassignedidentityresource-string"></a>

## PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>, string[])

- Name: `PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2033-L2035)

When published, assigns application roles of this API to a user-assigned managed identity.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> PublishWithAppRoleAssignment(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<AzureUserAssignedIdentityResource> identity,
        params string[] roleValues)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The API registration builder.
- `identity` (`IResourceBuilder<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

- `ArgumentNullException` -- Thrown when an argument is null.
- `ArgumentException` -- Thrown when no roles are supplied or a role is unknown, disabled, or does not allow application members.
- `InvalidOperationException` -- Thrown 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 `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](https://learn.microsoft.com/graph/api/serviceprincipal-post-approleassignedto).

## Examples

```csharp
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);
```

## ATS metadata

### Ignored by ATS

- Reason: The publishWithAppRoleAssignment export accepts an identity or compute resource using a union.

<a id="publishwithapproleassignment-iresourcebuilder-entraidapplicationresource-iresourcebuilder-t-string"></a>

## PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>, string[])

- Name: `PublishWithAppRoleAssignment(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2075-L2077)

When published, assigns application roles of this API to a compute resource's user-assigned managed identity.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> PublishWithAppRoleAssignment<T>(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<T> computeResource,
        params string[] roleValues)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `ArgumentNullException` -- Thrown when an argument is null.
- `ArgumentException` -- Thrown when no roles are supplied or a role is unknown, disabled, or does not allow application members.
- `InvalidOperationException` -- Thrown when the API references an existing registration or the published compute resource has no user-assigned managed identity.

## Remarks

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.

## Examples

```csharp
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");
```

## ATS metadata

### Ignored by ATS

- Reason: The publishWithAppRoleAssignment export accepts an identity or compute resource using a union.

<a id="publishwithfederatedmanagedidentitycredential"></a>
<a id="publishwithfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource"></a>

## PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>)

- Name: `PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L868-L887)

When published, authenticates this Entra ID application as each referencing resource's own user-assigned managed identity, without a client secret or certificate.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential(
        this IResourceBuilder<EntraIdApplicationResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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 [EntraIdResourceExtensions.PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#publishwithfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource) 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(IResourceBuilder<EntraIdApplicationResource>, string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource-string) 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](https://learn.microsoft.com/entra/workload-id/workload-identity-federation-config-app-trust-managed-identity).

## Examples

```csharp
var entra = builder.AddEntraIdApplication("entra-web")
    .PublishWithFederatedManagedIdentityCredential();

builder.AddDotnetProject("web", "../Web/Web.csproj")
    .WithReference(entra);
```

## ATS metadata

### Ignored by ATS

- Reason: The publishWithFederatedManagedIdentityCredential export selects consumer, compute resource, or explicit identity using a union.

<a id="publishwithfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource-iresourcebuilder-t"></a>

## PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>)

- Name: `PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<T>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L924-L943)

When published, authenticates this Entra ID application as a compute resource's user-assigned managed identity, without a client secret or certificate.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential<T>(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<T> computeResource)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

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(IResourceBuilder<EntraIdApplicationResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#publishwithfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource).

## Examples

```csharp
var entra = builder.AddEntraIdApplication("entra-web");
var web = builder.AddDotnetProject("web", "../Web/Web.csproj")
    .WithReference(entra);

entra.PublishWithFederatedManagedIdentityCredential(web);
```

## ATS metadata

### Ignored by ATS

- Reason: The publishWithFederatedManagedIdentityCredential export selects consumer, compute resource, or explicit identity using a union.

<a id="publishwithfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource-iresourcebuilder-azureuserassignedidentityresource"></a>

## PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)

- Name: `PublishWithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L977-L995)

When published, authenticates this Entra ID application as a specific user-assigned managed identity, without a client secret or certificate.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> PublishWithFederatedManagedIdentityCredential(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<AzureUserAssignedIdentityResource> identity)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `identity` (`IResourceBuilder<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

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.

## Examples

```csharp
var identity = builder.AddAzureUserAssignedIdentity("web-identity");
var entra = builder.AddEntraIdApplication("entra-web")
    .PublishWithFederatedManagedIdentityCredential(identity);

builder.AddDotnetProject("web", "../Web/Web.csproj")
    .WithAzureUserAssignedIdentity(identity)
    .WithReference(entra);
```

## ATS metadata

### Ignored by ATS

- Reason: The publishWithFederatedManagedIdentityCredential export selects consumer, compute resource, or explicit identity using a union.

<a id="runwithlocaldevelopercertificatecredential"></a>
<a id="runwithlocaldevelopercertificatecredential-iresourcebuilder-entraidapplicationresource"></a>

## RunWithLocalDeveloperCertificateCredential(IResourceBuilder<EntraIdApplicationResource>)

- Name: `RunWithLocalDeveloperCertificateCredential(IResourceBuilder<EntraIdApplicationResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L687-L700)

Creates and provisions a short-lived certificate credential for local development.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> RunWithLocalDeveloperCertificateCredential(
        this IResourceBuilder<EntraIdApplicationResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `InvalidOperationException` -- The 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 `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.

## Examples

```csharp
// 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);
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withadminconsent"></a>
<a id="withadminconsent-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string"></a>

## WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2724-L2737)

Grants tenant-wide consent to delegated permissions that this registration declared for another registration in the AppHost.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithAdminConsent(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<EntraIdApplicationResource> api,
        params string[] scopeNames)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The calling registration, which must be created by Aspire.
- `api` (`IResourceBuilder<EntraIdApplicationResource>`)
  The registration that exposes the scopes.
- `scopeNames` (`string[]`)
  The names of scopes already declared with [EntraIdResourceExtensions.WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapipermissions-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string).

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentException` -- A scope is not exposed or is disabled, or no scope was given.
- `InvalidOperationException` -- The calling registration is existing, or a scope was not declared first.

## Remarks

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](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.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withadminconsent-iresourcebuilder-entraidapplicationresource-entraidapi-entraidapipermission"></a>

## WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[])

- Name: `WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2785-L2802)

Grants tenant-wide consent to permissions that this registration declared for an API that is not an Aspire resource.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithAdminConsent(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        EntraIdApi api,
        params EntraIdApiPermission[] permissions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The calling registration, which must be created by Aspire.
- `api` ([EntraIdApi](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapi.md))
  The API, for example [EntraIdApi.MicrosoftGraph](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapi/properties.md#microsoftgraph).
- `permissions` (`EntraIdApiPermission[]`)
  Permissions already declared with [EntraIdResourceExtensions.WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapipermissions-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string).

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `InvalidOperationException` -- The calling registration is existing, or a permission was not declared first.

## Remarks

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](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.

```csharp
var entraWeb = builder.AddEntraIdApplication("entra-web")
    .WithApiPermissions(EntraIdApi.MicrosoftGraph, EntraIdApiPermission.Application("User.Read.All"))
    .WithAdminConsent(EntraIdApi.MicrosoftGraph, EntraIdApiPermission.Application("User.Read.All"));
```

## ATS metadata

### Ignored by ATS

- Reason: EntraIdApi and EntraIdApiPermission are C# types. The withExternalApiAdminConsent export takes DTOs.

<a id="withallowwebapitobeauthorizedbyacl"></a>
<a id="withallowwebapitobeauthorizedbyacl-iresourcebuilder-entraidapplicationresource"></a>

## WithAllowWebApiToBeAuthorizedByACL(IResourceBuilder<EntraIdApplicationResource>)

- Name: `WithAllowWebApiToBeAuthorizedByACL(IResourceBuilder<EntraIdApplicationResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2211-L2214)

Enables ACL-based authorization for daemon-to-API scenarios.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithAllowWebApiToBeAuthorizedByACL(
        this IResourceBuilder<EntraIdApplicationResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withapipermissions"></a>
<a id="withapipermissions-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string"></a>

## WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2591-L2611)

Declares that this registration requires delegated permissions to scopes of another registration in the AppHost.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithApiPermissions(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<EntraIdApplicationResource> api,
        params string[] scopeNames)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The calling registration.
- `api` (`IResourceBuilder<EntraIdApplicationResource>`)
  The registration that exposes the scopes.
- `scopeNames` (`string[]`)
  The names of the scopes, added with [EntraIdResourceExtensions.WithScope(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withscope-iresourcebuilder-entraidapplicationresource-string-string-action-entraidscope) to `api`.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentException` -- A scope is not exposed or is disabled, or no scope was given.
- `InvalidOperationException` -- `api` already pre-authorizes this registration, or depends on it in another way. See [EntraIdResourceExtensions.WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withpreauthorizedapplication-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string).

## 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 ( [EntraIdResourceExtensions.WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withadminconsent-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string)) or `api` pre-authorizes the caller ( [EntraIdResourceExtensions.WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withpreauthorizedapplication-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string)).

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.

```csharp
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");
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withapipermissions-iresourcebuilder-entraidapplicationresource-entraidapi-entraidapipermission"></a>

## WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[])

- Name: `WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, EntraIdApi, EntraIdApiPermission[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2647-L2663)

Declares that this registration requires permissions to an API that is not an Aspire resource, such as Microsoft Graph.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithApiPermissions(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        EntraIdApi api,
        params EntraIdApiPermission[] permissions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The calling registration.
- `api` ([EntraIdApi](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapi.md))
  The API, for example [EntraIdApi.MicrosoftGraph](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapi/properties.md#microsoftgraph).
- `permissions` (`EntraIdApiPermission[]`)
  The permissions to require.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentException` -- A 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 [EntraIdResourceExtensions.WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withadminconsent-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string) to opt in to consent. For an existing caller, only consumer DownstreamApis configuration is emitted; configure its API permissions manually.

Delegated permissions ( [EntraIdApiPermission.Delegated(string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapipermission/methods.md#delegated-string)) let the application act for a signed-in user. Application permissions ( [EntraIdApiPermission.Application(string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapipermission/methods.md#application-string)) 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.

```csharp
var entraWeb = builder.AddEntraIdApplication("entra-web")
    .WithApiPermissions(EntraIdApi.MicrosoftGraph, EntraIdApiPermission.Delegated("User.Read"));
```

## ATS metadata

### Ignored by ATS

- Reason: EntraIdApi and EntraIdApiPermission are C# types. The withExternalApiPermissions export takes DTOs.

<a id="withapplicationiduri"></a>
<a id="withapplicationiduri-iresourcebuilder-entraidapplicationresource"></a>

## WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>)

- Name: `WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2298-L2304)

Exposes the registration as an API identified by the default application ID URI, `api://{clientId}`.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithApplicationIdUri(
        this IResourceBuilder<EntraIdApplicationResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `InvalidOperationException` -- The 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://{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(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withscope-iresourcebuilder-entraidapplicationresource-string-string-action-entraidscope) uses this URI unless [EntraIdResourceExtensions.WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapplicationiduri-iresourcebuilder-entraidapplicationresource) sets another one.

This setting only affects registrations created by Aspire. For an existing registration, call [EntraIdResourceExtensions.WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapplicationiduri-iresourcebuilder-entraidapplicationresource) with the URI it already has.

## ATS metadata

### Ignored by ATS

- Reason: The withApplicationIdUri export accepts an optional URI.

<a id="withapplicationiduri-iresourcebuilder-entraidapplicationresource-string"></a>

## WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>, string)

- Name: `WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2332-L2342)

Exposes the registration as an API identified by a custom application ID URI.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithApplicationIdUri(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string applicationIdUri)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `applicationIdUri` (`string`)
  The URI, such as `api://contoso-orders` or `https://contoso.onmicrosoft.com/orders`.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentException` -- `applicationIdUri` 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 `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](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(string)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapplicationresource/methods.md#getscopeuri-string) uses the URI to build scope names for callers.

## ATS metadata

### Ignored by ATS

- Reason: The withApplicationIdUri export accepts an optional URI.

<a id="withapplicationowners"></a>
<a id="withapplicationowners-iresourcebuilder-entraidapplicationresource-string"></a>

## WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds explicit owners to the application registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithApplicationOwners(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params string[] ownerObjectIds)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its owners manually.
- `ArgumentNullException` -- Thrown when `builder` or `ownerObjectIds` is null.
- `ArgumentException` -- Thrown 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.ReadWrite.All` Microsoft Graph permission or a directory role such as Application Administrator).

Application and service principal ownership are separate; use [EntraIdResourceExtensions.WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withserviceprincipalowners-iresourcebuilder-entraidapplicationresource-string) for the enterprise application. Throws for existing registrations; configure their owners manually in the Microsoft Entra admin center.

## Examples

```csharp
var entraApi = builder.AddEntraIdApplication("entra-api")
    .WithApplicationOwners("00000000-0000-0000-0000-000000000001");
```

## ATS metadata

### Ignored by ATS

- Reason: The withApplicationOwners export accepts literal or parameter owner IDs.

<a id="withapplicationowners-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource"></a>

## WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)

- Name: `WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds explicit owners, supplied by parameters, to the application registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithApplicationOwners(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params IResourceBuilder<ParameterResource>[] ownerObjectIds)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its owners manually.
- `ArgumentNullException` -- Thrown when `builder` or `ownerObjectIds` is null.

## Remarks

See [EntraIdResourceExtensions.WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapplicationowners-iresourcebuilder-entraidapplicationresource-string) for permission and append semantics.

## ATS metadata

### Ignored by ATS

- Reason: The withApplicationOwners export accepts literal or parameter owner IDs.

<a id="withapprole"></a>
<a id="withapprole-iresourcebuilder-entraidapplicationresource-entraidapprole"></a>

## WithAppRole(IResourceBuilder<EntraIdApplicationResource>, EntraIdAppRole)

- Name: `WithAppRole(IResourceBuilder<EntraIdApplicationResource>, EntraIdAppRole)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1927-L1945)

Declares an application role on the registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithAppRole(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        EntraIdAppRole role)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `role` ([EntraIdAppRole](/reference/api/csharp/aspire.hosting.azure.entraid/entraidapprole.md))
  The application role to declare.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `role` is null.
- `ArgumentException` -- Thrown when a role with the same value or ID is already declared.
- `InvalidOperationException` -- Thrown 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 `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`.

## Examples

```csharp
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"]));
```

## ATS metadata

### Ignored by ATS

- Reason: EntraIdAppRole is a C# type with a constructor. The withAppRole export takes its values as arguments.

<a id="withaudience"></a>
<a id="withaudience-iresourcebuilder-entraidapplicationresource-string"></a>

## WithAudience(IResourceBuilder<EntraIdApplicationResource>, string)

- Name: `WithAudience(IResourceBuilder<EntraIdApplicationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2269-L2273)

Adds an accepted audience for this application.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithAudience(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string audience)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `audience` (`string`)
  The audience value (e.g., `api://<client-id>`).

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Remarks

Configures consumer token validation only. It does not change application ID URIs on created or existing registrations.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withcertificatedistinguishedname"></a>
<a id="withcertificatedistinguishedname-iresourcebuilder-entraidapplicationresource-string-string"></a>

## WithCertificateDistinguishedName(IResourceBuilder<EntraIdApplicationResource>, string, string)

- Name: `WithCertificateDistinguishedName(IResourceBuilder<EntraIdApplicationResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1172-L1182)

Adds a certificate credential from the certificate store by distinguished name.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithCertificateDistinguishedName(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string storePath,
        string distinguishedName)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `storePath` (`string`)
  The certificate store path (e.g., `"CurrentUser/My"`).
- `distinguishedName` (`string`)
  The certificate distinguished name (e.g., `"CN=MyCert"`).

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withcertificatefromkeyvault"></a>
<a id="withcertificatefromkeyvault-iresourcebuilder-entraidapplicationresource-string-string"></a>

## WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, string, string)

- Name: `WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1055-L1065)

Adds a certificate credential from Azure Key Vault to this Entra ID application.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithCertificateFromKeyVault(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string keyVaultUrl,
        string certificateName)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `keyVaultUrl` (`string`)
  The URL of the Key Vault (e.g., `"https://myvault.vault.azure.net"`).
- `certificateName` (`string`)
  The name of the certificate in Key Vault.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### Ignored by ATS

- Reason: The withCertificateFromKeyVault export accepts a URL or a Key Vault resource using a union.

<a id="withcertificatefromkeyvault-iresourcebuilder-entraidapplicationresource-iresourcebuilder-azurekeyvaultresource-string"></a>

## WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureKeyVaultResource>, string)

- Name: `WithCertificateFromKeyVault(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<AzureKeyVaultResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1097-L1105)

Adds a certificate credential from an Azure Key Vault resource to this Entra ID application.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithCertificateFromKeyVault(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<AzureKeyVaultResource> keyVault,
        string certificateName)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `keyVault` (`IResourceBuilder<AzureKeyVaultResource>`)
  The Key Vault containing the certificate.
- `certificateName` (`string`)
  The name of the certificate in Key Vault.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `keyVault` is null.
- `ArgumentException` -- Thrown when `certificateName` is null or empty.

## Remarks

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.

## Examples

```csharp
var vault = builder.AddAzureKeyVault("vault");
var entra = builder.AddExistingEntraIdApplication("entra", tenantId, clientId)
    .WithCertificateFromKeyVault(vault, "web-certificate");
builder.AddProject<Projects.Web>("web").WithReference(entra);
```

## ATS metadata

### Ignored by ATS

- Reason: The withCertificateFromKeyVault export accepts a URL or a Key Vault resource using a union.

<a id="withcertificatethumbprint"></a>
<a id="withcertificatethumbprint-iresourcebuilder-entraidapplicationresource-string-string"></a>

## WithCertificateThumbprint(IResourceBuilder<EntraIdApplicationResource>, string, string)

- Name: `WithCertificateThumbprint(IResourceBuilder<EntraIdApplicationResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1146-L1156)

Adds a certificate credential from the certificate store by thumbprint.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithCertificateThumbprint(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string storePath,
        string thumbprint)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `storePath` (`string`)
  The certificate store path (e.g., `"CurrentUser/My"`).
- `thumbprint` (`string`)
  The certificate thumbprint.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withclientcapability"></a>
<a id="withclientcapability-iresourcebuilder-entraidapplicationresource-string"></a>

## WithClientCapability(IResourceBuilder<EntraIdApplicationResource>, string)

- Name: `WithClientCapability(IResourceBuilder<EntraIdApplicationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2195-L2199)

Adds a client capability (e.g., `"cp1"` for Continuous Access Evaluation).

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithClientCapability(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string capability)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `capability` (`string`)
  The capability identifier.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withclientsecret"></a>
<a id="withclientsecret-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource"></a>

## WithClientSecret(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)

- Name: `WithClientSecret(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L723-L736)

Adds a client secret credential to this Entra ID application.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithClientSecret(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<ParameterResource> clientSecret)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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 `ClientCredentials` array in the Microsoft.Identity.Web configuration with `SourceType` set to `"ClientSecret"`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withcredential"></a>
<a id="withcredential-iresourcebuilder-entraidapplicationresource-entraidclientcredential"></a>

## WithCredential(IResourceBuilder<EntraIdApplicationResource>, EntraIdClientCredential)

- Name: `WithCredential(IResourceBuilder<EntraIdApplicationResource>, EntraIdClientCredential)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1239-L1248)

Adds a raw credential entry for advanced scenarios not covered by convenience methods.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithCredential(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        EntraIdClientCredential credential)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `credential` ([EntraIdClientCredential](/reference/api/csharp/aspire.hosting.azure.entraid/entraidclientcredential.md))
  A fully configured [EntraIdClientCredential](/reference/api/csharp/aspire.hosting.azure.entraid/entraidclientcredential.md).

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### Ignored by ATS

- Reason: EntraIdClientCredential is a mutable C# hierarchy. Use the typed credential exports instead.

<a id="withextraqueryparameter"></a>
<a id="withextraqueryparameter-iresourcebuilder-entraidapplicationresource-string-string"></a>

## WithExtraQueryParameter(IResourceBuilder<EntraIdApplicationResource>, string, string)

- Name: `WithExtraQueryParameter(IResourceBuilder<EntraIdApplicationResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2249-L2254)

Adds an extra query parameter to send to the identity provider.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithExtraQueryParameter(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string key,
        string value)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `key` (`string`)
  The query parameter key.
- `value` (`string`)
  The query parameter value.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withfederatedmanagedidentitycredential"></a>
<a id="withfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource-string"></a>

## WithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, string)

- Name: `WithFederatedManagedIdentityCredential(IResourceBuilder<EntraIdApplicationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L785-L795)

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.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithFederatedManagedIdentityCredential(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string managedIdentityClientId)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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 `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(IResourceBuilder<EntraIdApplicationResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#publishwithfederatedmanagedidentitycredential-iresourcebuilder-entraidapplicationresource) 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](https://learn.microsoft.com/entra/workload-id/workload-identity-federation-config-app-trust-managed-identity).

## Examples

```csharp
var entraWeb = builder.AddExistingEntraIdApplication("entra-web", tenantId, clientId)
    .WithFederatedManagedIdentityCredential("00001111-aaaa-2222-bbbb-3333cccc4444");
```

## ATS metadata

### Ignored by ATS

- Reason: The withFederatedManagedIdentityCredential export also accepts typed token exchange options.

<a id="withidtokenissuance"></a>
<a id="withidtokenissuance-iresourcebuilder-entraidapplicationresource"></a>

## WithIdTokenIssuance(IResourceBuilder<EntraIdApplicationResource>)

- Name: `WithIdTokenIssuance(IResourceBuilder<EntraIdApplicationResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2177-L2181)

Enables ID-token issuance through implicit and hybrid flows for a registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithIdTokenIssuance(
        this IResourceBuilder<EntraIdApplicationResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `InvalidOperationException` -- The registration is existing. Configure its ID-token issuance manually.
- `ArgumentNullException` -- Thrown 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.

```csharp
var entraWeb = builder.AddEntraIdApplication("entra-web")
    .WithIdTokenIssuance()
    .WithRedirectUris("https://localhost:7123/signin-oidc");
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withinstance"></a>
<a id="withinstance-iresourcebuilder-entraidapplicationresource-string"></a>

## WithInstance(IResourceBuilder<EntraIdApplicationResource>, string)

- Name: `WithInstance(IResourceBuilder<EntraIdApplicationResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1308-L1317)

Configures the Entra ID instance URL. Defaults to `https://login.microsoftonline.com/`.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithInstance(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string instance)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `instance` (`string`)
  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.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withowners"></a>
<a id="withowners-iresourcebuilder-entraidapplicationresource-string"></a>

## WithOwners(IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithOwners(IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds explicit owners to both the application registration and the service principal created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithOwners(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params string[] ownerObjectIds)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its owners manually.

## Remarks

Equivalent to calling [EntraIdResourceExtensions.WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapplicationowners-iresourcebuilder-entraidapplicationresource-string) and [EntraIdResourceExtensions.WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withserviceprincipalowners-iresourcebuilder-entraidapplicationresource-string) with the same IDs.

## ATS metadata

### Ignored by ATS

- Reason: The withOwners export accepts literal or parameter owner IDs.

<a id="withowners-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource"></a>

## WithOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)

- Name: `WithOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds explicit owners, supplied by parameters, to both the application registration and the service principal created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithOwners(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params IResourceBuilder<ParameterResource>[] ownerObjectIds)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its owners manually.

## ATS metadata

### Ignored by ATS

- Reason: The withOwners export accepts literal or parameter owner IDs.

<a id="withpreauthorizedapplication"></a>
<a id="withpreauthorizedapplication-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string"></a>

## WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithPreAuthorizedApplication(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2533-L2549)

Pre-authorizes a client application to request some of this registration's scopes without any consent prompt.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithPreAuthorizedApplication(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<EntraIdApplicationResource> client,
        params string[] scopeNames)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The registration that exposes the scopes, which must be created by Aspire.
- `client` (`IResourceBuilder<EntraIdApplicationResource>`)
  The client application to pre-authorize.
- `scopeNames` (`string[]`)
  The names of the scopes, added with [EntraIdResourceExtensions.WithScope(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withscope-iresourcebuilder-entraidapplicationresource-string-string-action-entraidscope), that the client may request.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentException` -- A 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 ( [EntraIdResourceExtensions.WithApiPermissions(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapipermissions-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string)) and from consent ( [EntraIdResourceExtensions.WithAdminConsent(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withadminconsent-iresourcebuilder-entraidapplicationresource-iresourcebuilder-entraidapplicationresource-string)). 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.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withredirecturis"></a>
<a id="withredirecturis-iresourcebuilder-entraidapplicationresource-string"></a>

## WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds web redirect URIs to a registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params string[] redirectUris)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its redirect URIs manually.
- `ArgumentNullException` -- Thrown when `builder` or `redirectUris` is null.
- `ArgumentException` -- Thrown when a redirect URI is empty.

## Remarks

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.

## Examples

```csharp
var entraWeb = builder.AddEntraIdApplication("entra-web")
    .WithRedirectUris("https://localhost:7123/signin-oidc");
```

## ATS metadata

### Ignored by ATS

- Reason: The withRedirectUris export accepts a literal, parameter, or endpoint with optional callback paths.

<a id="withredirecturis-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource"></a>

## WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)

- Name: `WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds parameters whose values supply web redirect URIs to a registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params IResourceBuilder<ParameterResource>[] redirectUris)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its redirect URIs manually.
- `ArgumentNullException` -- Thrown 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 [EntraIdResourceExtensions.WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withredirecturis-iresourcebuilder-entraidapplicationresource-string); URIs are registered in call order.

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

## Examples

```csharp
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);
```

## ATS metadata

### Ignored by ATS

- Reason: The withRedirectUris export accepts a literal, parameter, or endpoint with optional callback paths.

<a id="withredirecturis-iresourcebuilder-entraidapplicationresource-endpointreference-string"></a>

## WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, EndpointReference, string[])

- Name: `WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, EndpointReference, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1510-L1534)

Adds redirect URIs for a resource's endpoint to a registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        EndpointReference endpoint,
        params string[] callbackPaths)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `endpoint` (`EndpointReference`)
  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

- `InvalidOperationException` -- The registration is existing, or infrastructure generation detects that TLS is disabled for the deployed endpoint.
- `ArgumentNullException` -- Thrown when an argument is null.
- `ArgumentException` -- Thrown 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 `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.

## Examples

```csharp
var web = builder.AddDotnetProject("web", "../Web/Web.csproj").WithExternalHttpEndpoints();
var entraWeb = builder.AddEntraIdApplication("entra-web")
    .WithRedirectUris(web.GetEndpoint("https"), "/signin-oidc", "/signout-callback-oidc");
```

## ATS metadata

### Ignored by ATS

- Reason: The withRedirectUris export accepts a literal, parameter, or endpoint with optional callback paths.

<a id="withredirecturis-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource-string-string"></a>

## WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, string, string[])

- Name: `WithRedirectUris(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>, string, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1603-L1623)

Adds redirect URIs for a host supplied by a parameter to a registration created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithRedirectUris(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        IResourceBuilder<ParameterResource> host,
        string callbackPath,
        params string[] additionalCallbackPaths)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `host` (`IResourceBuilder<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` (`string`)
  The 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

- `InvalidOperationException` -- The registration is existing. Configure its redirect URIs manually.
- `ArgumentNullException` -- Thrown when an argument is null.
- `ArgumentException` -- Thrown 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://{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(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withredirecturis-iresourcebuilder-entraidapplicationresource-string). Throws for existing registrations; configure their redirect URIs manually.

## Examples

```csharp
var host = builder.AddParameter("web-host");
var entraWeb = builder.AddEntraIdApplication("entra-web")
    .WithRedirectUris(host, "/signin-oidc", "/signout-callback-oidc");
```

## ATS metadata

### Ignored by ATS

- Reason: The withRedirectUris export accepts a literal, parameter, or endpoint with optional callback paths.

<a id="withreference"></a>
<a id="withreference-iresourcebuilder-t-iresourcebuilder-entraidapplicationresource-string-string"></a>

## WithReference(IResourceBuilder<T>, IResourceBuilder<EntraIdApplicationResource>, string?, string?)

- Name: `WithReference(IResourceBuilder<T>, IResourceBuilder<EntraIdApplicationResource>, string?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L3037-L3057)

Injects Entra ID authentication configuration into a consuming resource.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<T> WithReference<T>(
        this IResourceBuilder<T> builder,
        IResourceBuilder<EntraIdApplicationResource> source,
        string? connectionName = null,
        string? downstreamApisPrefix = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource that will receive the authentication configuration.
- `source` (`IResourceBuilder<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_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:

```csharp
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.

```csharp
var entraApi = builder.AddExistingEntraIdApplication("entra-api",
        tenantId: tenantId,
        clientId: clientId);

builder.AddDotnetProject("api", "../Api/Api.csproj")
    .WithReference(entraApi);
```

## ATS metadata

### Ignored by ATS

- Reason: Polyglot AppHosts use the generic withReference dispatcher with an Entra ID application builder.

<a id="withscope"></a>
<a id="withscope-iresourcebuilder-entraidapplicationresource-string-string-action-entraidscope"></a>

## WithScope(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>)

- Name: `WithScope(IResourceBuilder<EntraIdApplicationResource>, string, string, Action<EntraIdScope>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2408-L2432)

Exposes a delegated permission scope that clients can request to call this registration as an API.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithScope(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        string name,
        string description,
        Action<EntraIdScope>? configure = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `name` (`string`)
  The scope's name, which appears in the token's `scp` claim, such as `access_as_user`.
- `description` (`string`)
  What the scope allows, shown on the consent page.
- `configure` (`Action<EntraIdScope>`) `optional`
  An 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](/reference/api/csharp/aspire.hosting.azure.entraid/entraidscope/properties.md#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 [EntraIdResourceExtensions.WithApplicationIdUri(IResourceBuilder<EntraIdApplicationResource>)](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapplicationiduri-iresourcebuilder-entraidapplicationresource), 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](/reference/api/csharp/aspire.hosting.azure.entraid/entraidscope/properties.md#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](/reference/api/csharp/aspire.hosting.azure.entraid/entraidscope/properties.md#id) to the ID of the scope that the registration defines.

```csharp
var entraApi = builder.AddEntraIdApplication("entra-api")
    .WithScope("access_as_user", "Allows the app to call the API on behalf of the signed-in user.");
```

## ATS metadata

### Ignored by ATS

- Reason: The withScope export takes the scope options as a DTO instead of a callback.

<a id="withsendx5c"></a>
<a id="withsendx5c-iresourcebuilder-entraidapplicationresource"></a>

## WithSendX5C(IResourceBuilder<EntraIdApplicationResource>)

- Name: `WithSendX5C(IResourceBuilder<EntraIdApplicationResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L2230-L2233)

Sends the `x5c` claim (the public key of the certificate) with token requests.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithSendX5C(
        this IResourceBuilder<EntraIdApplicationResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Remarks

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.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withserviceprincipalowners"></a>
<a id="withserviceprincipalowners-iresourcebuilder-entraidapplicationresource-string"></a>

## WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, string[])

- Name: `WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds explicit owners to the service principal (enterprise application) created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithServicePrincipalOwners(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params string[] ownerObjectIds)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its service principal owners manually.
- `ArgumentNullException` -- Thrown when `builder` or `ownerObjectIds` is null.
- `ArgumentException` -- Thrown when an owner ID is not a GUID.

## Remarks

Service principal ownership is independent of application registration ownership and has the same append semantics and permission requirements as [EntraIdResourceExtensions.WithApplicationOwners(IResourceBuilder<EntraIdApplicationResource>, string[])](/reference/api/csharp/aspire.hosting.azure.entraid/entraidresourceextensions/methods.md#withapplicationowners-iresourcebuilder-entraidapplicationresource-string). Throws for existing registrations; configure service principal owners manually in the Microsoft Entra admin center.

## ATS metadata

### Ignored by ATS

- Reason: The withServicePrincipalOwners export accepts literal or parameter owner IDs.

<a id="withserviceprincipalowners-iresourcebuilder-entraidapplicationresource-iresourcebuilder-parameterresource"></a>

## WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)

- Name: `WithServicePrincipalOwners(IResourceBuilder<EntraIdApplicationResource>, IResourceBuilder<ParameterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs)

Adds explicit owners, supplied by parameters, to the service principal (enterprise application) created by Aspire.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithServicePrincipalOwners(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        params IResourceBuilder<ParameterResource>[] ownerObjectIds)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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

- `InvalidOperationException` -- The registration is existing. Configure its service principal owners manually.
- `ArgumentNullException` -- Thrown when `builder` or `ownerObjectIds` is null.

## ATS metadata

### Ignored by ATS

- Reason: The withServicePrincipalOwners export accepts literal or parameter owner IDs.

<a id="withsigninaudience"></a>
<a id="withsigninaudience-iresourcebuilder-entraidapplicationresource-entraidsigninaudience"></a>

## WithSignInAudience(IResourceBuilder<EntraIdApplicationResource>, EntraIdSignInAudience)

- Name: `WithSignInAudience(IResourceBuilder<EntraIdApplicationResource>, EntraIdSignInAudience)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<EntraIdApplicationResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs#L1367-L1375)

Configures which accounts can sign in to this application.

```csharp
public static class EntraIdResourceExtensions
{
    public static IResourceBuilder<EntraIdApplicationResource> WithSignInAudience(
        this IResourceBuilder<EntraIdApplicationResource> builder,
        EntraIdSignInAudience signInAudience)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<EntraIdApplicationResource>`)
  The resource builder.
- `signInAudience` ([EntraIdSignInAudience](/reference/api/csharp/aspire.hosting.azure.entraid/entraidsigninaudience.md))
  The accounts that can sign in. It must match the "Supported account types" setting of the app registration.

## Returns

`IResourceBuilder<EntraIdApplicationResource>` -- The resource builder for chaining.

## Exceptions

- `ArgumentOutOfRangeException` -- Thrown when `signInAudience` is not a defined [EntraIdSignInAudience](/reference/api/csharp/aspire.hosting.azure.entraid/entraidsigninaudience.md) value.

## Remarks

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](https://learn.microsoft.com/entra/identity-platform/claims-validation).

Let work or school accounts from any organization sign in:

```csharp
var entraWeb = builder.AddExistingEntraIdApplication("entra-web", tenantId, clientId)
    .WithSignInAudience(EntraIdSignInAudience.AzureADMultipleOrgs);
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
