-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[msal-node] Cache-1: Msal node cache entities #1444
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
Merged
Merged
Changes from 34 commits
Commits
Show all changes
109 commits
Select commit
Hold shift + click to select a range
076ecb3
Adding knownAuthorities() and B2CAuthority
sameerag 679425b
Merge branch 'msal-node-logging' into msal-node-authority
sameerag c4fe6c0
addressing feedback and in sync with PR #1416
sameerag 4d31901
Merge branch 'sagonzal/device-code' into msal-node-authority
sameerag 7a9cefc
Update package.json
sameerag b846ebc
Merge branch 'sagonzal/device-code' into msal-node-authority
sameerag ae43cea
addressing feedback
sameerag eb02ba3
Cache entities
sameerag b66e3dd
Add Account
sameerag fda585d
Add AccountCache
sameerag 9868ae0
Cache helpers and Serialization Code
sameerag a66906f
Fix a bug in AuthorityFactory.ts
sameerag 4a6fc0f
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag 33efd5d
Add tests and merge msal-node-tests
sameerag cb2cf62
Merge remote-tracking branch 'origin/sagonzal/msal-node-tests' into m…
sameerag 5a680a6
merge msal-node-tests
sameerag 80b2e1d
remove log stmt
sameerag 2662d04
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag 890ed57
Merge branch 'msal-node-logging' into msal-node-authority
sameerag 5228945
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag 61569c9
More serialization code
sameerag 735ace6
Merge branch 'msal-node-logging' into msal-node-authority
sameerag 9001c8b
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag 8834420
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag 75f5e8e
Serialize, Deserialize code, unit tests
sameerag ca9bc66
Merge branch 'msal-node-logging' into msal-node-authority
sameerag e93edb0
Add unit tests fpr authority changes
sameerag ea8cf9a
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag 85387c1
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag 888c13c
Update UT for AccessTokenEntity
sameerag f0255ee
Initial changes
sameerag 0512a01
Merge branch 'msal-node-cache-utils' into msal-node-cache-generator
sameerag 2a23b57
Addressing feedback and fixing tests
sameerag fb4c5cf
Initiate knownAuthorities in msal-node
sameerag aed2a50
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag 6a59e1f
Merge branch 'msal-node-base' into msal-node-cache-entities
sameerag 7bea70c
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag f58fa41
git merge msal-node-logging
sameerag 0fdafe9
Merge branch 'msal-node-authority' into msal-node-cache-utils
sameerag 67311ff
Add client_info for tokenResponse
sameerag 60523ee
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag ebf12b2
rename folder, address feedback
sameerag c004275
Merge branch 'msal-node-logging' into msal-node-authority
sameerag b0d8ad9
Merge branch 'msal-node-authority' into msal-node-cache-entities
sameerag 6cee693
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag 85e64c4
update cache folder name, move to generics
sameerag e90fda9
Address feedback
sameerag 1124a56
Merge branch 'msal-node-cache-utils' into msal-node-cache-generator
sameerag 8633ceb
add client_info in response
sameerag 2dd9672
Adding ResponseHandler, AuthenticationResult generation and Credentia…
sameerag 00d639e
All changes - will create separate PRs later
sameerag b974367
End-to-End cache read/write working
sameerag b9badaa
Optimization to serialization/deserialization
sameerag 461a8c5
Merge branch 'msal-node-cache-utils' into msal-node-cache-generator
sameerag 5bf084e
Address feedback in function names
sameerag 3371ff5
More changes for the demo
sameerag 516d004
Cache PR - Add Storage, token generation and rename response
sameerag 185be7c
Response Initial changes
sameerag 4f98589
Update node with result type
sameerag bf00ed5
Final changes for cache end-to-end Phase-I
sameerag 29b4210
Update CacheTypes include
sameerag 32b30b7
Updated tests
sameerag 5c62e0d
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag 813a341
Remove dup types
sameerag 8169a5b
Added tests; Updated feedback response
sameerag f519782
Adding more tests
sameerag 5cc8f0a
Merge branch 'msal-node-base' into msal-node-cache-entities
sameerag f61a4e8
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag 62ba010
Merge branch 'msal-node-cache-utils' into msal-node-response-cacheTokens
sameerag 4e32965
Addressing feedback
sameerag 53d2200
Merge branch 'msal-node-response-cacheTokens' into msal-node-response
sameerag 8f93841
addressing comments
sameerag 75877aa
Merge branch 'msal-node-response' into msal-node-cache-final
sameerag e4c1316
Update Storage.ts
sameerag 49908e6
Merge branch 'msal-node-response' into msal-node-cache-final
sameerag 63f4e44
Fixing compiler issues
sameerag 7b67e10
Merge branch 'dev' into msal-node-cache-entities
sameerag daef4b6
update as per dev
sameerag 5b06d3e
Merge branch 'msal-node-cache-entities' into msal-node-cache-utils
sameerag a459a2f
Merge branch 'msal-node-cache-utils' into msal-node-response-cacheTokens
sameerag df671bb
Fixing compiler issues
sameerag cbf1105
Merge branch 'msal-node-response-cacheTokens' into msal-node-response
sameerag cfa4b6d
Merge branch 'msal-node-response' into msal-node-cache-final
sameerag 36ac337
remove duplicate declaration in merge
sameerag 4c77d1c
Merge pull request #1522 from AzureAD/msal-node-cache-final
sameerag 5e4d601
Merge pull request #1520 from AzureAD/msal-node-response
sameerag cf6df64
Merge pull request #1519 from AzureAD/msal-node-response-cacheTokens
sameerag de5e99c
Merge pull request #1471 from AzureAD/msal-node-cache-utils
sameerag bbe3f84
Merge code, aync read/write
sameerag 07df0a6
Update function names in default Config
sameerag e88e95d
Adding test support
sameerag 2103928
Fix linter errors
sameerag d6baa29
remove unused type
sameerag 19eb25a
fix linter issue in browser storage
sameerag b9d63a8
Merge branch 'dev' into msal-node-cache-fileops-async
sameerag 9f88651
Add dev changes to SPAResponseHandler
sameerag 18d5c1c
Update commented code
sameerag 789fb45
Updateds for browser tests
sameerag e0a2422
Merge branch 'dev' into msal-node-cache-entities
sameerag 7258a04
Merge branch 'msal-node-cache-entities' into msal-node-cache-fileops-…
sameerag 000c646
Update sample with writeToDisk and mark file lock APIs
sameerag db845ff
merge dev into branch
DarylThayil 98d4b65
remove file read and write from node lib
DarylThayil 73ebd27
Merge pull request #1652 from AzureAD/removefile
DarylThayil daa1da9
Merge branch 'dev' into msal-node-cache-entities
sameerag adae586
Merge pull request #1622 from AzureAD/msal-node-cache-fileops-async
sameerag c03d8eb
Merge branch 'msal-node-cache-entities' of https://github.com/AzureAD…
sameerag 93f0021
Update Storage
sameerag b6803ba
fix linter/tests to merge to dev
sameerag 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
import { Authority } from "./Authority"; | ||
import { AuthorityType } from "./AuthorityType"; | ||
import { ClientConfigurationError } from "../error/ClientConfigurationError"; | ||
import { INetworkModule } from "../network/INetworkModule"; | ||
|
||
export const B2CTrustedHostList: string[] = []; | ||
|
||
/** | ||
* The AadAuthority class extends the Authority class and adds functionality specific to the Azure AD OAuth Authority. | ||
*/ | ||
export class B2cAuthority extends Authority { | ||
// Set authority type to AAD | ||
public get authorityType(): AuthorityType { | ||
return AuthorityType.B2C; | ||
} | ||
|
||
public constructor(authority: string, networkInterface: INetworkModule) { | ||
super(authority, networkInterface); | ||
} | ||
|
||
/** | ||
* Returns a promise which resolves to the OIDC endpoint | ||
* Only responds with the endpoint | ||
*/ | ||
public async getOpenIdConfigurationEndpointAsync(): Promise<string> { | ||
if (this.isInTrustedHostList(this.canonicalAuthorityUrlComponents.HostNameAndPort)) { | ||
return this.defaultOpenIdConfigurationEndpoint; | ||
} | ||
|
||
throw ClientConfigurationError.createUntrustedAuthorityError(); | ||
} | ||
|
||
/** | ||
* Checks to see if the host is in a list of trusted hosts | ||
* @param {string} The host to look up | ||
*/ | ||
private isInTrustedHostList(host: string): boolean { | ||
return B2CTrustedHostList.includes(host); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { Credential } from "./Credential"; | ||
import { Separators } from "../../utils/Constants"; | ||
|
||
/** | ||
* ACCESS_TOKEN Credential Type | ||
*/ | ||
export class AccessTokenEntity extends Credential { | ||
realm: string; | ||
target: string; | ||
cachedAt: string; | ||
expiresOn: string; | ||
extendedExpiresOn?: string; | ||
refreshOn?: string; | ||
keyId?: string; // for POP and SSH tokenTypes | ||
tokenType?: string; | ||
|
||
/** | ||
* Generate Account Cache Key as per the schema: <home_account_id>-<environment>-<realm*> | ||
*/ | ||
public generateAccessTokenEntityKey(): string { | ||
const accessTokenKeyArray: Array<string> = [ | ||
this.homeAccountId, | ||
this.environment, | ||
this.credentialType, | ||
this.clientId, | ||
this.realm, | ||
this.target | ||
]; | ||
|
||
return accessTokenKeyArray.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase(); | ||
} | ||
} |
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,95 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { Separators, CacheAccountType } from "../../utils/Constants"; | ||
import { Authority } from "../../authority/Authority"; | ||
import { IdToken } from "../../account/IdToken"; | ||
import { ICrypto } from "../../crypto/ICrypto"; | ||
import { buildClientInfo } from "../../account/ClientInfo"; | ||
import { StringUtils } from "../../utils/StringUtils"; | ||
|
||
/** | ||
* Type that defines required and optional parameters for an Account field (based on universal cache schema implemented by all MSALs) | ||
*/ | ||
export class AccountEntity { | ||
homeAccountId: string; | ||
environment: string; | ||
realm: string; | ||
localAccountId: string; | ||
username: string; | ||
authorityType: string; | ||
name?: string; | ||
clientInfo?: string; | ||
lastModificationTime?: string; | ||
lastModificationApp?: string; | ||
|
||
/** | ||
* Generate Account Cache Key as per the schema: <home_account_id>-<environment>-<realm*> | ||
*/ | ||
public generateAccountEntityKey(): string { | ||
const accountCacheKeyArray: Array<string> = [ | ||
this.homeAccountId, | ||
this.environment, | ||
this.realm | ||
]; | ||
|
||
return accountCacheKeyArray.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase(); | ||
} | ||
|
||
/** | ||
* Build Account cache from IdToken, clientInfo and authority/policy | ||
* @param clientInfo | ||
* @param authority | ||
* @param idToken | ||
* @param policy | ||
*/ | ||
static createAccount(clientInfo: string, authority: Authority, idToken: IdToken, policy: string, crypto: ICrypto): AccountEntity { | ||
let account: AccountEntity; | ||
|
||
account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE; | ||
account.clientInfo = clientInfo; | ||
// TBD: Clarify "policy" addition | ||
const clientInfoObj = buildClientInfo(clientInfo, crypto); | ||
const homeAccountId = `${clientInfoObj.uid}${Separators.CLIENT_INFO_SEPARATOR}${clientInfoObj.utid}`; | ||
account.homeAccountId = | ||
policy != null | ||
? homeAccountId + Separators.CACHE_KEY_SEPARATOR + policy | ||
: homeAccountId; | ||
account.environment = | ||
authority.canonicalAuthorityUrlComponents.HostNameAndPort; | ||
account.realm = authority.tenant; | ||
|
||
if (idToken) { | ||
// How do you account for MSA CID here? | ||
const localAccountId = !StringUtils.isEmpty(idToken.claims.oid) | ||
? idToken.claims.oid | ||
: idToken.claims.sid; | ||
account.localAccountId = localAccountId; | ||
account.username = idToken.claims.preferred_username; | ||
account.name = idToken.claims.name; | ||
} | ||
|
||
return account; | ||
} | ||
|
||
/** | ||
* Build ADFS account type | ||
* @param authority | ||
* @param idToken | ||
*/ | ||
static createADFSAccount(authority: Authority, idToken: IdToken): AccountEntity { | ||
let account: AccountEntity; | ||
|
||
account.authorityType = CacheAccountType.ADFS_ACCOUNT_TYPE; | ||
account.homeAccountId = idToken.claims.sub; | ||
account.environment = | ||
authority.canonicalAuthorityUrlComponents.HostNameAndPort; | ||
account.username = idToken.claims.upn; | ||
// add uniqueName to claims | ||
// account.name = idToken.claims.uniqueName; | ||
|
||
return account; | ||
} | ||
} |
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.
!==
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.
And does this need to check specifically for
null
? Or can it be this: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.
I am not sure about this as we do not track "policy" for B2C, this code is mostly for compliance with java. I will get back to this once I clarify the requirement.
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.
Will handle this over a different PR once the requirement is clear.