Skip to content

[AzureDevOpsExtension].LoginTenantSelection #3304

Open

Description

@h2floh

What

For the login flow, I would additional need the option to select the Entra Tenant I want to connect to.

Why

I am working with many different Azure DevOps Organisations in different Entra Tenants while keeping one identity as guest users in all of the tenants.

Activity

  1. bagleytravis68 commented on Sep 15, 2026

    @bagleytravis68

    Root cause and automatic resolution

    We encountered this exact issue when connecting to an Azure DevOps organization as a guest user (an external identity from another Entra ID tenant).

    Cause

    In azure-devops-copilot-plugin/extensions/azure-devops/canvas-server.mjs:

    const AZURE_AUTHORITY = "https://login.microsoftonline.com/common/oauth2/v2.0";

    Because /common is hardcoded, Entra ID issues tokens scoped to the user's home tenant rather than the Azure DevOps organization's resource tenant. Azure DevOps then denies access to the organization's projects and repositories, returning empty arrays ([]) from the REST APIs.

    Solution

    Azure DevOps exposes the organization's resource tenant ID directly on the organization endpoint without requiring manual tenant input from the user.

    A HEAD request to https://dev.azure.com/{organization} returns:

    • X-VSS-ResourceTenant: <tenant-guid>
    • WWW-Authenticate: Bearer authorization_uri=https://login.microsoftonline.com/<tenant-guid>

    By resolving the authority dynamically from the target organization:

    async function getAzureAuthority(organization) {
        if (!organization) return AZURE_AUTHORITY;
        try {
            const res = await fetch(`https://dev.azure.com/${encodeURIComponent(organization)}`, {
                method: "HEAD",
                headers: { "User-Agent": "Copilot-CLI-Azure-DevOps-Canvas" },
            });
            const tenant = res.headers.get("x-vss-resourcetenant");
            if (tenant) {
                return `https://login.microsoftonline.com/${tenant}/oauth2/v2.0`;
            }
        } catch {
            // Fall back to /common
        }
        return AZURE_AUTHORITY;
    }

    Using this authority when constructing authorizeUrl, calling requestMicrosoftToken, and storing it for token refreshes allows guest users to authenticate directly against the organization's tenant without needing manual tenant entry.

  2. MetzMarkus commented on Oct 6, 2026

    @MetzMarkus

    I applied the proposed approach locally: discovering the organization’s tenant via X-VSS-ResourceTenant and using that authority for authorization, token exchange, and refresh. After signing in again, the canvas correctly loads my repository, pull requests, and work items.
    Please include this into the app.

  3. added
    azure-devops
    on Oct 29, 2026
  4. meozhang commented on Nov 5, 2026

    @meozhang

    Thanks for the feedback. We've logged this with the Azure DevOps canvas team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    azure-devops

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions