-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add accountSource when caching an account #8213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
AccountSourcetype 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 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@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. |
There was a problem hiding this 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.
change/@azure-msal-common-66533c87-d4a2-4bbc-a945-dd29a31aefdd.json
Outdated
Show resolved
Hide resolved
change/@azure-msal-browser-1145035b-3987-40b0-aa28-833a1eaff8cd.json
Outdated
Show resolved
Hide resolved
change/@azure-msal-node-08f73185-611d-41d3-80cd-5f09a114593a.json
Outdated
Show resolved
Hide resolved
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>
This pull request introduces support for tracking the source of accounts cached by MSAL, through a new
accountSourceproperty. This property is now included in theAccountInfoandAccountEntitytypes, 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 thataccountSourceis emitted in performance events and tested accordingly.Account source tracking and propagation:
AccountSourcetype andaccountSourceproperty toAccountInfoandAccountEntity, 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]TokenCache,StandardController,NestedAppAuthController, andPlatformAuthInteractionClientto set the appropriateaccountSourcevalue based on the context (e.g.,"external"for external tokens,"pwb"for pairwise broker, etc.). [1] [2] [3] [4] [5]Performance telemetry enhancements:
accountSourceproperty, allowing for more granular telemetry and debugging. [1] [2] [3]API and codebase updates:
accountSource, and extended thebuildAccountToCachefunction to accept anaccountSourceparameter.DataBoundarytype to the public API for completeness.Testing improvements:
accountSourceis correctly set and emitted in performance events and when loading external tokens. [1] [2]Changelog entries:
@azure/msal-browserand@azure/msal-commonpackages documenting the addition ofaccountSourcewhen caching an account. [1] [2]