@azure/msal-common 14.2.0 → 14.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/account/AuthToken.mjs +1 -1
  2. package/dist/account/CcsCredential.mjs +1 -1
  3. package/dist/account/ClientInfo.mjs +1 -1
  4. package/dist/authority/Authority.d.ts.map +1 -1
  5. package/dist/authority/Authority.mjs +3 -3
  6. package/dist/authority/AuthorityFactory.mjs +1 -1
  7. package/dist/authority/AuthorityMetadata.d.ts +29 -172
  8. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  9. package/dist/authority/AuthorityMetadata.mjs +79 -413
  10. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  11. package/dist/authority/AuthorityOptions.d.ts +2 -2
  12. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  13. package/dist/authority/AuthorityOptions.mjs +1 -1
  14. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  15. package/dist/authority/AuthorityType.mjs +1 -1
  16. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  17. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  18. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  19. package/dist/authority/ProtocolMode.mjs +1 -1
  20. package/dist/authority/RegionDiscovery.mjs +1 -1
  21. package/dist/cache/CacheManager.d.ts.map +1 -1
  22. package/dist/cache/CacheManager.mjs +16 -11
  23. package/dist/cache/CacheManager.mjs.map +1 -1
  24. package/dist/cache/entities/AccessTokenEntity.d.ts +12 -43
  25. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  26. package/dist/cache/entities/AccountEntity.mjs +1 -1
  27. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  28. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  29. package/dist/cache/entities/CacheRecord.mjs +1 -1
  30. package/dist/cache/entities/CredentialEntity.d.ts +15 -73
  31. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  32. package/dist/cache/entities/IdTokenEntity.d.ts +4 -30
  33. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  34. package/dist/cache/entities/RefreshTokenEntity.d.ts +2 -33
  35. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  36. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  37. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  38. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  39. package/dist/cache/utils/CacheHelpers.d.ts +59 -0
  40. package/dist/cache/utils/CacheHelpers.d.ts.map +1 -0
  41. package/dist/cache/utils/CacheHelpers.mjs +226 -0
  42. package/dist/cache/utils/CacheHelpers.mjs.map +1 -0
  43. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  44. package/dist/client/AuthorizationCodeClient.mjs +2 -2
  45. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  46. package/dist/client/BaseClient.d.ts +1 -1
  47. package/dist/client/BaseClient.d.ts.map +1 -1
  48. package/dist/client/BaseClient.mjs +8 -8
  49. package/dist/client/BaseClient.mjs.map +1 -1
  50. package/dist/client/RefreshTokenClient.mjs +1 -1
  51. package/dist/client/SilentFlowClient.mjs +1 -1
  52. package/dist/config/ClientConfiguration.mjs +1 -1
  53. package/dist/crypto/ICrypto.mjs +1 -1
  54. package/dist/crypto/JoseHeader.mjs +1 -1
  55. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  56. package/dist/error/AuthError.mjs +1 -1
  57. package/dist/error/AuthErrorCodes.mjs +1 -1
  58. package/dist/error/ClientAuthError.mjs +1 -1
  59. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  60. package/dist/error/ClientConfigurationError.mjs +1 -1
  61. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  62. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  63. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  64. package/dist/error/JoseHeaderError.mjs +1 -1
  65. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  66. package/dist/error/ServerError.mjs +1 -1
  67. package/dist/index.cjs +2632 -3105
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.ts +1 -0
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.mjs +3 -5
  72. package/dist/index.mjs.map +1 -1
  73. package/dist/logger/Logger.mjs +1 -1
  74. package/dist/network/INetworkModule.mjs +1 -1
  75. package/dist/network/NetworkManager.mjs +1 -1
  76. package/dist/network/ThrottlingUtils.mjs +1 -1
  77. package/dist/packageMetadata.d.ts +1 -1
  78. package/dist/packageMetadata.mjs +2 -2
  79. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  80. package/dist/request/RequestParameterBuilder.mjs +1 -1
  81. package/dist/request/RequestValidator.mjs +1 -1
  82. package/dist/request/ScopeSet.mjs +1 -1
  83. package/dist/response/ResponseHandler.d.ts +2 -2
  84. package/dist/response/ResponseHandler.d.ts.map +1 -1
  85. package/dist/response/ResponseHandler.mjs +23 -29
  86. package/dist/response/ResponseHandler.mjs.map +1 -1
  87. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  88. package/dist/telemetry/performance/PerformanceEvent.mjs +1 -1
  89. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  90. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  91. package/dist/url/UrlString.mjs +1 -1
  92. package/dist/utils/Constants.mjs +1 -1
  93. package/dist/utils/FunctionWrappers.mjs +1 -1
  94. package/dist/utils/ProtocolUtils.mjs +1 -1
  95. package/dist/utils/StringUtils.mjs +1 -1
  96. package/dist/utils/TimeUtils.mjs +1 -1
  97. package/package.json +1 -1
  98. package/src/authority/Authority.ts +3 -5
  99. package/src/authority/AuthorityMetadata.ts +109 -435
  100. package/src/authority/AuthorityOptions.ts +2 -2
  101. package/src/cache/CacheManager.ts +16 -20
  102. package/src/cache/entities/AccessTokenEntity.ts +13 -149
  103. package/src/cache/entities/CredentialEntity.ts +16 -200
  104. package/src/cache/entities/IdTokenEntity.ts +4 -64
  105. package/src/cache/entities/RefreshTokenEntity.ts +2 -69
  106. package/src/cache/utils/CacheHelpers.ts +306 -0
  107. package/src/client/AuthorizationCodeClient.ts +1 -2
  108. package/src/client/BaseClient.ts +21 -10
  109. package/src/index.ts +1 -0
  110. package/src/packageMetadata.ts +1 -1
  111. package/src/response/ResponseHandler.ts +36 -41
  112. package/dist/cache/entities/AccessTokenEntity.mjs +0 -121
  113. package/dist/cache/entities/AccessTokenEntity.mjs.map +0 -1
  114. package/dist/cache/entities/CredentialEntity.mjs +0 -145
  115. package/dist/cache/entities/CredentialEntity.mjs.map +0 -1
  116. package/dist/cache/entities/IdTokenEntity.mjs +0 -64
  117. package/dist/cache/entities/IdTokenEntity.mjs.map +0 -1
  118. package/dist/cache/entities/RefreshTokenEntity.mjs +0 -67
  119. package/dist/cache/entities/RefreshTokenEntity.mjs.map +0 -1
@@ -6,7 +6,7 @@
6
6
  import { ProtocolMode } from "./ProtocolMode";
7
7
  import { OIDCOptions } from "./OIDCOptions";
8
8
  import { AzureRegionConfiguration } from "./AzureRegionConfiguration";
9
- import { CloudDiscoveryMetadata } from "./CloudDiscoveryMetadata";
9
+ import { CloudInstanceDiscoveryResponse } from "./CloudInstanceDiscoveryResponse";
10
10
 
11
11
  export type AuthorityOptions = {
12
12
  protocolMode: ProtocolMode;
@@ -23,7 +23,7 @@ export type StaticAuthorityOptions = Partial<
23
23
  Pick<AuthorityOptions, "knownAuthorities">
24
24
  > & {
25
25
  canonicalAuthority?: string;
26
- cloudDiscoveryMetadata?: CloudDiscoveryMetadata[];
26
+ cloudDiscoveryMetadata?: CloudInstanceDiscoveryResponse;
27
27
  };
28
28
 
29
29
  export const AzureCloudInstance = {
@@ -21,6 +21,7 @@ import {
21
21
  Separators,
22
22
  } from "../utils/Constants";
23
23
  import { CredentialEntity } from "./entities/CredentialEntity";
24
+ import { generateCredentialKey } from "./utils/CacheHelpers";
24
25
  import { ScopeSet } from "../request/ScopeSet";
25
26
  import { AccountEntity } from "./entities/AccountEntity";
26
27
  import { AccessTokenEntity } from "./entities/AccessTokenEntity";
@@ -42,10 +43,7 @@ import { BaseAuthRequest } from "../request/BaseAuthRequest";
42
43
  import { Logger } from "../logger/Logger";
43
44
  import { name, version } from "../packageMetadata";
44
45
  import { StoreInCache } from "../request/StoreInCache";
45
- import {
46
- getAliasesFromConfigMetadata,
47
- getHardcodedAliasesForCanonicalAuthority,
48
- } from "../authority/AuthorityMetadata";
46
+ import { getAliasesFromStaticSources } from "../authority/AuthorityMetadata";
49
47
  import { StaticAuthorityOptions } from "../authority/AuthorityOptions";
50
48
  import { TokenClaims } from "../account/TokenClaims";
51
49
 
@@ -259,7 +257,13 @@ export abstract class CacheManager implements ICacheManager {
259
257
  */
260
258
  getAccountInfoFilteredBy(accountFilter: AccountFilter): AccountInfo | null {
261
259
  const allAccounts = this.getAllAccounts(accountFilter);
262
- if (allAccounts.length > 0) {
260
+ if (allAccounts.length > 1) {
261
+ // If one or more accounts are found, further filter to the first account that has an ID token
262
+ return allAccounts.filter((account) => {
263
+ return !!account.idTokenClaims;
264
+ })[0];
265
+ } else if (allAccounts.length === 1) {
266
+ // If only one account is found, return it regardless of whether a matching ID token was found
263
267
  return allAccounts[0];
264
268
  } else {
265
269
  return null;
@@ -303,7 +307,7 @@ export abstract class CacheManager implements ICacheManager {
303
307
  return accountInfo;
304
308
  }
305
309
  }
306
- return null;
310
+ return accountInfo;
307
311
  }
308
312
 
309
313
  private idTokenClaimsMatchAccountFilter(
@@ -957,7 +961,7 @@ export abstract class CacheManager implements ICacheManager {
957
961
  "CacheManager:getIdToken - Multiple id tokens found, clearing them"
958
962
  );
959
963
  idTokens.forEach((idToken) => {
960
- this.removeIdToken(idToken.generateCredentialKey());
964
+ this.removeIdToken(generateCredentialKey(idToken));
961
965
  });
962
966
  return null;
963
967
  }
@@ -1113,9 +1117,7 @@ export abstract class CacheManager implements ICacheManager {
1113
1117
  "CacheManager:getAccessToken - Multiple access tokens found, clearing them"
1114
1118
  );
1115
1119
  accessTokens.forEach((accessToken) => {
1116
- void this.removeAccessToken(
1117
- accessToken.generateCredentialKey()
1118
- );
1120
+ void this.removeAccessToken(generateCredentialKey(accessToken));
1119
1121
  });
1120
1122
  return null;
1121
1123
  }
@@ -1423,17 +1425,11 @@ export abstract class CacheManager implements ICacheManager {
1423
1425
  ): boolean {
1424
1426
  // Check static authority options first for cases where authority metadata has not been resolved and cached yet
1425
1427
  if (this.staticAuthorityOptions) {
1426
- const staticAliases =
1427
- getAliasesFromConfigMetadata(
1428
- this.staticAuthorityOptions.canonicalAuthority,
1429
- this.staticAuthorityOptions.cloudDiscoveryMetadata
1430
- ) ||
1431
- getHardcodedAliasesForCanonicalAuthority(
1432
- this.staticAuthorityOptions.canonicalAuthority
1433
- ) ||
1434
- this.staticAuthorityOptions.knownAuthorities;
1428
+ const staticAliases = getAliasesFromStaticSources(
1429
+ this.staticAuthorityOptions,
1430
+ this.commonLogger
1431
+ );
1435
1432
  if (
1436
- staticAliases &&
1437
1433
  staticAliases.includes(environment) &&
1438
1434
  staticAliases.includes(entity.environment)
1439
1435
  ) {
@@ -4,164 +4,28 @@
4
4
  */
5
5
 
6
6
  import { CredentialEntity } from "./CredentialEntity";
7
- import { CredentialType, AuthenticationScheme } from "../../utils/Constants";
8
- import { TimeUtils } from "../../utils/TimeUtils";
9
- import { ICrypto } from "../../crypto/ICrypto";
10
- import { TokenClaims } from "../../account/TokenClaims";
11
- import {
12
- createClientAuthError,
13
- ClientAuthErrorCodes,
14
- } from "../../error/ClientAuthError";
15
- import { extractTokenClaims } from "../../account/AuthToken";
7
+ import { AuthenticationScheme } from "../../utils/Constants";
16
8
 
17
9
  /**
18
- * ACCESS_TOKEN Credential Type
19
- *
20
- * Key:Value Schema:
21
- *
22
- * Key Example: uid.utid-login.microsoftonline.com-accesstoken-clientId-contoso.com-user.read
23
- *
24
- * Value Schema:
25
- * {
26
- * homeAccountId: home account identifier for the auth scheme,
27
- * environment: entity that issued the token, represented as a full host
28
- * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
29
- * clientId: client ID of the application
30
- * secret: Actual credential as a string
31
- * familyId: Family ID identifier, usually only used for refresh tokens
32
- * realm: Full tenant or organizational identifier that the account belongs to
33
- * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
34
- * cachedAt: Absolute device time when entry was created in the cache.
35
- * expiresOn: Token expiry time, calculated based on current UTC time in seconds. Represented as a string.
36
- * extendedExpiresOn: Additional extended expiry time until when token is valid in case of server-side outage. Represented as string in UTC seconds.
37
- * keyId: used for POP and SSH tokenTypes
38
- * tokenType: Type of the token issued. Usually "Bearer"
39
- * }
10
+ * Access token cache type
40
11
  */
41
- export class AccessTokenEntity extends CredentialEntity {
12
+ export type AccessTokenEntity = CredentialEntity & {
13
+ /** Full tenant or organizational identifier that the account belongs to */
42
14
  realm: string;
15
+ /** Permissions that are included in the token, or for refresh tokens, the resource identifier. */
43
16
  target: string;
17
+ /** Absolute device time when entry was created in the cache. */
44
18
  cachedAt: string;
19
+ /** Token expiry time, calculated based on current UTC time in seconds. Represented as a string. */
45
20
  expiresOn: string;
21
+ /** Additional extended expiry time until when token is valid in case of server-side outage. Represented as string in UTC seconds. */
46
22
  extendedExpiresOn?: string;
23
+ /** Used for proactive refresh */
47
24
  refreshOn?: string;
48
- keyId?: string; // for POP and SSH tokenTypes
25
+ /** Matches the authentication scheme for which the token was issued (i.e. Bearer or pop) */
49
26
  tokenType?: AuthenticationScheme;
27
+ /** Stringified claims object */
50
28
  requestedClaims?: string;
29
+ /** Matches the SHA 256 hash of the claims object included in the token request */
51
30
  requestedClaimsHash?: string;
52
-
53
- /**
54
- * Create AccessTokenEntity
55
- * @param homeAccountId
56
- * @param environment
57
- * @param accessToken
58
- * @param clientId
59
- * @param tenantId
60
- * @param scopes
61
- * @param expiresOn
62
- * @param extExpiresOn
63
- */
64
- static createAccessTokenEntity(
65
- homeAccountId: string,
66
- environment: string,
67
- accessToken: string,
68
- clientId: string,
69
- tenantId: string,
70
- scopes: string,
71
- expiresOn: number,
72
- extExpiresOn: number,
73
- cryptoUtils: ICrypto,
74
- refreshOn?: number,
75
- tokenType?: AuthenticationScheme,
76
- userAssertionHash?: string,
77
- keyId?: string,
78
- requestedClaims?: string,
79
- requestedClaimsHash?: string
80
- ): AccessTokenEntity {
81
- const atEntity: AccessTokenEntity = new AccessTokenEntity();
82
-
83
- atEntity.homeAccountId = homeAccountId;
84
- atEntity.credentialType = CredentialType.ACCESS_TOKEN;
85
- atEntity.secret = accessToken;
86
-
87
- const currentTime = TimeUtils.nowSeconds();
88
- atEntity.cachedAt = currentTime.toString();
89
-
90
- /*
91
- * Token expiry time.
92
- * This value should be  calculated based on the current UTC time measured locally and the value  expires_in Represented as a string in JSON.
93
- */
94
- atEntity.expiresOn = expiresOn.toString();
95
- atEntity.extendedExpiresOn = extExpiresOn.toString();
96
- if (refreshOn) {
97
- atEntity.refreshOn = refreshOn.toString();
98
- }
99
-
100
- atEntity.environment = environment;
101
- atEntity.clientId = clientId;
102
- atEntity.realm = tenantId;
103
- atEntity.target = scopes;
104
- atEntity.userAssertionHash = userAssertionHash;
105
-
106
- atEntity.tokenType = tokenType || AuthenticationScheme.BEARER;
107
-
108
- if (requestedClaims) {
109
- atEntity.requestedClaims = requestedClaims;
110
- atEntity.requestedClaimsHash = requestedClaimsHash;
111
- }
112
-
113
- /*
114
- * Create Access Token With Auth Scheme instead of regular access token
115
- * Cast to lower to handle "bearer" from ADFS
116
- */
117
- if (
118
- atEntity.tokenType?.toLowerCase() !==
119
- AuthenticationScheme.BEARER.toLowerCase()
120
- ) {
121
- atEntity.credentialType =
122
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
123
- switch (atEntity.tokenType) {
124
- case AuthenticationScheme.POP:
125
- // Make sure keyId is present and add it to credential
126
- const tokenClaims: TokenClaims | null = extractTokenClaims(
127
- accessToken,
128
- cryptoUtils.base64Decode
129
- );
130
- if (!tokenClaims?.cnf?.kid) {
131
- throw createClientAuthError(
132
- ClientAuthErrorCodes.tokenClaimsCnfRequiredForSignedJwt
133
- );
134
- }
135
- atEntity.keyId = tokenClaims.cnf.kid;
136
- break;
137
- case AuthenticationScheme.SSH:
138
- atEntity.keyId = keyId;
139
- }
140
- }
141
-
142
- return atEntity;
143
- }
144
-
145
- /**
146
- * Validates an entity: checks for all expected params
147
- * @param entity
148
- */
149
- static isAccessTokenEntity(entity: object): boolean {
150
- if (!entity) {
151
- return false;
152
- }
153
-
154
- return (
155
- entity.hasOwnProperty("homeAccountId") &&
156
- entity.hasOwnProperty("environment") &&
157
- entity.hasOwnProperty("credentialType") &&
158
- entity.hasOwnProperty("realm") &&
159
- entity.hasOwnProperty("clientId") &&
160
- entity.hasOwnProperty("secret") &&
161
- entity.hasOwnProperty("target") &&
162
- (entity["credentialType"] === CredentialType.ACCESS_TOKEN ||
163
- entity["credentialType"] ===
164
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME)
165
- );
166
- }
167
- }
31
+ };
@@ -3,218 +3,34 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import {
7
- Separators,
8
- CredentialType,
9
- CacheType,
10
- Constants,
11
- AuthenticationScheme,
12
- } from "../../utils/Constants";
13
- import {
14
- ClientAuthErrorCodes,
15
- createClientAuthError,
16
- } from "../../error/ClientAuthError";
6
+ import { CredentialType, AuthenticationScheme } from "../../utils/Constants";
17
7
 
18
8
  /**
19
- * Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
20
- *
21
- * Key:Value Schema:
22
- *
23
- * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
24
- *
25
- * Value Schema:
26
- * {
27
- * homeAccountId: home account identifier for the auth scheme,
28
- * environment: entity that issued the token, represented as a full host
29
- * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
30
- * clientId: client ID of the application
31
- * secret: Actual credential as a string
32
- * familyId: Family ID identifier, usually only used for refresh tokens
33
- * realm: Full tenant or organizational identifier that the account belongs to
34
- * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
35
- * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
36
- * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
37
- * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
38
- * }
9
+ * Credential Cache Type
39
10
  */
40
- export class CredentialEntity {
11
+ export type CredentialEntity = {
12
+ /** Identifier for the user in their home tenant*/
41
13
  homeAccountId: string;
14
+ /** Entity that issued the token, represented as a full host */
42
15
  environment: string;
16
+ /** Type of credential */
43
17
  credentialType: CredentialType;
18
+ /** Client ID of the application */
44
19
  clientId: string;
20
+ /** Actual credential as a string */
45
21
  secret: string;
22
+ /** Family ID identifier, usually only used for refresh tokens */
46
23
  familyId?: string;
24
+ /** Full tenant or organizational identifier that the account belongs to */
47
25
  realm?: string;
26
+ /** Permissions that are included in the token, or for refresh tokens, the resource identifier. */
48
27
  target?: string;
28
+ /** Matches the SHA 256 hash of the obo_assertion for the OBO flow */
49
29
  userAssertionHash?: string;
30
+ /** Matches the authentication scheme for which the token was issued (i.e. Bearer or pop) */
50
31
  tokenType?: AuthenticationScheme;
32
+ /** KeyId for PoP and SSH tokens stored in the kid claim */
51
33
  keyId?: string;
34
+ /** Matches the SHA 256 hash of the claims object included in the token request */
52
35
  requestedClaimsHash?: string;
53
-
54
- /**
55
- * Generate Account Id key component as per the schema: <home_account_id>-<environment>
56
- */
57
- generateAccountId(): string {
58
- return CredentialEntity.generateAccountIdForCacheKey(
59
- this.homeAccountId,
60
- this.environment
61
- );
62
- }
63
-
64
- /**
65
- * Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
66
- */
67
- generateCredentialId(): string {
68
- return CredentialEntity.generateCredentialIdForCacheKey(
69
- this.credentialType,
70
- this.clientId,
71
- this.realm,
72
- this.familyId
73
- );
74
- }
75
-
76
- /**
77
- * Generate target key component as per schema: <target>
78
- */
79
- generateTarget(): string {
80
- return CredentialEntity.generateTargetForCacheKey(this.target);
81
- }
82
-
83
- /**
84
- * generates credential key
85
- */
86
- generateCredentialKey(): string {
87
- return CredentialEntity.generateCredentialCacheKey(
88
- this.homeAccountId,
89
- this.environment,
90
- this.credentialType,
91
- this.clientId,
92
- this.realm,
93
- this.target,
94
- this.familyId,
95
- this.tokenType,
96
- this.requestedClaimsHash
97
- );
98
- }
99
-
100
- /**
101
- * returns the type of the cache (in this case credential)
102
- */
103
- generateType(): number {
104
- switch (this.credentialType) {
105
- case CredentialType.ID_TOKEN:
106
- return CacheType.ID_TOKEN;
107
- case CredentialType.ACCESS_TOKEN:
108
- case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
109
- return CacheType.ACCESS_TOKEN;
110
- case CredentialType.REFRESH_TOKEN:
111
- return CacheType.REFRESH_TOKEN;
112
- default: {
113
- throw createClientAuthError(
114
- ClientAuthErrorCodes.unexpectedCredentialType
115
- );
116
- }
117
- }
118
- }
119
-
120
- /**
121
- * generates credential key
122
- * <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
123
- */
124
- static generateCredentialCacheKey(
125
- homeAccountId: string,
126
- environment: string,
127
- credentialType: CredentialType,
128
- clientId: string,
129
- realm?: string,
130
- target?: string,
131
- familyId?: string,
132
- tokenType?: AuthenticationScheme,
133
- requestedClaimsHash?: string
134
- ): string {
135
- const credentialKey = [
136
- this.generateAccountIdForCacheKey(homeAccountId, environment),
137
- this.generateCredentialIdForCacheKey(
138
- credentialType,
139
- clientId,
140
- realm,
141
- familyId
142
- ),
143
- this.generateTargetForCacheKey(target),
144
- this.generateClaimsHashForCacheKey(requestedClaimsHash),
145
- this.generateSchemeForCacheKey(tokenType),
146
- ];
147
-
148
- return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
149
- }
150
-
151
- /**
152
- * generates Account Id for keys
153
- * @param homeAccountId
154
- * @param environment
155
- */
156
- private static generateAccountIdForCacheKey(
157
- homeAccountId: string,
158
- environment: string
159
- ): string {
160
- const accountId: Array<string> = [homeAccountId, environment];
161
- return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
162
- }
163
-
164
- /**
165
- * Generates Credential Id for keys
166
- * @param credentialType
167
- * @param realm
168
- * @param clientId
169
- * @param familyId
170
- */
171
- private static generateCredentialIdForCacheKey(
172
- credentialType: CredentialType,
173
- clientId: string,
174
- realm?: string,
175
- familyId?: string
176
- ): string {
177
- const clientOrFamilyId =
178
- credentialType === CredentialType.REFRESH_TOKEN
179
- ? familyId || clientId
180
- : clientId;
181
- const credentialId: Array<string> = [
182
- credentialType,
183
- clientOrFamilyId,
184
- realm || Constants.EMPTY_STRING,
185
- ];
186
-
187
- return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
188
- }
189
-
190
- /**
191
- * Generate target key component as per schema: <target>
192
- */
193
- private static generateTargetForCacheKey(scopes?: string): string {
194
- return (scopes || Constants.EMPTY_STRING).toLowerCase();
195
- }
196
-
197
- /**
198
- * Generate requested claims key component as per schema: <requestedClaims>
199
- */
200
- private static generateClaimsHashForCacheKey(
201
- requestedClaimsHash?: string
202
- ): string {
203
- return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
204
- }
205
-
206
- /**
207
- * Generate scheme key componenet as per schema: <scheme>
208
- */
209
- private static generateSchemeForCacheKey(tokenType?: string): string {
210
- /*
211
- * PoP Tokens and SSH certs include scheme in cache key
212
- * Cast to lowercase to handle "bearer" from ADFS
213
- */
214
- return tokenType &&
215
- tokenType.toLowerCase() !==
216
- AuthenticationScheme.BEARER.toLowerCase()
217
- ? tokenType.toLowerCase()
218
- : Constants.EMPTY_STRING;
219
- }
220
- }
36
+ };
@@ -4,71 +4,11 @@
4
4
  */
5
5
 
6
6
  import { CredentialEntity } from "./CredentialEntity";
7
- import { CredentialType } from "../../utils/Constants";
8
7
 
9
8
  /**
10
- * ID_TOKEN Cache
11
- *
12
- * Key:Value Schema:
13
- *
14
- * Key Example: uid.utid-login.microsoftonline.com-idtoken-clientId-contoso.com-
15
- *
16
- * Value Schema:
17
- * {
18
- * homeAccountId: home account identifier for the auth scheme,
19
- * environment: entity that issued the token, represented as a full host
20
- * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
21
- * clientId: client ID of the application
22
- * secret: Actual credential as a string
23
- * realm: Full tenant or organizational identifier that the account belongs to
24
- * }
9
+ * Id Token Cache Type
25
10
  */
26
- export class IdTokenEntity extends CredentialEntity {
11
+ export type IdTokenEntity = CredentialEntity & {
12
+ /** Full tenant or organizational identifier that the account belongs to */
27
13
  realm: string;
28
-
29
- /**
30
- * Create IdTokenEntity
31
- * @param homeAccountId
32
- * @param authenticationResult
33
- * @param clientId
34
- * @param authority
35
- */
36
- static createIdTokenEntity(
37
- homeAccountId: string,
38
- environment: string,
39
- idToken: string,
40
- clientId: string,
41
- tenantId: string
42
- ): IdTokenEntity {
43
- const idTokenEntity = new IdTokenEntity();
44
-
45
- idTokenEntity.credentialType = CredentialType.ID_TOKEN;
46
- idTokenEntity.homeAccountId = homeAccountId;
47
- idTokenEntity.environment = environment;
48
- idTokenEntity.clientId = clientId;
49
- idTokenEntity.secret = idToken;
50
- idTokenEntity.realm = tenantId;
51
-
52
- return idTokenEntity;
53
- }
54
-
55
- /**
56
- * Validates an entity: checks for all expected params
57
- * @param entity
58
- */
59
- static isIdTokenEntity(entity: object): boolean {
60
- if (!entity) {
61
- return false;
62
- }
63
-
64
- return (
65
- entity.hasOwnProperty("homeAccountId") &&
66
- entity.hasOwnProperty("environment") &&
67
- entity.hasOwnProperty("credentialType") &&
68
- entity.hasOwnProperty("realm") &&
69
- entity.hasOwnProperty("clientId") &&
70
- entity.hasOwnProperty("secret") &&
71
- entity["credentialType"] === CredentialType.ID_TOKEN
72
- );
73
- }
74
- }
14
+ };
@@ -4,75 +4,8 @@
4
4
  */
5
5
 
6
6
  import { CredentialEntity } from "./CredentialEntity";
7
- import { CredentialType } from "../../utils/Constants";
8
7
 
9
8
  /**
10
- * REFRESH_TOKEN Cache
11
- *
12
- * Key:Value Schema:
13
- *
14
- * Key Example: uid.utid-login.microsoftonline.com-refreshtoken-clientId--
15
- *
16
- * Value:
17
- * {
18
- * homeAccountId: home account identifier for the auth scheme,
19
- * environment: entity that issued the token, represented as a full host
20
- * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
21
- * clientId: client ID of the application
22
- * secret: Actual credential as a string
23
- * familyId: Family ID identifier, '1' represents Microsoft Family
24
- * realm: Full tenant or organizational identifier that the account belongs to
25
- * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
26
- * }
9
+ * Refresh Token Cache Type
27
10
  */
28
- export class RefreshTokenEntity extends CredentialEntity {
29
- familyId?: string;
30
-
31
- /**
32
- * Create RefreshTokenEntity
33
- * @param homeAccountId
34
- * @param authenticationResult
35
- * @param clientId
36
- * @param authority
37
- */
38
- static createRefreshTokenEntity(
39
- homeAccountId: string,
40
- environment: string,
41
- refreshToken: string,
42
- clientId: string,
43
- familyId?: string,
44
- userAssertionHash?: string
45
- ): RefreshTokenEntity {
46
- const rtEntity = new RefreshTokenEntity();
47
-
48
- rtEntity.clientId = clientId;
49
- rtEntity.credentialType = CredentialType.REFRESH_TOKEN;
50
- rtEntity.environment = environment;
51
- rtEntity.homeAccountId = homeAccountId;
52
- rtEntity.secret = refreshToken;
53
- rtEntity.userAssertionHash = userAssertionHash;
54
-
55
- if (familyId) rtEntity.familyId = familyId;
56
-
57
- return rtEntity;
58
- }
59
-
60
- /**
61
- * Validates an entity: checks for all expected params
62
- * @param entity
63
- */
64
- static isRefreshTokenEntity(entity: object): boolean {
65
- if (!entity) {
66
- return false;
67
- }
68
-
69
- return (
70
- entity.hasOwnProperty("homeAccountId") &&
71
- entity.hasOwnProperty("environment") &&
72
- entity.hasOwnProperty("credentialType") &&
73
- entity.hasOwnProperty("clientId") &&
74
- entity.hasOwnProperty("secret") &&
75
- entity["credentialType"] === CredentialType.REFRESH_TOKEN
76
- );
77
- }
78
- }
11
+ export type RefreshTokenEntity = CredentialEntity;