-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[msal-node] Cache Lookup - 1: Logical keys for cache entities #1624
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
Changes from 9 commits
446258d
8b86a3d
82e11c8
4ff2f5f
6948e41
ddee5c4
a456a67
398802f
5863af0
c3d30dd
6f9565b
4ddae07
2b0afe1
953e638
7ca83ab
87ce032
06ecbaf
d109982
7369e51
9649a91
703b6c1
e19fdad
5b66edc
87fa687
1660b16
403e81a
bdd0162
036ac45
ef1f729
2da03d9
533a907
4dcd69d
3da2e57
4a4dc16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,62 @@ | |
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { Separators, CredentialType } from "../../utils/Constants"; | ||
|
||
/** | ||
* Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc | ||
*/ | ||
export class Credential { | ||
homeAccountId: string; | ||
environment: string; | ||
credentialType: string; | ||
credentialType: CredentialType; | ||
clientId: string; | ||
secret: string; | ||
}; | ||
familyId?: string; | ||
realm?: string; | ||
target?: string; | ||
|
||
/** | ||
* Generate Account Id key component as per the schema: <home_account_id>-<environment> | ||
*/ | ||
generateAccountId(): string { | ||
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. Can these be used as utils for cache lookup (i.e. generate keys for looking up a specific cred)? 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. So generating accountId for an account object instance should be separate from generating it from a set of values. I will try coming up with common code as needed, for now I added static helpers in |
||
const accountId: Array<string> = [this.homeAccountId, this.environment]; | ||
return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase(); | ||
} | ||
|
||
/** | ||
* Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm> | ||
*/ | ||
generateCredentialId(): string { | ||
const clientOrFamilyId = CredentialType.REFRESH_TOKEN | ||
? this.familyId || this.clientId | ||
: this.clientId; | ||
const credentialId: Array<string> = [ | ||
this.credentialType, | ||
clientOrFamilyId, | ||
this.realm || "", | ||
]; | ||
|
||
return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase(); | ||
} | ||
|
||
/** | ||
* Generate target key component as per schema: <target> | ||
*/ | ||
generateTarget(): string { | ||
return (this.target || "").toLowerCase(); | ||
} | ||
|
||
/** | ||
* generates credential key | ||
*/ | ||
generateCredentialKey(): string { | ||
const credentialKey = [ | ||
this.generateAccountId(), | ||
this.generateCredentialId(), | ||
this.generateTarget(), | ||
]; | ||
|
||
return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase(); | ||
} | ||
} |
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 think empty space is used in multiple places, consider adding it to the constants file
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.
+1 for EMPTY_STRING constant