Migrate region discovery to IMDS /compute JSON endpoint#8660
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates msal-common region auto-discovery from the legacy IMDS text endpoint (/compute/location?format=text) to the IMDS /compute JSON endpoint (api-version 2021-02-01), reading the location field while preserving the existing precedence/fallback behavior.
Changes:
- Updated IMDS endpoint + api-version constants to point to
/metadata/instance/computeand2021-02-01. - Updated region discovery to parse
body.locationfrom JSON responses (including 400-version-negotiation retry path). - Added unit tests for success/missing/null/malformed JSON + 400 api-version negotiation; refreshed apiReview and added changefile.
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 |
|---|---|
| lib/msal-common/src/utils/Constants.ts | Updates IMDS endpoint path and api-version used for region discovery. |
| lib/msal-common/src/response/ImdsComputeResponse.ts | Adds a typed shape for the IMDS /compute JSON response. |
| lib/msal-common/src/authority/RegionDiscovery.ts | Switches region parsing from text response to JSON location field and adjusts region_source assignment. |
| lib/msal-common/test/authority/Authority.spec.ts | Adds test coverage for new IMDS /compute behavior and edge cases. |
| lib/msal-common/apiReview/msal-common.api.md | Reflects updated constant values in the reviewed API snapshot. |
| change/@azure-msal-common-82a28208-9ab4-418a-9bf7-07f559d81efd.json | Beachball changefile for the msal-common patch. |
The IMDS /compute payload can legitimately omit location or return null, and the region-discovery code already handles that via optional chaining. Declare location as optional so the type reflects reality and future callers can't assume it is always a non-empty string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
gladjohn
reviewed
Jun 18, 2026
gladjohn
previously approved these changes
Jun 18, 2026
The @param referenced a removed imdsEndpointUrl parameter; update it to document the actual version and options parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
gladjohn
approved these changes
Jun 22, 2026
tnorling
approved these changes
Jun 23, 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
Ports microsoft-authentication-library-for-dotnet PR #6057 to MSAL.js.
Migrates region auto-discovery in
lib/msal-commonfrom the legacy IMDS text endpoint/metadata/instance/compute/location(api-version=2020-06-01,format=text) to the newer JSON endpoint/metadata/instance/compute(api-version=2021-02-01), parsing thelocationfield.There is no public API surface change (only the values of the existing
IMDS_ENDPOINT/IMDS_VERSIONconstants change), no telemetry schema change, and no feature flag.REGION_NAMEprecedence, the api-version 400 fallback, process-wide caching, and timeouts are all preserved.What changed
Constants.ts:IMDS_ENDPOINT->.../metadata/instance/compute(drop/location);IMDS_VERSION->2021-02-01.ImdsComputeResponsetype ({ location: string }) mirroring dotnet'sLocalImdsComputeResponseDTO.RegionDiscovery.ts:getRegionFromIMDSdropsformat=textand is typed asNetworkResponse<ImdsComputeResponse>;detectRegionreadsbody?.locationin both success branches and only setsregion_source = IMDSwhen a usable location exists. Missing/nulllocationfunnels into the existingFAILED_AUTO_DETECTIONpath; malformed JSON is caught by the existingtry/catch(msal-js auto-parses viaresponse.json()).Authority.spec.ts): newRegionDiscovery IMDS compute endpointblock covering the success path, missinglocation, nulllocation, malformed JSON, and the 400 api-version negotiation retry.apiReview/msal-common.api.mdrefreshed;@azure/msal-commonchangefile added.Testing
npm run build,npm run lint(0 errors),npm test(1026 passed, incl. 5 new),npm run format:check,npm run apiExtractor, and rootnpm run beachball:checkall pass.Out of scope
Unified
/computesnapshot cache for VM-only consumers; MI source detection.