Do not carry authority port to global instance discovery - #6155
Open
Bogdan Gavril (bgavrilMS) wants to merge 1 commit into
Open
Do not carry authority port to global instance discovery#6155Bogdan Gavril (bgavrilMS) wants to merge 1 commit into
Bogdan Gavril (bgavrilMS) wants to merge 1 commit into
Conversation
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
Contributor
There was a problem hiding this comment.
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() |
Contributor
There was a problem hiding this comment.
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)
Gladwin Johnson (gladjohn)
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6154
Testing
dotnet build src\client\Microsoft.Identity.Client\Microsoft.Identity.Client.csproj --framework net8.0 --no-restore --verbosity quiet