-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add support for Multi-tenant accounts and cross-tenant token caching #6536
Merged
Merged
Changes from all commits
Commits
Show all changes
124 commits
Select commit
Hold shift + click to select a range
33d94a6
Remove ID token claims from account entity before caching
hectormmg 8b7e6ad
Refactor getAllAccounts to remove duplicated logic
hectormmg 13b2f8b
Persist authority metadata in temporary cache to make it available fo…
hectormmg 4c1f845
Update getAccount APIs to only return accounts if there's a matching …
hectormmg 9ea89fd
Update tests to reflect authority metadata caching changes
hectormmg 14a1181
Merge branch 'dev' into cached-account-change
hectormmg d747689
Revert authority metadata storage to in-memory cache and add a synchr…
hectormmg dd78466
Merge branch 'dev' into cached-account-change
hectormmg 6149773
Change files
hectormmg 1c73768
Remove unused authority metadata removal method
hectormmg efdfff0
Remove unused method from cachemanager
hectormmg 2f35887
Load local authority metadata in MSAL Node PCA
hectormmg 1b53577
Change files
hectormmg dbc7d8c
Add multi-tenant sample
hectormmg 6e964e2
Update change/@azure-msal-node-695c255d-9b72-4c81-b93a-886e651da57a.json
hectormmg 2888e74
Add support for cross-tenant token caching and multi-tenant accounts
hectormmg a4cad18
Merge branch 'cached-account-change' into enable-multi-tenant
hectormmg 774603e
Merge branch 'dev' into cached-account-change
hectormmg 2acc32d
Update getAccount API tests to use test ID token secrets instead of a…
hectormmg a28dab5
Update tests to reflect account caching changes for multi-tenant support
hectormmg 3ba2016
Merge branch 'enable-multi-tenant' of github.com:AzureAD/microsoft-au…
hectormmg de492e1
Merge branch 'cached-account-change' into enable-multi-tenant
hectormmg 48b8ed7
Update multi-tenant sample
hectormmg d3361b6
Merge branch 'dev' into cached-account-change
hectormmg f61a563
Merge branch 'dev' into cached-account-change
hectormmg 1c1b582
Use static authority options from configuration and hardcoded metadat…
hectormmg 2f7621c
Update lib/msal-browser/test/interaction_client/BaseInteractionClient…
hectormmg 69ebbea
Refactor active account logic and native account lookup
hectormmg 84c69c2
Merge branch 'dev' into cached-account-change
hectormmg c7ffc41
Fix cloud discovery metadata static config processing
hectormmg fff6198
Make sure id token claims are excluded from accounts to be cached but…
hectormmg 7fff7fc
Clean up static authority options code
hectormmg aacea06
Undo pre-caching idtokenclaims removal for accounts
hectormmg 5a40a66
Update lib/msal-common/src/response/ResponseHandler.ts
hectormmg 9001cee
Add environment filtering tests with static metadata and refactor res…
hectormmg 129b96f
Merge branch 'cached-account-change' of github.com:AzureAD/microsoft-…
hectormmg 13ba16d
Merge branch 'dev' into cached-account-change
hectormmg ebdbacc
Merge branch 'cached-account-change' into enable-multi-tenant
hectormmg 9f9af08
Add tenant list assignment to AccountEntity.createFromAccountInfo
hectormmg 08111cd
Update node serialization/deserialization to include tenants list
hectormmg ad67c66
Factor out getTenantFromAuthorityString into an exported function
hectormmg 6f50405
Fix mock client info parsing in node ClientTestUtils
hectormmg 8273740
Update node storage tests with new test cache keys
hectormmg 223cab9
Update Node PCA tests
hectormmg 54aa44c
Merge branch 'dev' into enable-multi-tenant
hectormmg f785dc1
Merge branch 'dev' into enable-multi-tenant
hectormmg 835e32f
Remove idTokenClaims from AccountEntity since ID token claims are not…
hectormmg b81b818
Make tenantId optional in active account filters
hectormmg b3ded6f
Add account cache update from single tenant to multi-tenant
hectormmg 140295e
Add outdated (single-tenant) account update logic when cached account…
hectormmg d508aa8
Address PR feedback
hectormmg fc7b14d
Address PR feedback
hectormmg 191ef0b
Fix B2C ID token matching by removing account tenantId from ID token …
hectormmg d805248
Merge branch 'dev' into enable-multi-tenant
hectormmg d517757
Merge branch 'dev' into enable-multi-tenant
hectormmg 6f6fda9
Change files
hectormmg e58470a
Fix B2C and named tenant cross-tenant caching and lookup
hectormmg 0cfe01e
Update common unit tests
hectormmg dda7588
Update common, browser and node unit tests
hectormmg 142be3a
Merge branch 'dev' into enable-multi-tenant
hectormmg af6130b
Update browser cache test utils to use utid from idToken homeAccountI…
hectormmg 6554303
Add ID token duplicate removal logic
hectormmg d35b27d
Merge branch 'dev' into enable-multi-tenant
hectormmg 276d2bd
Set sample to localstorage
hectormmg 41be4ae
Merge branch 'dev' into enable-multi-tenant
hectormmg f9d1797
Add tenant profile maps
hectormmg 99d45a7
Merge branch 'dev' into enable-multi-tenant
hectormmg 8894041
Add migration logic from single-tenant to multi-tenant account entities
hectormmg ec1d5ae
Merge branch 'dev' into enable-multi-tenant
hectormmg f9dae3c
Update account APIs to return all tenant profiles as overriden accoun…
hectormmg 15162ca
Update common tests
hectormmg 4a6a186
Merge branch 'enable-multi-tenant' of github.com:AzureAD/microsoft-au…
hectormmg 587a9e1
Merge branch 'dev' into enable-multi-tenant
hectormmg 90f6e02
Factor setCachedAccount out into an exported function in ResponseHand…
hectormmg 572c28d
Update msal-node to use tenantProfiles in serialization instead of te…
hectormmg c9e8a18
Replace encoding test constants
hectormmg 6721a3a
Prettify test cache file
hectormmg 3ea2dd8
Fix b2c tests by using msal-node serializer instead of outdated e2e-t…
hectormmg 877ad7e
Merge branch 'dev' into enable-multi-tenant
hectormmg be6b7ab
Add tests for Authority Utility functions
hectormmg bf45c12
Increase test coverage in CacheManager
hectormmg 01d3793
Add TokenClaims utilties tests
hectormmg 3a62e4e
Increase test coverage for AccountEntity
hectormmg 932594c
Add multi-tenant docs first draft
hectormmg 17301aa
Update multi-tenant docs
hectormmg 662b20a
Add multi-tenant reference to node and browser docs
hectormmg 09a95af
Merge branch 'dev' into enable-multi-tenant
hectormmg 30b4488
Update lib/msal-browser/test/cache/TestStorageManager.ts
hectormmg 82dc1e9
Address PR feedback
hectormmg 8c35085
Merge branch 'enable-multi-tenant' of github.com:AzureAD/microsoft-au…
hectormmg d609c6f
Update base64Decode in buildClientInfo usages
hectormmg 2e09ae5
Fix formatting
hectormmg d17fc59
Update docs
hectormmg e24ce71
Update lib/msal-common/docs/multi-tenant-accounts.md
hectormmg fda2f57
Update multi-tenant docs from feedback
hectormmg df39511
Merge branch 'enable-multi-tenant' of github.com:AzureAD/microsoft-au…
hectormmg e77b98a
Merge branch 'dev' into enable-multi-tenant
hectormmg f2a21de
Address PR feedback
hectormmg 1c3d33e
Merge branch 'enable-multi-tenant' of github.com:AzureAD/microsoft-au…
hectormmg c2038db
Merge branch 'dev' into enable-multi-tenant
hectormmg 4b1bf37
Update multi-tenant account docs
hectormmg c3bb735
Replace cryptoObj.base64Decode with original base64Decode function
hectormmg 585b9e3
Merge branch 'enable-multi-tenant' of github.com:AzureAD/microsoft-au…
hectormmg 36c9f1a
Add multi-tenant e2e tests
hectormmg 78b5d9a
Update test utils
hectormmg 8a8623c
Remove multi-tenant sample app
hectormmg fe405c4
Update browser cache test utils to ignore pop tokens in accessTokenFo…
hectormmg 0ff394c
Hide http request log in VanillaJSTestApp when running customizable-e…
hectormmg d873cbf
Fix realm matching logic in CacheManager
hectormmg 75c576a
Update customizable-e2e-sample to use activeAccount
hectormmg 9e476fb
Refactor verifyTokenStore browser cache util
hectormmg 21ac601
Fix multi-tenant e2e tests
hectormmg cbc4454
Fix BrowserCacheTestUtils typing
hectormmg 3465668
Update test utils to avoid undefined assignments
hectormmg a9afc38
Update test utils
hectormmg 6ad097f
Fix ignorable ts error in BrowserCacheTestUtils
hectormmg d65cbeb
Fix browser cache test utils for angular e2e
hectormmg 662cd52
Use check-latest on setup node
hectormmg f2f3519
Move account and ID token creation test utils to a shared-test-utils dir
hectormmg 900155a
Add shared msal config package
hectormmg d452fb0
Merge branch 'dev' into enable-multi-tenant
hectormmg e27fff7
Add shared-utils to workspaces
hectormmg 8363d22
Update package-lock
hectormmg 561f8e7
Merge branch 'dev' into enable-multi-tenant
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-79eee614-ede9-45f3-b008-5fa2b8a7ecf3.json
This file contains 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 support for Multi-tenant accounts and cross-tenant token caching #6466", | ||
"packageName": "@azure/msal-browser", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-common-8efe538a-488d-46f1-b1ea-f1bdea1ad4ae.json
This file contains 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 support for Multi-tenant accounts and cross-tenant token caching #6466", | ||
"packageName": "@azure/msal-common", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-node-fd8922d0-15cd-4b36-b209-0810fd9a67d6.json
This file contains 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 support for Multi-tenant accounts and cross-tenant token caching #6466", | ||
"packageName": "@azure/msal-node", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
CacheRecord, | ||
TokenClaims, | ||
CacheHelpers, | ||
buildAccountToCache, | ||
} from "@azure/msal-common"; | ||
import { BrowserConfiguration } from "../config/Configuration"; | ||
import { SilentRequest } from "../request/SilentRequest"; | ||
|
@@ -240,40 +241,43 @@ export class TokenCache implements ITokenCache { | |
clientInfo?: string, | ||
requestHomeAccountId?: string | ||
): AccountEntity { | ||
let homeAccountId; | ||
if (requestHomeAccountId) { | ||
homeAccountId = requestHomeAccountId; | ||
} else if (authority.authorityType !== undefined && clientInfo) { | ||
homeAccountId = AccountEntity.generateHomeAccountId( | ||
clientInfo, | ||
authority.authorityType, | ||
this.logger, | ||
this.cryptoObj, | ||
idTokenClaims | ||
); | ||
} | ||
if (this.isBrowserEnvironment) { | ||
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. Moved the check up here before all the work is done instead of checking after building the account and then throwing |
||
this.logger.verbose("TokenCache - loading account"); | ||
let homeAccountId; | ||
if (requestHomeAccountId) { | ||
homeAccountId = requestHomeAccountId; | ||
} else if (authority.authorityType !== undefined && clientInfo) { | ||
homeAccountId = AccountEntity.generateHomeAccountId( | ||
clientInfo, | ||
authority.authorityType, | ||
this.logger, | ||
this.cryptoObj, | ||
idTokenClaims | ||
); | ||
} | ||
|
||
if (!homeAccountId) { | ||
throw createBrowserAuthError( | ||
BrowserAuthErrorCodes.unableToLoadToken | ||
); | ||
} | ||
if (!homeAccountId) { | ||
throw createBrowserAuthError( | ||
BrowserAuthErrorCodes.unableToLoadToken | ||
); | ||
} | ||
const claimsTenantId = idTokenClaims.tid; | ||
|
||
const accountEntity = AccountEntity.createAccount( | ||
{ | ||
const cachedAccount = buildAccountToCache( | ||
this.storage, | ||
authority, | ||
homeAccountId, | ||
idTokenClaims: idTokenClaims, | ||
idTokenClaims, | ||
base64Decode, | ||
clientInfo, | ||
environment: authority.hostnameAndPort, | ||
}, | ||
authority | ||
); | ||
|
||
if (this.isBrowserEnvironment) { | ||
this.logger.verbose("TokenCache - loading account"); | ||
claimsTenantId, | ||
undefined, | ||
undefined, | ||
this.logger | ||
); | ||
|
||
this.storage.setAccount(accountEntity); | ||
return accountEntity; | ||
this.storage.setAccount(cachedAccount); | ||
return cachedAccount; | ||
} else { | ||
throw createBrowserAuthError( | ||
BrowserAuthErrorCodes.unableToLoadToken | ||
|
This file contains 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 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 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.
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.
Can you use the existing removeAccount API instead? Should do the same things
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.
Unfortunately that method is async and also removes all tokens related to the account context, I'll try to find a way to factor out the part that removes the account object only.
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.
Ah thats right ok. Nvm this can stay.
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.
Can we rename it to removeAccountOnly() as a sync function and call it inside
removeAccount
? Can be done later, I think that is viable and removes code duplicityThere 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.
Name is fine. Just reusing is what I want to focus on.