Skip to content

Derive Entra redirect URIs from resource endpoints - #21151

Merged
Eric Erhardt (eerhardt) merged 10 commits into
mainfrom
eerhardt-entra-redirect-uri-consumer-endpoints
Oct 21, 2026
Merged

Eric Erhardt (eerhardt) merged 10 commits into
mainfrom
eerhardt-entra-redirect-uri-consumer-endpoints

Conversation

@eerhardt

Copy link
Copy Markdown
Member

Description

Stacked on #21091. Adds WithRedirectUris(EndpointReference endpoint, params string[] callbackPaths) so redirect URIs follow a resource's endpoint instead of hard-coded literals.

  • Run mode: the URI is the allocated endpoint URL plus the callback path, passed as a Bicep parameter. DCP allocates endpoints before any workload starts, so Entra provisions with the real URLs first.
  • Publish/deploy: https:// plus the compute environment's GetHostAddressExpression (as Azure Front Door does) plus the path.
  • Callback path: can't be discovered, so the AppHost supplies it. It must start with / and match the consuming app's configuration. Gateways and custom domains keep using the literal or parameter overloads.
  • The EntraId playground now uses the new overload, so isolated runs register the actual ports.

Verified manually in run mode against a real Entra tenant: registered URIs matched the actual endpoints (including a random port that changed on restart) and sign-in redirect_uri values matched. Publish mode is covered only by a snapshot test with a fake compute environment.

Not covered yet (part of #21073): Web vs SPA platform, URI-count and .dev.localhost validation, duplicate-URI guard (Graph rejects duplicates with Request_BadRequest), and optional Graph diagnostics.

Part of #21073

Checklist

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

Fixes: #21073

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

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

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

Or

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

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Base automatically changed from eerhardt-entra-parameter-redirect-uris to main October 20, 2026 03:32
Add WithRedirectUris(EndpointReference, params string[] callbackPaths). Run mode uses the allocated endpoint URL; publish mode uses the compute environment host address. Callback paths are supplied by the AppHost. Update the EntraId playground to use it.

Fixes #21073

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
When the dashboard or endpoint uses a *.dev.localhost name, the orchestrator makes the friendly URL primary. Entra matches such hosts exactly, so the redirect URI must use it instead of the allocated localhost URL.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@eerhardt
Eric Erhardt (eerhardt) marked this pull request as ready for review October 20, 2026 03:35
@eerhardt
Eric Erhardt (eerhardt) force-pushed the eerhardt-entra-redirect-uri-consumer-endpoints branch from 5d4b825 to 3feb7c2 Compare October 20, 2026 03:35
@eerhardt
Eric Erhardt (eerhardt) marked this pull request as draft October 20, 2026 03:35
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 20, 2026 03:35
…play URLs

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@eerhardt
Eric Erhardt (eerhardt) marked this pull request as ready for review October 20, 2026 03:37
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The playground has a missing integration reference and mismatched Node callback origins, while deployment-derived callbacks need stronger validation.

3 open issues
What changed in this PR

Extends Entra ID redirect URI configuration so callbacks can follow resource endpoints or parameter-supplied domains instead of fixed URLs.

Changes:

  • Adds endpoint- and domain-based WithRedirectUris overloads.
  • Resolves local origins and deployment host expressions into provisioning parameters.
  • Updates tests, documentation, and the Entra ID playground.
File Description
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.WithRedirectUris_Endpoint_RunMode_UsesAllocatedEndpointUrl.verified.bicep Snapshots local redirect parameters.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.WithRedirectUris_Endpoint_PublishMode_UsesComputeEnvironmentHost.verified.bicep Snapshots publish redirect parameters.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.WithRedirectUris_Domain_WritesDomainParameterWithPaths.verified.bicep Snapshots domain-derived redirect parameters.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​EntraIdProvisioningTests.cs Tests overloads, URL resolution, and parameter naming.
src/​Aspire.Hosting.Azure.EntraId/​README.md Documents endpoint and domain configuration.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdResourceExtensions.cs Adds redirect URI overloads and validation.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdEndpointRedirectUri.cs Implements deferred redirect URI expressions.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdApplicationResource.cs Emits derived URI provisioning parameters.
src/​Aspire.Hosting.Azure.EntraId/​Aspire.Hosting.Azure.EntraId.csproj Includes the shared compute-environment resolver.
playground/​EntraId/​README.md Explains isolated-run support.
playground/​EntraId/​EntraId.AppHost/​AppHost.cs Uses endpoint-derived callbacks and adds a deployment environment.

Review effort: Balanced

Remove the unrelated container app environment from the playground, give the Node front end the same registered origin, and add a publish test with a real container app environment plus a derived callback in the deployment scenario.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved origin-selection and callback-ordering issues can register or send mismatched redirect URIs, breaking sign-in.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Match endpoint resource when selecting callback origin

src/​Aspire.Hosting.Azure.EntraId/​EntraIdEndpointRedirectUri.cs:96

Endpoint names alone do not identify an endpoint: a resource can display links to another resource's https endpoint. If its own endpoint link is DetailsOnly and a linked resource's HTTPS URL is shown in the summary, this filter selects the other resource's origin and registers callbacks on the wrong application. Match the endpoint's resource name as well, as ResourceBuilderExtensions.cs:2596–2599 does, and add a regression case with two endpoint owners.

Medium severity Resolve callback origin after URL callbacks complete

src/​Aspire.Hosting.Azure.EntraId/​EntraIdEndpointRedirectUri.cs:115

This captures the origin before later URL callbacks run, making registration depend on fluent-call order. With a *.dev.localhost dashboard, calling WithRedirectUris(...) before web.WithUrlForEndpoint("https", u => u.Url = "/swagger") captures the friendly host. The orchestrator then resolves /swagger against the allocated localhost URL, so signing in from the final dashboard link uses an unregistered callback host. Resolve the origin after all URL callbacks and relative-URL normalization finish, without blocking that pipeline, and cover both call orders.

2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Run-mode URL selection can register incorrect callback origins and introduce repeated provisioning delays.

5 open issues

Review effort: Balanced

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Case-variant parameter names can collide with generated redirect URI parameters and prevent provisioning.

4 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Use case-insensitive parameter name collision detection

src/​Aspire.Hosting.Azure.EntraId/​EntraIdApplicationResource.cs:163

This case-sensitive reservation set allows a full-URI parameter named RedirectUri0 alongside the generated redirectUri0. Bicep rejects parameter names that differ only in casing with BCP353 because Azure Resource Manager cannot distinguish them, so this combination prevents registration provisioning. Use OrdinalIgnoreCase and extend the collision test to cover a case-variant parameter name in both call orders.

1 resolved since last review

Review effort: Balanced

Match the owning resource when choosing the primary URL, complete with the allocated URL when no displayed URL remains, and use Task.WaitAsync for the timeout.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Deployment tests starting on PR #21151...

This will deploy to real Azure infrastructure. Results will be posted here when complete.

View workflow run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Authentication-sensitive URL selection and provisioning lifecycle changes need final human validation.

1 open issue
4 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 871660ba-8d46-4fb6-b76a-33b719ed42e7
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

3 / 99 PR test projects · 1 PR job, from 13 changed files.

Selected PR test projects (3 / 99)

Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests, Aspire.Playground.Tests

Selected PR jobs (1)

typescript-api-compat


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.Azure.EntraId/Aspire.Hosting.Azure.EntraId.csproj (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdApplicationResource.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdEndpointRedirectUri.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

📄 playground/EntraId/EntraId.AppHost/AppHost.cs (changed)
→ 1 directly: Aspire.Playground.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Aspire.Hosting.Azure.EntraId.Tests.csproj (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/EntraIdProvisioningTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdProvisioningTests.Publish_EndpointRedirectUri_UsesContainerAppEnvironmentHostAndOutputs#00.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdProvisioningTests.Publish_EndpointRedirectUri_UsesContainerAppEnvironmentHostAndOutputs#01.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdProvisioningTests.WithRedirectUris_Endpoint_PublishMode_UsesComputeEnvironmentHost.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdProvisioningTests.WithRedirectUris_Endpoint_RunMode_UsesAllocatedEndpointUrl.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdProvisioningTests.WithRedirectUris_Host_WritesHostParameterWithPaths.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

Job reasons

Job Triggered by
typescript-api-compat affected project Aspire.Hosting.Azure.EntraId

Selection computed for commit 3a4657d.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Authentication-origin matching and deferred provisioning dependencies need final human validation of deployment and sign-in behavior.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@eerhardt

Copy link
Copy Markdown
Member Author

PR Testing Report

PR Information

Artifact Version Verification

  • Expected Commit: 3a4657d
  • Installed Version: 17.0.0-pr.21151.g3a4657d3 (PR dogfood CLI from workflow run 39482644068)
  • Status: ✅ Verified

Changes Analyzed

  • Hosting changes: new WithRedirectUris(EndpointReference, params string[]) and WithRedirectUris(IResourceBuilder<ParameterResource> host, string, params string[]) overloads in Aspire.Hosting.Azure.EntraId; endpoint-derived URIs resolve from the allocated primary URL in run mode and from the compute environment host in publish/deploy.
  • Playground: playground/EntraId uses the endpoint overload.
  • Test changes: new unit tests and snapshots; the Entra deployment e2e scenario gains an endpoint-derived callback.
  • No CLI, Dashboard, template or CI infrastructure changes.

Test Scenarios Executed

1. Unit tests

Coverage Type: Happy path, unhappy path, boundary
Status: ✅ Passed (264/264 in Aspire.Hosting.Azure.EntraId.Tests)

Covers run mode and publish mode, a real Container App Environment publish with the parent-module parameter wiring, *.dev.localhost primary URL, relative display URLs, URLs of another resource with the same endpoint name, cleared URLs, generated parameter names colliding with user parameters (both call orders), path validation (must start with /), and a single parameter still binding to the existing overload.

2. Publish with the PR CLI (no deployment)

Coverage Type: Happy path
Status: ✅ Passed

Created an app from the PR build (Container Apps Express environment, Entra app, a consumer project) that registers an endpoint-derived URI, a host-parameter URI, a literal and a comma-separated parameter. aspire publish succeeded (11/11 steps) and generated:

  • main.bicep: redirectUri0 = 'https://consumer.${env.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN}/endpoint-callback', redirectUri1 = …/endpoint-signout, redirectUri2 = 'https://${web_host}/host-callback'
  • identity.bicep: redirectUris: concat([redirectUri0, redirectUri1, redirectUri2, 'https://example.invalid/literal-callback'], split(redirecturis, ','))

3. Manual Azure deployment (by Eric Erhardt (@eerhardt)) and Graph verification

Coverage Type: Happy path, end to end
Status: ✅ Passed

aspire deploy of the app above succeeded (westus3, consumer at https://consumer.purpleplant-7a8a8aeb.westus3.azurecontainerapps.io). Reading the registration back through Microsoft Graph showed web.redirectUris:

  • https://consumer.purpleplant-7a8a8aeb.westus3.azurecontainerapps.io/endpoint-callback
  • https://consumer.purpleplant-7a8a8aeb.westus3.azurecontainerapps.io/endpoint-signout
  • https://app.contoso.example/host-callback
  • https://example.invalid/literal-callback
  • https://example.invalid/callback
  • https://example.invalid/signout-oidc

The endpoint-derived URIs use the deployed consumer's host name, confirming the compute-environment host wiring and the dependency order.

4. Run mode against a real tenant (earlier commits)

Coverage Type: Happy path, boundary
Status: ✅ Passed, on earlier commits of this branch

Ran the playground/EntraId AppHost locally against an Entra tenant: the registered URIs matched the allocated endpoints, including a random port that changed on restart, and sign-in redirect_uri values matched. With the dashboard on *.dev.localhost the registration used the friendly URL. This predates later review fixes to the run-mode URL capture (resource matching, cleared URLs, timeout handling); those are covered by unit tests (scenario 1) but were not re-run live.

CI Infrastructure Validation

Not applicable: no CI infrastructure changes.

Known Issue: Entra deployment e2e test

AzureEntraIdDeploymentTests currently fails on CI with a Microsoft Graph Forbidden (Authorization_RequestDenied) when creating the service principal. It fails identically on main and on the Oct 16 merge commit of the original Entra provisioning PR, with the same tenant and permissions as the Oct 15 passing run, so it is not caused by this PR. The extended scenario therefore could not be executed in CI; scenario 3 covers it manually.

Summary

Scenario Status Notes
Unit tests ✅ Passed 264/264
Publish with PR CLI ✅ Passed Bicep as expected
Manual deploy + Graph check ✅ Passed URIs match deployed host
Run mode, real tenant ✅ Passed Earlier commits
Entra deployment e2e (CI) ⚠️ Blocked Tenant-side Graph failure, also fails on main

Overall Result

✅ PR VERIFIED, with the CI deployment e2e blocked by an unrelated tenant issue.

Recommendations

  • Re-run AzureEntraIdDeploymentTests once the Graph issue is resolved.

@eerhardt
Eric Erhardt (eerhardt) merged commit 8bb44fe into main Oct 21, 2026
53 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 21, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1934

Generated by PR Documentation Check · copilot · auto · 35.2 AIC · ⌖ 1.18 AIC · ⊞ 20.4K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#1934 targeting release/17.0.

Added a new Microsoft Entra ID integration page documenting the new WithRedirectUris(EndpointReference, params string[]) overload (and host-parameter overload) plus a sidebar entry. Triggered signal: integration_readme_changed (evidence: src/Aspire.Hosting.Azure.EntraId/README.md).

Note

This draft PR needs human review before merging.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Entra redirect URI configuration follow consumer endpoints and callback paths

3 participants