-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[msal-v5] Add accountSource when caching an account #8215
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
af364b9
Add accountSource property to account generation and caching logic
hectormmg f96b111
Add account source unit tests
hectormmg 0fee271
Add acountSource to ATS telemetry fields
hectormmg 27880c8
Fix format and update apiReview
hectormmg ae21838
Change files
hectormmg 3c16bd6
Add test for accountSource telemetry field
hectormmg a0a5071
Update lib/msal-common/src/account/AccountInfo.ts
hectormmg a39dd11
Update lib/msal-common/test/response/ResponseHandler.spec.ts
hectormmg 4eb799a
Add accountSource to testconstants in Node tests
hectormmg 59e12a0
Change files
hectormmg fefe52d
Fix changefile
hectormmg 56d5a61
Fix tests and format
hectormmg 7bc8eea
Parameterize accountSource in loadAccount
hectormmg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-1145035b-3987-40b0-aa28-833a1eaff8cd.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": " Add accountSource when caching an account #8213", | ||
| "packageName": "@azure/msal-browser", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-common-66533c87-d4a2-4bbc-a945-dd29a31aefdd.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add accountSource when caching an account #8213", | ||
| "packageName": "@azure/msal-common", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-node-08f73185-611d-41d3-80cd-5f09a114593a.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "Add accountSource when caching an account 8213", | ||
| "packageName": "@azure/msal-node", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "none" | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1431,7 +1431,10 @@ export class StandardController implements IController { | |
| // Account gets saved to browser storage regardless of native or not | ||
| const accountEntity = | ||
| AccountEntityUtils.createAccountEntityFromAccountInfo( | ||
| result.account, | ||
| { | ||
| ...result.account, | ||
| accountSource: "pwb", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use API names or a number tag, we can't assume this is a PWB call
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest using ApiId actually |
||
| }, | ||
| result.cloudGraphHostName, | ||
| result.msGraphHost | ||
| ); | ||
|
|
@@ -1881,6 +1884,7 @@ export class StandardController implements IController { | |
| isNativeBroker: result.fromPlatformBroker, | ||
| accessTokenSize: result.accessToken.length, | ||
| idTokenSize: result.idToken.length, | ||
| accountSource: account.accountSource, | ||
| }, | ||
| undefined, | ||
| result.account | ||
|
|
@@ -1900,6 +1904,7 @@ export class StandardController implements IController { | |
| atsMeasurement.end( | ||
| { | ||
| success: false, | ||
| accountSource: account.accountSource, | ||
| }, | ||
| error, | ||
| account | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5350,6 +5350,60 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { | |
| pca.acquireTokenSilent(silentRequest); | ||
| }); | ||
|
|
||
| it("emits accountSource in performance event when account has accountSource", (done) => { | ||
| const testIdTokenClaims: TokenClaims = { | ||
| ver: "2.0", | ||
| iss: "https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0", | ||
| sub: "AAAAAAAAAAAAAAAAAAAAAIkzqFVrSaSaFHy782bbtaQ", | ||
| name: "Abe Lincoln", | ||
| preferred_username: "[email protected]", | ||
| oid: "00000000-0000-0000-66f3-3332eca7ea81", | ||
| tid: "3338040d-6c67-4c5b-b112-36a304b66dad", | ||
| nonce: "123523", | ||
| login_hint: "testLoginHint", | ||
| }; | ||
|
|
||
| const testAccount: AccountInfo = { | ||
| homeAccountId: TEST_DATA_CLIENT_INFO.TEST_HOME_ACCOUNT_ID, | ||
| localAccountId: TEST_DATA_CLIENT_INFO.TEST_UID, | ||
| environment: "login.windows.net", | ||
| tenantId: testIdTokenClaims.tid || "", | ||
| username: testIdTokenClaims.preferred_username || "", | ||
| loginHint: testIdTokenClaims.login_hint, | ||
| idTokenClaims: { ...testIdTokenClaims }, | ||
| accountSource: "external", | ||
| }; | ||
|
|
||
| jest.spyOn(ProtocolUtils, "setRequestState").mockReturnValue( | ||
| TEST_STATE_VALUES.TEST_STATE_SILENT | ||
| ); | ||
| const silentRequest: SilentRequest = { | ||
| scopes: ["User.Read"], | ||
| account: testAccount, | ||
| correlationId: RANDOM_TEST_GUID, | ||
| }; | ||
|
|
||
| jest.spyOn( | ||
| StandardController.prototype, | ||
| <any>"acquireTokenSilentAsync" | ||
| ).mockResolvedValue({ | ||
| fromCache: true, | ||
| accessToken: "abc", | ||
| idToken: "defg", | ||
| account: testAccount, | ||
| }); | ||
|
|
||
| const callbackId = pca.addPerformanceCallback((events) => { | ||
| expect(events[0].success).toBe(true); | ||
| expect(events[0].accountSource).toBe("external"); | ||
|
|
||
| pca.removePerformanceCallback(callbackId); | ||
| done(); | ||
| }); | ||
|
|
||
| pca.acquireTokenSilent(silentRequest); | ||
| }); | ||
|
|
||
| it("emits expect performance event when successful in case of network request", (done) => { | ||
| const testAccount: AccountInfo = { | ||
| homeAccountId: TEST_DATA_CLIENT_INFO.TEST_HOME_ACCOUNT_ID, | ||
|
|
@@ -6508,7 +6562,9 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { | |
| describe("hydrateCache tests", () => { | ||
| const testAccount: AccountInfo = { | ||
| ...AccountEntityUtils.getAccountInfo( | ||
| buildAccountFromIdTokenClaims(ID_TOKEN_CLAIMS) | ||
| buildAccountFromIdTokenClaims(ID_TOKEN_CLAIMS, undefined, { | ||
| accountSource: "pwb", | ||
| }) | ||
| ), | ||
| idTokenClaims: ID_TOKEN_CLAIMS, | ||
| idToken: TEST_TOKENS.IDTOKEN_V2, | ||
|
|
||
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.