Skip to content

Improve sovereign cloud support and network error handling#1018

Open
Avery-Dunn wants to merge 4 commits intodevfrom
avdunn/instance-discovery-improvement
Open

Improve sovereign cloud support and network error handling#1018
Avery-Dunn wants to merge 4 commits intodevfrom
avdunn/instance-discovery-improvement

Conversation

@Avery-Dunn
Copy link
Contributor

@Avery-Dunn Avery-Dunn commented Mar 12, 2026

Resolves issue #1008 and makes similar changes as two MSAL.NET PRs

This PR makes the following changes:

  • Adds support for several sovereign clouds (Bleu/.fr/France, Delos/.de/Germany, .sg/Singapore)
  • Improves resiliency by falling back to non-network metadata entries when network issues occur (server-side error responses are still propagated)
  • Adds a new KnownMetadataProvider class containing known metadata entries/aliases, matching what is done in .NET
  • Adds unit tests covering the new behavior

@Avery-Dunn Avery-Dunn requested a review from a team as a code owner March 12, 2026 19:09
@@ -45,7 +45,10 @@ class AadInstanceDiscoveryProvider {
"login.chinacloudapi.cn",
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in the latest commit, Java's list should now match .NET's

try {
aadInstanceDiscoveryResponse = sendInstanceDiscoveryRequest(authorityUrl, msalRequest, serviceBundle);
} catch (MsalServiceException ex) {
// MsalServiceException indicates a definitive HTTP-level error from the server
Copy link
Member

Choose a reason for hiding this comment

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

We should only throw on "invalid_instance" error code.

}

@Test
void discoveryEndpoint_routesToSovereignHost() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

These tests mock too much and it's hard to undertand what they do. I don't think the scenario in the work item is captured here.

We need an acceptance test with mocked HTTP request / response.

  1. Authority is login.sovcloud-identity.fr
  2. Add HTTP mocks
  3. Call some acquire token (ideally from CCA)
  4. Look at HTTP requets and assert that all the requests where made on https://login.sovcloud-identity.fr/* URLs. If any of the requets were made on https://login.microsoftonline.com or any other host, fail the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed these tests and added a new SovereignCloudInstanceDiscoveryTest class: the unit tests there set up a CCA app/make acquireToken() calls and check that no calls get made to the public endpoint.

@@ -45,7 +45,10 @@ class AadInstanceDiscoveryProvider {
"login.chinacloudapi.cn",
"login-us.microsoftonline.com",
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be https://login.microsoftonline.us instead? I am not sure if login-us.microsoftonline.com exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Java has both, and so does .NET: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/112f8228349e96c25846883ed3fd95067d7fda59/src/client/Microsoft.Identity.Client/Instance/Discovery/KnownMetadataProvider.cs#L68

It still could be outdated though, we may need to audit our list of well-known hosts at some point to make sure they're still up to date.

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.

3 participants