Remove region as hard requirement for mTLS PoP flows#5902
Open
Remove region as hard requirement for mTLS PoP flows#5902
Conversation
mTLS is now supported on global endpoints, so region should be optional. When region is available, regional mtlsauth endpoints are used as before. When no region is available, the global mtlsauth endpoint is used instead of throwing an exception. Changes: - Remove region null checks in MtlsPopParametersInitializer - Remove region validation in AcquireTokenForClientParameterBuilder.Validate() - Add global mTLS endpoint fallback in RegionAndMtlsDiscoveryProvider - Update tests that expected region-required exceptions to verify success - Add new unit tests for global mtlsauth endpoints (public, sovereign, non-standard) - Add integration tests for mTLS PoP without region Fixes: #5865 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates MSAL.NET’s mTLS PoP behavior so that an Azure region is no longer a hard requirement: when no region is configured or discoverable, MSAL falls back to global mtlsauth endpoints (while preserving existing regional behavior when a region is available).
Changes:
- Removed “region required” validation for explicit mTLS PoP and implicit bearer-over-mTLS flows.
- Added global mTLS environment fallback in region/mTLS discovery when region is unavailable.
- Updated and added unit + integration tests to validate global
mtlsauthendpoint behavior across clouds and scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/MtlsPopTests.cs | Updates existing tests to expect success without region and adds new coverage for global mtlsauth endpoint mapping (public/sovereign/non-standard). |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs | Updates client-assertion + mTLS scenarios to succeed without region and validate global endpoint usage. |
| tests/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsMtlsPopTests.cs | Adds integration coverage for no-region (global endpoint) SNI cert flow and assertion flow. |
| src/client/Microsoft.Identity.Client/Instance/Discovery/RegionAndMtlsDiscoveryProvider.cs | Implements global mtlsauth fallback when region discovery returns empty for mTLS requests. |
| src/client/Microsoft.Identity.Client/ApiConfig/Parameters/MtlsPopParametersInitializer.cs | Removes region-required checks for explicit mTLS PoP and implicit bearer-over-mTLS initialization. |
| src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs | Removes region validation from AcquireTokenForClient builder validation path for mTLS PoP. |
src/client/Microsoft.Identity.Client/Instance/Discovery/RegionAndMtlsDiscoveryProvider.cs
Show resolved
Hide resolved
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsMtlsPopTests.cs
Outdated
Show resolved
Hide resolved
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs
Outdated
Show resolved
Hide resolved
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs
Outdated
Show resolved
Hide resolved
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs
Outdated
Show resolved
Hide resolved
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Instance/Discovery/RegionAndMtlsDiscoveryProvider.cs
Show resolved
Hide resolved
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsMtlsPopTests.cs
Outdated
Show resolved
Hide resolved
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsMtlsPopTests.cs
Outdated
Show resolved
Hide resolved
- Use StringComparison.OrdinalIgnoreCase for host.StartsWith checks in GetGlobalMtlsEnvironment and GetRegionalizedEnvironment - Remove unused 'cert' variables in ClientAssertionTests - Tighten assertions: use exact URI host equality instead of StringAssert.Contains for global endpoint validation - Wrap all global-endpoint tests in EnvVariableContext with REGION_NAME cleared for deterministic behavior - Fix unused appConfig variable in integration test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
All no-region tests now explicitly clear both REGION_NAME and MSAL_FORCE_REGION within EnvVariableContext for deterministic behavior regardless of test runner environment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs
Show resolved
Hide resolved
tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientAssertionTests.cs
Show resolved
Hide resolved
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsMtlsPopTests.cs
Show resolved
Hide resolved
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsMtlsPopTests.cs
Show resolved
Hide resolved
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 #5865 — MSAL currently enforces a region for SNI mTLS/PoP scenarios. Since mTLS is now supported on global endpoints, this PR makes region optional.
When a region is configured, MSAL continues to use regional
mtlsauthendpoints as before. When no region is available, it now falls back to the globalmtlsauthendpoint instead (for example,mtlsauth.microsoft.com).Changes
Source (3 files)
MtlsPopParametersInitializer.csAcquireTokenForClientParameterBuilder.csValidate().RegionAndMtlsDiscoveryProvider.csGetGlobalMtlsEnvironment()to return globalmtlsauthendpoints when no region is available, instead of throwing.Tests (3 files)
MtlsPopTests.csmtlsauthendpoints across public, sovereign, and non-standard clouds.ClientAssertionTests.csClientCredentialsMtlsPopTests.csBehavior
eastus.mtlsauth.microsoft.comeastus.mtlsauth.microsoft.com(unchanged)MsalClientExceptionthrownmtlsauth.microsoft.com(global)MsalServiceExceptionthrownmtlsauth.microsoft.com(global)What is preserved
/commonand/organizationsare still rejected).login.usgovcloudapi.netandlogin.chinacloudapi.cnare still rejected where unsupported).