Skip to content

Conversation

@hectormmg
Copy link
Member

@hectormmg hectormmg commented Jan 5, 2026

This pull request introduces support for tracking the source of accounts cached by MSAL, through a new accountSource property. This property is now included in the AccountInfo and AccountEntity types, and is set appropriately throughout the codebase depending on how the account was created or loaded (e.g., from MSAL, an external source, or a broker). The changes also ensure that accountSource is emitted in performance events and tested accordingly.

Account source tracking and propagation:

  • Added a new AccountSource type and accountSource property to AccountInfo and AccountEntity, allowing the source of an account (such as "msal", "external", "pwb", "naa", or "platform_broker") to be tracked throughout the authentication flow. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Updated account creation and caching logic in TokenCache, StandardController, NestedAppAuthController, and PlatformAuthInteractionClient to set the appropriate accountSource value based on the context (e.g., "external" for external tokens, "pwb" for pairwise broker, etc.). [1] [2] [3] [4] [5]

Performance telemetry enhancements:

  • Modified performance event emission to include the accountSource property, allowing for more granular telemetry and debugging. [1] [2] [3]

API and codebase updates:

  • Updated the public API documentation and type signatures to reflect the addition of accountSource, and extended the buildAccountToCache function to accept an accountSource parameter.
  • Added the DataBoundary type to the public API for completeness.

Testing improvements:

  • Added new unit tests to verify that accountSource is correctly set and emitted in performance events and when loading external tokens. [1] [2]

Changelog entries:

  • Added changelog entries for both @azure/msal-browser and @azure/msal-common packages documenting the addition of accountSource when caching an account. [1] [2]

Copilot AI review requested due to automatic review settings January 5, 2026 06:59
@hectormmg hectormmg requested a review from a team as a code owner January 5, 2026 06:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a new accountSource field to the account model, enabling MSAL to track and differentiate how accounts are created and cached. The field indicates whether an account was created by MSAL directly from a network response, loaded from external tokens, or obtained through various broker flows (pairwise broker, nested app auth, or platform broker like WAM). This enhancement improves observability, traceability, and debugging capabilities throughout the authentication flow.

Key changes:

  • Introduced the AccountSource type with five valid values: "msal", "external", "pwb", "naa", and "platform_broker"
  • Updated account creation logic across controllers and cache managers to assign appropriate source values
  • Added telemetry integration to include account source in performance events

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/msal-common/src/account/AccountInfo.ts Defines the new AccountSource type and adds the accountSource field to the AccountInfo interface
lib/msal-common/src/cache/entities/AccountEntity.ts Adds accountSource field to AccountEntity class and updates creation methods to preserve and propagate the field
lib/msal-common/src/response/ResponseHandler.ts Extends buildAccountToCache function to accept accountSource parameter with default value of "msal"
lib/msal-common/src/exports-common.ts Exports AccountSource and DataBoundary types for public API usage
lib/msal-common/src/telemetry/performance/PerformanceEvent.ts Adds accountSource to the PerformanceEvent type for telemetry tracking
lib/msal-browser/src/cache/TokenCache.ts Sets accountSource to "external" when loading external tokens via loadExternalTokens API
lib/msal-browser/src/interaction_client/PlatformAuthInteractionClient.ts Sets accountSource to "platform_broker" for accounts cached from native/platform broker responses
lib/msal-browser/src/controllers/NestedAppAuthController.ts Sets accountSource to "naa" for accounts cached from nested app auth host responses
lib/msal-browser/src/controllers/StandardController.ts Sets accountSource to "pwb" for accounts cached from pairwise broker responses and includes accountSource in telemetry
lib/msal-common/test/cache/entities/AccountEntity.spec.ts Adds comprehensive unit tests for accountSource behavior in AccountEntity creation and retrieval methods
lib/msal-common/test/response/ResponseHandler.spec.ts Adds unit tests verifying buildAccountToCache correctly handles accountSource parameter with default value
lib/msal-browser/test/cache/TokenCache.spec.ts Adds test verifying loadExternalTokens sets accountSource to "external"
lib/msal-common/apiReview/msal-common.api.md Documents API surface changes including the new AccountSource type and updated function signatures

hectormmg and others added 2 commits January 4, 2026 23:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Jan 5, 2026

@hectormmg I've opened a new pull request, #8214, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

hectormmg and others added 5 commits January 4, 2026 23:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…d.json

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
….json

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants