Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 15, 2025

Problem

When using managed identity in multi-tenant applications with AzureAd.TenantId set to "common", the GetAuthenticationResultForAppAsync method throws an IDW10405 error:

IDW10405: 'tenant' parameter should be a tenant ID or domain name, not 'common', 'organizations' or 'consumers'.

This occurs because ResolveTenant is called before checking if managed identity is being used. For managed identity flows, tenant resolution is not needed and should be skipped entirely.

Configuration Example

{
  "AzureAd": {
    "TenantId": "common",
    "ClientId": "<app-guid>"
  },
  "DownstreamApis": {
    "MyApi": {
      "BaseUrl": "https://example.com",
      "Scopes": ["scope"],
      "AcquireTokenOptions": {
        "ManagedIdentity": {
          "UserAssignedClientId": "<managed-identity-client-guid>"
        }
      }
    }
  }
}

Solution

Moved the ResolveTenant call to execute only for non-managed identity scenarios:

  • Before: ResolveTenant was called unconditionally, causing the error
  • After: ResolveTenant is skipped when using managed identity, preventing the error

Changes

  1. TokenAcquisition.cs: Moved ResolveTenant call after managed identity check
  2. TokenAcquisitionTests.cs: Added test case to verify the fix

The fix is minimal and surgical - only 3 lines changed in the core logic while preserving all existing functionality.

Testing

  • Added comprehensive test case covering the scenario
  • Verified existing tenant resolution logic still works correctly
  • Confirmed no regression in non-managed identity flows

Fixes #3395.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] [Bug] Getting IDW10405 when overriding acquire token options with managed identity Fix IDW10405 error when using managed identity with common tenant Jul 15, 2025
Copilot finished work on behalf of jmprieur July 15, 2025 16:30
Copilot AI requested a review from jmprieur July 15, 2025 16:30
@jmprieur jmprieur marked this pull request as ready for review July 15, 2025 16:45
@jmprieur jmprieur requested a review from a team as a code owner July 15, 2025 16:45
Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

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

LGTM

This was referenced Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Getting IDW10405 when overriding acquire token options with managed identity

4 participants