Skip to content

Do not carry authority port to global instance discovery - #6155

Open
Bogdan Gavril (bgavrilMS) wants to merge 1 commit into
mainfrom
fix/6154-global-discovery-port
Open

Do not carry authority port to global instance discovery#6155
Bogdan Gavril (bgavrilMS) wants to merge 1 commit into
mainfrom
fix/6154-global-discovery-port

Conversation

@bgavrilMS

Copy link
Copy Markdown
Member

Summary

  • use an authority's custom port for instance discovery only when discovery targets that same host
  • use the default HTTPS port when an unknown authority is redirected to the global discovery host
  • preserve the custom port on authorization and token endpoints
  • update the custom-port regression coverage and shared discovery mock behavior

Fixes #6154

Testing

  • dotnet build src\client\Microsoft.Identity.Client\Microsoft.Identity.Client.csproj --framework net8.0 --no-restore --verbosity quiet

Use a custom authority port only when instance discovery targets the same host. Preserve the port on the authority itself for authorization and token requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8fd80bfc-67a0-4961-86f7-e911aaebfc13
Copilot AI review requested due to automatic review settings July 31, 2026 14:41
@bgavrilMS
Bogdan Gavril (bgavrilMS) requested a review from a team as a code owner July 31, 2026 14:41

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.

Pull request overview

This PR fixes instance discovery URL construction so that a custom authority port is not propagated when MSAL redirects instance discovery to the global discovery host, while still preserving the custom port for authorization/token endpoints.

Changes:

  • Update instance discovery endpoint computation to only apply the authority’s custom port when discovery targets the same host.
  • Align the shared instance discovery mock helper with the new endpoint behavior.
  • Update/rename the custom-port regression unit test to validate “no port on global discovery” behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/Microsoft.Identity.Test.Unit/CoreTests/InstanceTests/AadAuthorityTests.cs Updates the regression test to ensure custom port is preserved for authority usage but not applied to global instance discovery.
src/client/Microsoft.Identity.Lab.Api/Http/MockHttpManagerExtensions.cs Adjusts discovery mock URL construction to mirror the new “port only when same host” logic.
src/client/Microsoft.Identity.Client/Instance/Discovery/NetworkMetadataProvider.cs Fixes production instance discovery endpoint creation to avoid carrying the authority port to the global discovery host.

[TestMethod]
//Test for bug #1292 (https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1292)
public void AuthorityCustomPortTest()
public void AuthorityCustomPortIsPreservedAndNotUsedForGlobalInstanceDiscoveryTest()

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.

The renamed test asserts the global redirect drops the port, but there's no positive test that a custom port is used when the authority host itself is the discovery host (discoveryHost == authority.Host)

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.

Do not carry authority port to global instance discovery endpoint

3 participants