@azure/msal-common 4.5.0 → 5.1.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 (186) hide show
  1. package/CHANGELOG.json +178 -0
  2. package/{changelog.md → CHANGELOG.md} +446 -390
  3. package/LICENSE +21 -21
  4. package/README.md +62 -61
  5. package/dist/_virtual/_tslib.js +1 -1
  6. package/dist/account/AuthToken.js +7 -7
  7. package/dist/account/AuthToken.js.map +1 -1
  8. package/dist/account/CcsCredential.js +1 -1
  9. package/dist/account/CcsCredential.js.map +1 -1
  10. package/dist/account/ClientInfo.js +10 -10
  11. package/dist/account/ClientInfo.js.map +1 -1
  12. package/dist/account/TokenClaims.d.ts +5 -0
  13. package/dist/account/TokenClaims.d.ts.map +1 -1
  14. package/dist/authority/Authority.d.ts.map +1 -1
  15. package/dist/authority/Authority.js +60 -54
  16. package/dist/authority/Authority.js.map +1 -1
  17. package/dist/authority/AuthorityFactory.js +9 -9
  18. package/dist/authority/AuthorityFactory.js.map +1 -1
  19. package/dist/authority/AuthorityType.js +1 -1
  20. package/dist/authority/AuthorityType.js.map +1 -1
  21. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  22. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  23. package/dist/authority/OpenIdConfigResponse.d.ts +1 -1
  24. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
  25. package/dist/authority/OpenIdConfigResponse.js +1 -2
  26. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  27. package/dist/authority/ProtocolMode.js +1 -1
  28. package/dist/authority/ProtocolMode.js.map +1 -1
  29. package/dist/authority/RegionDiscovery.js +9 -9
  30. package/dist/authority/RegionDiscovery.js.map +1 -1
  31. package/dist/cache/CacheManager.d.ts +23 -9
  32. package/dist/cache/CacheManager.d.ts.map +1 -1
  33. package/dist/cache/CacheManager.js +244 -114
  34. package/dist/cache/CacheManager.js.map +1 -1
  35. package/dist/cache/entities/AccessTokenEntity.d.ts +3 -2
  36. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  37. package/dist/cache/entities/AccessTokenEntity.js +23 -17
  38. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  39. package/dist/cache/entities/AccountEntity.d.ts +2 -2
  40. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  41. package/dist/cache/entities/AccountEntity.js +18 -18
  42. package/dist/cache/entities/AccountEntity.js.map +1 -1
  43. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  44. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  45. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -1
  46. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  47. package/dist/cache/entities/AuthorityMetadataEntity.js +5 -6
  48. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  49. package/dist/cache/entities/CacheRecord.js +1 -1
  50. package/dist/cache/entities/CacheRecord.js.map +1 -1
  51. package/dist/cache/entities/CredentialEntity.d.ts +7 -3
  52. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  53. package/dist/cache/entities/CredentialEntity.js +16 -9
  54. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  55. package/dist/cache/entities/IdTokenEntity.js +3 -3
  56. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  57. package/dist/cache/entities/RefreshTokenEntity.js +3 -3
  58. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  59. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  60. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  61. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  62. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  63. package/dist/cache/interface/ICacheManager.d.ts +5 -5
  64. package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
  65. package/dist/cache/persistence/TokenCacheContext.js +3 -3
  66. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  67. package/dist/cache/utils/CacheTypes.d.ts +4 -1
  68. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  69. package/dist/client/AuthorizationCodeClient.d.ts +1 -1
  70. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  71. package/dist/client/AuthorizationCodeClient.js +56 -43
  72. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  73. package/dist/client/BaseClient.js +11 -11
  74. package/dist/client/BaseClient.js.map +1 -1
  75. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  76. package/dist/client/ClientCredentialClient.js +24 -18
  77. package/dist/client/ClientCredentialClient.js.map +1 -1
  78. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  79. package/dist/client/DeviceCodeClient.js +39 -27
  80. package/dist/client/DeviceCodeClient.js.map +1 -1
  81. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  82. package/dist/client/OnBehalfOfClient.js +26 -20
  83. package/dist/client/OnBehalfOfClient.js.map +1 -1
  84. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  85. package/dist/client/RefreshTokenClient.js +49 -32
  86. package/dist/client/RefreshTokenClient.js.map +1 -1
  87. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  88. package/dist/client/SilentFlowClient.js +40 -35
  89. package/dist/client/SilentFlowClient.js.map +1 -1
  90. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  91. package/dist/client/UsernamePasswordClient.js +18 -12
  92. package/dist/client/UsernamePasswordClient.js.map +1 -1
  93. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  94. package/dist/config/ClientConfiguration.js +8 -7
  95. package/dist/config/ClientConfiguration.js.map +1 -1
  96. package/dist/crypto/ICrypto.d.ts +11 -1
  97. package/dist/crypto/ICrypto.d.ts.map +1 -1
  98. package/dist/crypto/ICrypto.js +26 -8
  99. package/dist/crypto/ICrypto.js.map +1 -1
  100. package/dist/crypto/PopTokenGenerator.d.ts +21 -4
  101. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  102. package/dist/crypto/PopTokenGenerator.js +42 -31
  103. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  104. package/dist/error/AuthError.d.ts +5 -0
  105. package/dist/error/AuthError.d.ts.map +1 -1
  106. package/dist/error/AuthError.js +6 -3
  107. package/dist/error/AuthError.js.map +1 -1
  108. package/dist/error/ClientAuthError.d.ts +13 -4
  109. package/dist/error/ClientAuthError.d.ts.map +1 -1
  110. package/dist/error/ClientAuthError.js +20 -9
  111. package/dist/error/ClientAuthError.js.map +1 -1
  112. package/dist/error/ClientConfigurationError.d.ts +29 -0
  113. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  114. package/dist/error/ClientConfigurationError.js +45 -5
  115. package/dist/error/ClientConfigurationError.js.map +1 -1
  116. package/dist/error/InteractionRequiredAuthError.d.ts +24 -5
  117. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  118. package/dist/error/InteractionRequiredAuthError.js +30 -9
  119. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  120. package/dist/error/ServerError.js +3 -3
  121. package/dist/error/ServerError.js.map +1 -1
  122. package/dist/index.cjs.js +675 -244
  123. package/dist/index.cjs.js.map +1 -1
  124. package/dist/index.d.ts +7 -2
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +33 -29
  127. package/dist/index.js.map +1 -1
  128. package/dist/logger/Logger.d.ts.map +1 -1
  129. package/dist/logger/Logger.js +11 -9
  130. package/dist/logger/Logger.js.map +1 -1
  131. package/dist/network/INetworkModule.js +4 -4
  132. package/dist/network/INetworkModule.js.map +1 -1
  133. package/dist/network/NetworkManager.js +8 -8
  134. package/dist/network/NetworkManager.js.map +1 -1
  135. package/dist/network/RequestThumbprint.d.ts +7 -0
  136. package/dist/network/RequestThumbprint.d.ts.map +1 -1
  137. package/dist/network/ThrottlingUtils.d.ts +2 -1
  138. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  139. package/dist/network/ThrottlingUtils.js +14 -8
  140. package/dist/network/ThrottlingUtils.js.map +1 -1
  141. package/dist/packageMetadata.d.ts +1 -1
  142. package/dist/packageMetadata.js +2 -2
  143. package/dist/packageMetadata.js.map +1 -1
  144. package/dist/request/AuthenticationHeaderParser.d.ts +20 -0
  145. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -0
  146. package/dist/request/AuthenticationHeaderParser.js +64 -0
  147. package/dist/request/AuthenticationHeaderParser.js.map +1 -0
  148. package/dist/request/BaseAuthRequest.d.ts +7 -1
  149. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  150. package/dist/request/CommonEndSessionRequest.d.ts +4 -0
  151. package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
  152. package/dist/request/RequestParameterBuilder.d.ts +4 -0
  153. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  154. package/dist/request/RequestParameterBuilder.js +27 -18
  155. package/dist/request/RequestParameterBuilder.js.map +1 -1
  156. package/dist/request/RequestValidator.js +10 -10
  157. package/dist/request/RequestValidator.js.map +1 -1
  158. package/dist/request/ScopeSet.js +14 -14
  159. package/dist/request/ScopeSet.js.map +1 -1
  160. package/dist/response/AuthenticationResult.d.ts +2 -1
  161. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  162. package/dist/response/ExternalTokenResponse.d.ts +15 -0
  163. package/dist/response/ExternalTokenResponse.d.ts.map +1 -0
  164. package/dist/response/ResponseHandler.d.ts.map +1 -1
  165. package/dist/response/ResponseHandler.js +74 -69
  166. package/dist/response/ResponseHandler.js.map +1 -1
  167. package/dist/response/ServerAuthorizationTokenResponse.d.ts +5 -2
  168. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  169. package/dist/telemetry/server/ServerTelemetryManager.js +13 -13
  170. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  171. package/dist/url/UrlString.d.ts +0 -6
  172. package/dist/url/UrlString.d.ts.map +1 -1
  173. package/dist/url/UrlString.js +25 -40
  174. package/dist/url/UrlString.js.map +1 -1
  175. package/dist/utils/Constants.d.ts +5 -2
  176. package/dist/utils/Constants.d.ts.map +1 -1
  177. package/dist/utils/Constants.js +5 -2
  178. package/dist/utils/Constants.js.map +1 -1
  179. package/dist/utils/ProtocolUtils.js +13 -13
  180. package/dist/utils/ProtocolUtils.js.map +1 -1
  181. package/dist/utils/StringUtils.d.ts.map +1 -1
  182. package/dist/utils/StringUtils.js +15 -14
  183. package/dist/utils/StringUtils.js.map +1 -1
  184. package/dist/utils/TimeUtils.js +1 -1
  185. package/dist/utils/TimeUtils.js.map +1 -1
  186. package/package.json +1 -1
@@ -1,24 +1,24 @@
1
- /*! @azure/msal-common v4.5.0 2021-07-22 */
1
+ /*! @azure/msal-common v5.1.0 2021-11-02 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator } from '../_virtual/_tslib.js';
4
- import { Constants as Constants$1, AuthenticationScheme, THE_FAMILY_ID } from '../utils/Constants.js';
5
- import { ClientAuthError as ClientAuthError$1 } from '../error/ClientAuthError.js';
6
- import { StringUtils as StringUtils$1 } from '../utils/StringUtils.js';
7
- import { ScopeSet as ScopeSet$1 } from '../request/ScopeSet.js';
8
4
  import { buildClientInfo } from '../account/ClientInfo.js';
9
- import { AuthorityType as AuthorityType$1 } from '../authority/AuthorityType.js';
10
- import { AccountEntity as AccountEntity$1 } from '../cache/entities/AccountEntity.js';
11
- import { AuthToken as AuthToken$1 } from '../account/AuthToken.js';
12
- import { ServerError as ServerError$1 } from '../error/ServerError.js';
13
- import { IdTokenEntity as IdTokenEntity$1 } from '../cache/entities/IdTokenEntity.js';
14
- import { AccessTokenEntity as AccessTokenEntity$1 } from '../cache/entities/AccessTokenEntity.js';
15
- import { RefreshTokenEntity as RefreshTokenEntity$1 } from '../cache/entities/RefreshTokenEntity.js';
16
- import { InteractionRequiredAuthError as InteractionRequiredAuthError$1 } from '../error/InteractionRequiredAuthError.js';
17
- import { CacheRecord as CacheRecord$1 } from '../cache/entities/CacheRecord.js';
18
- import { ProtocolUtils as ProtocolUtils$1 } from '../utils/ProtocolUtils.js';
19
- import { PopTokenGenerator as PopTokenGenerator$1 } from '../crypto/PopTokenGenerator.js';
20
- import { AppMetadataEntity as AppMetadataEntity$1 } from '../cache/entities/AppMetadataEntity.js';
21
- import { TokenCacheContext as TokenCacheContext$1 } from '../cache/persistence/TokenCacheContext.js';
5
+ import { ClientAuthError } from '../error/ClientAuthError.js';
6
+ import { StringUtils } from '../utils/StringUtils.js';
7
+ import { ServerError } from '../error/ServerError.js';
8
+ import { AuthToken } from '../account/AuthToken.js';
9
+ import { ScopeSet } from '../request/ScopeSet.js';
10
+ import { AccountEntity } from '../cache/entities/AccountEntity.js';
11
+ import { AuthorityType } from '../authority/AuthorityType.js';
12
+ import { IdTokenEntity } from '../cache/entities/IdTokenEntity.js';
13
+ import { AccessTokenEntity } from '../cache/entities/AccessTokenEntity.js';
14
+ import { RefreshTokenEntity } from '../cache/entities/RefreshTokenEntity.js';
15
+ import { InteractionRequiredAuthError } from '../error/InteractionRequiredAuthError.js';
16
+ import { CacheRecord } from '../cache/entities/CacheRecord.js';
17
+ import { ProtocolUtils } from '../utils/ProtocolUtils.js';
18
+ import { Constants, AuthenticationScheme, THE_FAMILY_ID } from '../utils/Constants.js';
19
+ import { PopTokenGenerator } from '../crypto/PopTokenGenerator.js';
20
+ import { AppMetadataEntity } from '../cache/entities/AppMetadataEntity.js';
21
+ import { TokenCacheContext } from '../cache/persistence/TokenCacheContext.js';
22
22
 
23
23
  /*
24
24
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -44,17 +44,17 @@ var ResponseHandler = /** @class */ (function () {
44
44
  */
45
45
  ResponseHandler.prototype.validateServerAuthorizationCodeResponse = function (serverResponseHash, cachedState, cryptoObj) {
46
46
  if (!serverResponseHash.state || !cachedState) {
47
- throw !serverResponseHash.state ? ClientAuthError$1.createStateNotFoundError("Server State") : ClientAuthError$1.createStateNotFoundError("Cached State");
47
+ throw !serverResponseHash.state ? ClientAuthError.createStateNotFoundError("Server State") : ClientAuthError.createStateNotFoundError("Cached State");
48
48
  }
49
49
  if (decodeURIComponent(serverResponseHash.state) !== decodeURIComponent(cachedState)) {
50
- throw ClientAuthError$1.createStateMismatchError();
50
+ throw ClientAuthError.createStateMismatchError();
51
51
  }
52
52
  // Check for error
53
53
  if (serverResponseHash.error || serverResponseHash.error_description || serverResponseHash.suberror) {
54
- if (InteractionRequiredAuthError$1.isInteractionRequiredError(serverResponseHash.error, serverResponseHash.error_description, serverResponseHash.suberror)) {
55
- throw new InteractionRequiredAuthError$1(serverResponseHash.error || Constants$1.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);
54
+ if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponseHash.error, serverResponseHash.error_description, serverResponseHash.suberror)) {
55
+ throw new InteractionRequiredAuthError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);
56
56
  }
57
- throw new ServerError$1(serverResponseHash.error || Constants$1.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);
57
+ throw new ServerError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);
58
58
  }
59
59
  if (serverResponseHash.client_info) {
60
60
  buildClientInfo(serverResponseHash.client_info, cryptoObj);
@@ -67,11 +67,11 @@ var ResponseHandler = /** @class */ (function () {
67
67
  ResponseHandler.prototype.validateTokenResponse = function (serverResponse) {
68
68
  // Check for error
69
69
  if (serverResponse.error || serverResponse.error_description || serverResponse.suberror) {
70
- if (InteractionRequiredAuthError$1.isInteractionRequiredError(serverResponse.error, serverResponse.error_description, serverResponse.suberror)) {
71
- throw new InteractionRequiredAuthError$1(serverResponse.error, serverResponse.error_description, serverResponse.suberror);
70
+ if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponse.error, serverResponse.error_description, serverResponse.suberror)) {
71
+ throw new InteractionRequiredAuthError(serverResponse.error, serverResponse.error_description, serverResponse.suberror);
72
72
  }
73
73
  var errString = serverResponse.error_codes + " - [" + serverResponse.timestamp + "]: " + serverResponse.error_description + " - Correlation ID: " + serverResponse.correlation_id + " - Trace ID: " + serverResponse.trace_id;
74
- throw new ServerError$1(serverResponse.error, errString, serverResponse.suberror);
74
+ throw new ServerError(serverResponse.error, errString, serverResponse.suberror);
75
75
  }
76
76
  };
77
77
  /**
@@ -86,26 +86,28 @@ var ResponseHandler = /** @class */ (function () {
86
86
  switch (_a.label) {
87
87
  case 0:
88
88
  if (serverTokenResponse.id_token) {
89
- idTokenObj = new AuthToken$1(serverTokenResponse.id_token || Constants$1.EMPTY_STRING, this.cryptoObj);
89
+ idTokenObj = new AuthToken(serverTokenResponse.id_token || Constants.EMPTY_STRING, this.cryptoObj);
90
90
  // token nonce check (TODO: Add a warning if no nonce is given?)
91
- if (authCodePayload && !StringUtils$1.isEmpty(authCodePayload.nonce)) {
91
+ if (authCodePayload && !StringUtils.isEmpty(authCodePayload.nonce)) {
92
92
  if (idTokenObj.claims.nonce !== authCodePayload.nonce) {
93
- throw ClientAuthError$1.createNonceMismatchError();
93
+ throw ClientAuthError.createNonceMismatchError();
94
94
  }
95
95
  }
96
96
  }
97
97
  // generate homeAccountId
98
- this.homeAccountIdentifier = AccountEntity$1.generateHomeAccountId(serverTokenResponse.client_info || Constants$1.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);
98
+ this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);
99
99
  if (!!authCodePayload && !!authCodePayload.state) {
100
- requestStateObj = ProtocolUtils$1.parseRequestState(this.cryptoObj, authCodePayload.state);
100
+ requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);
101
101
  }
102
+ // Add keyId from request to serverTokenResponse if defined
103
+ serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
102
104
  cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);
103
105
  _a.label = 1;
104
106
  case 1:
105
- _a.trys.push([1, , 4, 7]);
107
+ _a.trys.push([1, , 5, 8]);
106
108
  if (!(this.persistencePlugin && this.serializableCache)) return [3 /*break*/, 3];
107
109
  this.logger.verbose("Persistence enabled, calling beforeCacheAccess");
108
- cacheContext = new TokenCacheContext$1(this.serializableCache, true);
110
+ cacheContext = new TokenCacheContext(this.serializableCache, true);
109
111
  return [4 /*yield*/, this.persistencePlugin.beforeCacheAccess(cacheContext)];
110
112
  case 2:
111
113
  _a.sent();
@@ -124,17 +126,19 @@ var ResponseHandler = /** @class */ (function () {
124
126
  return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
125
127
  }
126
128
  }
127
- this.cacheStorage.saveCacheRecord(cacheRecord);
128
- return [3 /*break*/, 7];
129
+ return [4 /*yield*/, this.cacheStorage.saveCacheRecord(cacheRecord)];
129
130
  case 4:
130
- if (!(this.persistencePlugin && this.serializableCache && cacheContext)) return [3 /*break*/, 6];
131
+ _a.sent();
132
+ return [3 /*break*/, 8];
133
+ case 5:
134
+ if (!(this.persistencePlugin && this.serializableCache && cacheContext)) return [3 /*break*/, 7];
131
135
  this.logger.verbose("Persistence enabled, calling afterCacheAccess");
132
136
  return [4 /*yield*/, this.persistencePlugin.afterCacheAccess(cacheContext)];
133
- case 5:
137
+ case 6:
134
138
  _a.sent();
135
- _a.label = 6;
136
- case 6: return [7 /*endfinally*/];
137
- case 7: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
139
+ _a.label = 7;
140
+ case 7: return [7 /*endfinally*/];
141
+ case 8: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
138
142
  }
139
143
  });
140
144
  });
@@ -147,21 +151,21 @@ var ResponseHandler = /** @class */ (function () {
147
151
  */
148
152
  ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, idTokenObj, requestScopes, oboAssertion, authCodePayload) {
149
153
  var env = authority.getPreferredCache();
150
- if (StringUtils$1.isEmpty(env)) {
151
- throw ClientAuthError$1.createInvalidCacheEnvironmentError();
154
+ if (StringUtils.isEmpty(env)) {
155
+ throw ClientAuthError.createInvalidCacheEnvironmentError();
152
156
  }
153
157
  // IdToken: non AAD scenarios can have empty realm
154
158
  var cachedIdToken;
155
159
  var cachedAccount;
156
- if (!StringUtils$1.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {
157
- cachedIdToken = IdTokenEntity$1.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants$1.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants$1.EMPTY_STRING, oboAssertion);
160
+ if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {
161
+ cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING, oboAssertion);
158
162
  cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, oboAssertion, authCodePayload);
159
163
  }
160
164
  // AccessToken
161
165
  var cachedAccessToken = null;
162
- if (!StringUtils$1.isEmpty(serverTokenResponse.access_token)) {
166
+ if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {
163
167
  // If scopes not returned in server response, use request scopes
164
- var responseScopes = serverTokenResponse.scope ? ScopeSet$1.fromString(serverTokenResponse.scope) : new ScopeSet$1(requestScopes || []);
168
+ var responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(requestScopes || []);
165
169
  /*
166
170
  * Use timestamp calculated before request
167
171
  * Server may return timestamps as strings, parse to numbers if so.
@@ -173,19 +177,19 @@ var ResponseHandler = /** @class */ (function () {
173
177
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
174
178
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
175
179
  // non AAD scenarios can have empty realm
176
- cachedAccessToken = AccessTokenEntity$1.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants$1.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants$1.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion);
180
+ cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion, serverTokenResponse.key_id);
177
181
  }
178
182
  // refreshToken
179
183
  var cachedRefreshToken = null;
180
- if (!StringUtils$1.isEmpty(serverTokenResponse.refresh_token)) {
181
- cachedRefreshToken = RefreshTokenEntity$1.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants$1.EMPTY_STRING, this.clientId, serverTokenResponse.foci, oboAssertion);
184
+ if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {
185
+ cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, oboAssertion);
182
186
  }
183
187
  // appMetadata
184
188
  var cachedAppMetadata = null;
185
- if (!StringUtils$1.isEmpty(serverTokenResponse.foci)) {
186
- cachedAppMetadata = AppMetadataEntity$1.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);
189
+ if (!StringUtils.isEmpty(serverTokenResponse.foci)) {
190
+ cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);
187
191
  }
188
- return new CacheRecord$1(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);
192
+ return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);
189
193
  };
190
194
  /**
191
195
  * Generate Account
@@ -198,17 +202,17 @@ var ResponseHandler = /** @class */ (function () {
198
202
  var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : "";
199
203
  var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : "";
200
204
  // ADFS does not require client_info in the response
201
- if (authorityType === AuthorityType$1.Adfs) {
205
+ if (authorityType === AuthorityType.Adfs) {
202
206
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
203
- return AccountEntity$1.createGenericAccount(authority, this.homeAccountIdentifier, idToken, oboAssertion, cloudGraphHostName, msGraphhost);
207
+ return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
204
208
  }
205
209
  // This fallback applies to B2C as well as they fall under an AAD account type.
206
- if (StringUtils$1.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
207
- throw ClientAuthError$1.createClientInfoEmptyError();
210
+ if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
211
+ throw ClientAuthError.createClientInfoEmptyError();
208
212
  }
209
213
  return serverTokenResponse.client_info ?
210
- AccountEntity$1.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, authority, idToken, oboAssertion, cloudGraphHostName, msGraphhost) :
211
- AccountEntity$1.createGenericAccount(authority, this.homeAccountIdentifier, idToken, oboAssertion, cloudGraphHostName, msGraphhost);
214
+ AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :
215
+ AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
212
216
  };
213
217
  /**
214
218
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
@@ -230,10 +234,10 @@ var ResponseHandler = /** @class */ (function () {
230
234
  accessToken = "";
231
235
  responseScopes = [];
232
236
  expiresOn = null;
233
- familyId = Constants$1.EMPTY_STRING;
237
+ familyId = Constants.EMPTY_STRING;
234
238
  if (!cacheRecord.accessToken) return [3 /*break*/, 4];
235
239
  if (!(cacheRecord.accessToken.tokenType === AuthenticationScheme.POP)) return [3 /*break*/, 2];
236
- popTokenGenerator = new PopTokenGenerator$1(cryptoObj);
240
+ popTokenGenerator = new PopTokenGenerator(cryptoObj);
237
241
  return [4 /*yield*/, popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request)];
238
242
  case 1:
239
243
  accessToken = _d.sent();
@@ -242,33 +246,34 @@ var ResponseHandler = /** @class */ (function () {
242
246
  accessToken = cacheRecord.accessToken.secret;
243
247
  _d.label = 3;
244
248
  case 3:
245
- responseScopes = ScopeSet$1.fromString(cacheRecord.accessToken.target).asArray();
249
+ responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();
246
250
  expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);
247
251
  extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);
248
252
  _d.label = 4;
249
253
  case 4:
250
254
  if (cacheRecord.appMetadata) {
251
- familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants$1.EMPTY_STRING;
255
+ familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;
252
256
  }
253
- uid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.oid) || (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.sub) || Constants$1.EMPTY_STRING;
254
- tid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.tid) || Constants$1.EMPTY_STRING;
257
+ uid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.oid) || (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.sub) || Constants.EMPTY_STRING;
258
+ tid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.tid) || Constants.EMPTY_STRING;
255
259
  return [2 /*return*/, {
256
260
  authority: authority.canonicalAuthority,
257
261
  uniqueId: uid,
258
262
  tenantId: tid,
259
263
  scopes: responseScopes,
260
264
  account: cacheRecord.account ? cacheRecord.account.getAccountInfo() : null,
261
- idToken: idTokenObj ? idTokenObj.rawToken : Constants$1.EMPTY_STRING,
265
+ idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,
262
266
  idTokenClaims: idTokenObj ? idTokenObj.claims : {},
263
267
  accessToken: accessToken,
264
268
  fromCache: fromTokenCache,
265
269
  expiresOn: expiresOn,
270
+ correlationId: request.correlationId,
266
271
  extExpiresOn: extExpiresOn,
267
272
  familyId: familyId,
268
- tokenType: ((_a = cacheRecord.accessToken) === null || _a === void 0 ? void 0 : _a.tokenType) || Constants$1.EMPTY_STRING,
269
- state: requestState ? requestState.userRequestState : Constants$1.EMPTY_STRING,
270
- cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants$1.EMPTY_STRING,
271
- msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants$1.EMPTY_STRING
273
+ tokenType: ((_a = cacheRecord.accessToken) === null || _a === void 0 ? void 0 : _a.tokenType) || Constants.EMPTY_STRING,
274
+ state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,
275
+ cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
276
+ msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING
272
277
  }];
273
278
  }
274
279
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ResponseHandler.js","sources":["../../src/response/ResponseHandler.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ServerAuthorizationTokenResponse } from \"./ServerAuthorizationTokenResponse\";\r\nimport { buildClientInfo} from \"../account/ClientInfo\";\r\nimport { ICrypto } from \"../crypto/ICrypto\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\nimport { StringUtils } from \"../utils/StringUtils\";\r\nimport { ServerAuthorizationCodeResponse } from \"./ServerAuthorizationCodeResponse\";\r\nimport { Logger } from \"../logger/Logger\";\r\nimport { ServerError } from \"../error/ServerError\";\r\nimport { AuthToken } from \"../account/AuthToken\";\r\nimport { ScopeSet } from \"../request/ScopeSet\";\r\nimport { AuthenticationResult } from \"./AuthenticationResult\";\r\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\r\nimport { Authority } from \"../authority/Authority\";\r\nimport { AuthorityType } from \"../authority/AuthorityType\";\r\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\r\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\r\nimport { RefreshTokenEntity } from \"../cache/entities/RefreshTokenEntity\";\r\nimport { InteractionRequiredAuthError } from \"../error/InteractionRequiredAuthError\";\r\nimport { CacheRecord } from \"../cache/entities/CacheRecord\";\r\nimport { CacheManager } from \"../cache/CacheManager\";\r\nimport { ProtocolUtils, RequestStateObject } from \"../utils/ProtocolUtils\";\r\nimport { AuthenticationScheme, Constants, THE_FAMILY_ID } from \"../utils/Constants\";\r\nimport { PopTokenGenerator } from \"../crypto/PopTokenGenerator\";\r\nimport { AppMetadataEntity } from \"../cache/entities/AppMetadataEntity\";\r\nimport { ICachePlugin } from \"../cache/interface/ICachePlugin\";\r\nimport { TokenCacheContext } from \"../cache/persistence/TokenCacheContext\";\r\nimport { ISerializableTokenCache } from \"../cache/interface/ISerializableTokenCache\";\r\nimport { AuthorizationCodePayload } from \"./AuthorizationCodePayload\";\r\nimport { BaseAuthRequest } from \"../request/BaseAuthRequest\";\r\n\r\n/**\r\n * Class that handles response parsing.\r\n */\r\nexport class ResponseHandler {\r\n private clientId: string;\r\n private cacheStorage: CacheManager;\r\n private cryptoObj: ICrypto;\r\n private logger: Logger;\r\n private homeAccountIdentifier: string;\r\n private serializableCache: ISerializableTokenCache | null;\r\n private persistencePlugin: ICachePlugin | null;\r\n\r\n constructor(clientId: string, cacheStorage: CacheManager, cryptoObj: ICrypto, logger: Logger, serializableCache: ISerializableTokenCache | null, persistencePlugin: ICachePlugin | null) {\r\n this.clientId = clientId;\r\n this.cacheStorage = cacheStorage;\r\n this.cryptoObj = cryptoObj;\r\n this.logger = logger;\r\n this.serializableCache = serializableCache;\r\n this.persistencePlugin = persistencePlugin;\r\n }\r\n\r\n /**\r\n * Function which validates server authorization code response.\r\n * @param serverResponseHash\r\n * @param cachedState\r\n * @param cryptoObj\r\n */\r\n validateServerAuthorizationCodeResponse(serverResponseHash: ServerAuthorizationCodeResponse, cachedState: string, cryptoObj: ICrypto): void {\r\n\r\n if (!serverResponseHash.state || !cachedState) {\r\n throw !serverResponseHash.state ? ClientAuthError.createStateNotFoundError(\"Server State\") : ClientAuthError.createStateNotFoundError(\"Cached State\");\r\n }\r\n\r\n if (decodeURIComponent(serverResponseHash.state) !== decodeURIComponent(cachedState)) {\r\n throw ClientAuthError.createStateMismatchError();\r\n }\r\n\r\n // Check for error\r\n if (serverResponseHash.error || serverResponseHash.error_description || serverResponseHash.suberror) {\r\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponseHash.error, serverResponseHash.error_description, serverResponseHash.suberror)) {\r\n throw new InteractionRequiredAuthError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\r\n }\r\n\r\n throw new ServerError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\r\n }\r\n\r\n if (serverResponseHash.client_info) {\r\n buildClientInfo(serverResponseHash.client_info, cryptoObj);\r\n }\r\n }\r\n\r\n /**\r\n * Function which validates server authorization token response.\r\n * @param serverResponse\r\n */\r\n validateTokenResponse(serverResponse: ServerAuthorizationTokenResponse): void {\r\n // Check for error\r\n if (serverResponse.error || serverResponse.error_description || serverResponse.suberror) {\r\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponse.error, serverResponse.error_description, serverResponse.suberror)) {\r\n throw new InteractionRequiredAuthError(serverResponse.error, serverResponse.error_description, serverResponse.suberror);\r\n }\r\n\r\n const errString = `${serverResponse.error_codes} - [${serverResponse.timestamp}]: ${serverResponse.error_description} - Correlation ID: ${serverResponse.correlation_id} - Trace ID: ${serverResponse.trace_id}`;\r\n throw new ServerError(serverResponse.error, errString, serverResponse.suberror);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a constructed token response based on given string. Also manages the cache updates and cleanups.\r\n * @param serverTokenResponse\r\n * @param authority\r\n */\r\n async handleServerTokenResponse(\r\n serverTokenResponse: ServerAuthorizationTokenResponse,\r\n authority: Authority,\r\n reqTimestamp: number,\r\n request: BaseAuthRequest,\r\n authCodePayload?: AuthorizationCodePayload,\r\n oboAssertion?: string,\r\n handlingRefreshTokenResponse?: boolean): Promise<AuthenticationResult> {\r\n\r\n // create an idToken object (not entity)\r\n let idTokenObj: AuthToken | undefined;\r\n if (serverTokenResponse.id_token) {\r\n idTokenObj = new AuthToken(serverTokenResponse.id_token || Constants.EMPTY_STRING, this.cryptoObj);\r\n \r\n // token nonce check (TODO: Add a warning if no nonce is given?)\r\n if (authCodePayload && !StringUtils.isEmpty(authCodePayload.nonce)) {\r\n if (idTokenObj.claims.nonce !== authCodePayload.nonce) {\r\n throw ClientAuthError.createNonceMismatchError();\r\n }\r\n }\r\n }\r\n\r\n // generate homeAccountId\r\n this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);\r\n\r\n // save the response tokens\r\n let requestStateObj: RequestStateObject | undefined;\r\n if (!!authCodePayload && !!authCodePayload.state) {\r\n requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);\r\n }\r\n\r\n const cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);\r\n let cacheContext;\r\n try {\r\n if (this.persistencePlugin && this.serializableCache) {\r\n this.logger.verbose(\"Persistence enabled, calling beforeCacheAccess\");\r\n cacheContext = new TokenCacheContext(this.serializableCache, true);\r\n await this.persistencePlugin.beforeCacheAccess(cacheContext);\r\n }\r\n /*\r\n * When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.\r\n * If not present, we should return null, as it's the case that another application called removeAccount in between\r\n * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal.\r\n */\r\n if (handlingRefreshTokenResponse && cacheRecord.account) {\r\n const key = cacheRecord.account.generateAccountKey();\r\n const account = this.cacheStorage.getAccount(key);\r\n if (!account) {\r\n this.logger.warning(\"Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache\");\r\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj);\r\n }\r\n }\r\n this.cacheStorage.saveCacheRecord(cacheRecord);\r\n } finally {\r\n if (this.persistencePlugin && this.serializableCache && cacheContext) {\r\n this.logger.verbose(\"Persistence enabled, calling afterCacheAccess\");\r\n await this.persistencePlugin.afterCacheAccess(cacheContext);\r\n }\r\n }\r\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj);\r\n }\r\n\r\n /**\r\n * Generates CacheRecord\r\n * @param serverTokenResponse\r\n * @param idTokenObj\r\n * @param authority\r\n */\r\n private generateCacheRecord(serverTokenResponse: ServerAuthorizationTokenResponse, authority: Authority, reqTimestamp: number, idTokenObj?: AuthToken, requestScopes?: string[], oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): CacheRecord {\r\n const env = authority.getPreferredCache();\r\n if (StringUtils.isEmpty(env)) {\r\n throw ClientAuthError.createInvalidCacheEnvironmentError();\r\n }\r\n\r\n // IdToken: non AAD scenarios can have empty realm\r\n let cachedIdToken: IdTokenEntity | undefined;\r\n let cachedAccount: AccountEntity | undefined;\r\n if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {\r\n cachedIdToken = IdTokenEntity.createIdTokenEntity(\r\n this.homeAccountIdentifier,\r\n env,\r\n serverTokenResponse.id_token || Constants.EMPTY_STRING,\r\n this.clientId,\r\n idTokenObj.claims.tid || Constants.EMPTY_STRING,\r\n oboAssertion\r\n );\r\n\r\n cachedAccount = this.generateAccountEntity(\r\n serverTokenResponse,\r\n idTokenObj,\r\n authority,\r\n oboAssertion,\r\n authCodePayload\r\n );\r\n }\r\n\r\n // AccessToken\r\n let cachedAccessToken: AccessTokenEntity | null = null;\r\n if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {\r\n\r\n // If scopes not returned in server response, use request scopes\r\n const responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(requestScopes || []);\r\n\r\n /*\r\n * Use timestamp calculated before request\r\n * Server may return timestamps as strings, parse to numbers if so.\r\n */\r\n const expiresIn: number = (typeof serverTokenResponse.expires_in === \"string\" ? parseInt(serverTokenResponse.expires_in, 10) : serverTokenResponse.expires_in) || 0;\r\n const extExpiresIn: number = (typeof serverTokenResponse.ext_expires_in === \"string\" ? parseInt(serverTokenResponse.ext_expires_in, 10) : serverTokenResponse.ext_expires_in) || 0;\r\n const refreshIn: number | undefined = (typeof serverTokenResponse.refresh_in === \"string\" ? parseInt(serverTokenResponse.refresh_in, 10) : serverTokenResponse.refresh_in) || undefined;\r\n const tokenExpirationSeconds = reqTimestamp + expiresIn;\r\n const extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;\r\n const refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;\r\n\r\n // non AAD scenarios can have empty realm\r\n cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(\r\n this.homeAccountIdentifier,\r\n env,\r\n serverTokenResponse.access_token || Constants.EMPTY_STRING,\r\n this.clientId,\r\n idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant,\r\n responseScopes.printScopes(),\r\n tokenExpirationSeconds,\r\n extendedTokenExpirationSeconds,\r\n this.cryptoObj,\r\n refreshOnSeconds,\r\n serverTokenResponse.token_type,\r\n oboAssertion\r\n );\r\n }\r\n\r\n // refreshToken\r\n let cachedRefreshToken: RefreshTokenEntity | null = null;\r\n if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {\r\n cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(\r\n this.homeAccountIdentifier,\r\n env,\r\n serverTokenResponse.refresh_token || Constants.EMPTY_STRING,\r\n this.clientId,\r\n serverTokenResponse.foci,\r\n oboAssertion\r\n );\r\n }\r\n\r\n // appMetadata\r\n let cachedAppMetadata: AppMetadataEntity | null = null;\r\n if (!StringUtils.isEmpty(serverTokenResponse.foci)) {\r\n cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);\r\n }\r\n\r\n return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);\r\n }\r\n\r\n /**\r\n * Generate Account\r\n * @param serverTokenResponse\r\n * @param idToken\r\n * @param authority\r\n */\r\n private generateAccountEntity(serverTokenResponse: ServerAuthorizationTokenResponse, idToken: AuthToken, authority: Authority, oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): AccountEntity {\r\n const authorityType = authority.authorityType;\r\n const cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : \"\";\r\n const msGraphhost = authCodePayload ? authCodePayload.msgraph_host : \"\";\r\n\r\n // ADFS does not require client_info in the response\r\n if (authorityType === AuthorityType.Adfs) {\r\n this.logger.verbose(\"Authority type is ADFS, creating ADFS account\");\r\n return AccountEntity.createGenericAccount(authority, this.homeAccountIdentifier, idToken, oboAssertion, cloudGraphHostName, msGraphhost);\r\n }\r\n\r\n // This fallback applies to B2C as well as they fall under an AAD account type.\r\n if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === \"AAD\") {\r\n throw ClientAuthError.createClientInfoEmptyError();\r\n }\r\n\r\n return serverTokenResponse.client_info ?\r\n AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, authority, idToken, oboAssertion, cloudGraphHostName, msGraphhost) :\r\n AccountEntity.createGenericAccount(authority, this.homeAccountIdentifier, idToken, oboAssertion, cloudGraphHostName, msGraphhost);\r\n }\r\n\r\n /**\r\n * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.\r\n *\r\n * Optionally takes a state string that is set as-is in the response.\r\n *\r\n * @param cacheRecord\r\n * @param idTokenObj\r\n * @param fromTokenCache\r\n * @param stateString\r\n */\r\n static async generateAuthenticationResult(\r\n cryptoObj: ICrypto, \r\n authority: Authority,\r\n cacheRecord: CacheRecord, \r\n fromTokenCache: boolean, \r\n request: BaseAuthRequest,\r\n idTokenObj?: AuthToken,\r\n requestState?: RequestStateObject): Promise<AuthenticationResult> {\r\n let accessToken: string = \"\";\r\n let responseScopes: Array<string> = [];\r\n let expiresOn: Date | null = null;\r\n let extExpiresOn: Date | undefined;\r\n let familyId: string = Constants.EMPTY_STRING;\r\n\r\n if (cacheRecord.accessToken) {\r\n if (cacheRecord.accessToken.tokenType === AuthenticationScheme.POP) {\r\n const popTokenGenerator: PopTokenGenerator = new PopTokenGenerator(cryptoObj);\r\n accessToken = await popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request);\r\n } else {\r\n accessToken = cacheRecord.accessToken.secret;\r\n }\r\n responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();\r\n expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);\r\n extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);\r\n }\r\n\r\n if (cacheRecord.appMetadata) {\r\n familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;\r\n }\r\n const uid = idTokenObj?.claims.oid || idTokenObj?.claims.sub || Constants.EMPTY_STRING;\r\n const tid = idTokenObj?.claims.tid || Constants.EMPTY_STRING;\r\n\r\n return {\r\n authority: authority.canonicalAuthority,\r\n uniqueId: uid,\r\n tenantId: tid,\r\n scopes: responseScopes,\r\n account: cacheRecord.account ? cacheRecord.account.getAccountInfo() : null,\r\n idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,\r\n idTokenClaims: idTokenObj ? idTokenObj.claims : {},\r\n accessToken: accessToken,\r\n fromCache: fromTokenCache,\r\n expiresOn: expiresOn,\r\n extExpiresOn: extExpiresOn,\r\n familyId: familyId,\r\n tokenType: cacheRecord.accessToken?.tokenType || Constants.EMPTY_STRING,\r\n state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,\r\n cloudGraphHostName: cacheRecord.account?.cloudGraphHostName || Constants.EMPTY_STRING,\r\n msGraphHost: cacheRecord.account?.msGraphHost || Constants.EMPTY_STRING\r\n };\r\n }\r\n}\r\n"],"names":["ClientAuthError","InteractionRequiredAuthError","Constants","ServerError","AuthToken","StringUtils","AccountEntity","ProtocolUtils","TokenCacheContext","IdTokenEntity","ScopeSet","AccessTokenEntity","RefreshTokenEntity","AppMetadataEntity","CacheRecord","AuthorityType","PopTokenGenerator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAmCA;;;;IAYI,yBAAY,QAAgB,EAAE,YAA0B,EAAE,SAAkB,EAAE,MAAc,EAAE,iBAAiD,EAAE,iBAAsC;QACnL,IAAI,CAAC,QAAQ,GAAG,QA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CAC1E,OAAO,EAAE,UAAU,GAAG,UAAU,CAAC,QAAQ,GAAGA,WAAS,CAAC,YAAY;gCAClE,aAAa,EAAE,UAAU,GAAG,UAAU,CAAC,MAAM,GAAG,EAAE;gCAClD,WAAW,EAAE,WAAW;gCACxB,SAAS,EAAE,cAAc;gCACzB,SAAS,EAAE,SAAS;gCACpB,YAAY,EAAE,YAAY;gCAC1B,QAAQ,EAAE,QAAQ;gCAClB,SAAS,EAAE,OAAA,WAAW,CAAC,WAAW,0CAAE,SAAS,KAAIA,WAAS,CAAC,YAAY;gCACvE,KAAK,EAAE,YAAY,GAAG,YAAY,CAAC,gBAAgB,GAAGA,WAAS,CAAC,YAAY;gCAC5E,kBAAkB,EAAE,OAAA,WAAW,CAAC,OAAO,0CAAE,kBAAkB,KAAIA,WAAS,CAAC,YAAY;gCACrF,WAAW,EAAE,OAAA,WAAW,CAAC,OAAO,0CAAE,WAAW,KAAIA,WAAS,CAAC,YAAY;6BAC1E,EAAC;;;;KACL;IACL,sBAAC;AAAD,CAAC;;;;"}
1
+ {"version":3,"file":"ResponseHandler.js","sources":["../../src/response/ResponseHandler.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ServerAuthorizationTokenResponse } from \"./ServerAuthorizationTokenResponse\";\nimport { buildClientInfo} from \"../account/ClientInfo\";\nimport { ICrypto } from \"../crypto/ICrypto\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { ServerAuthorizationCodeResponse } from \"./ServerAuthorizationCodeResponse\";\nimport { Logger } from \"../logger/Logger\";\nimport { ServerError } from \"../error/ServerError\";\nimport { AuthToken } from \"../account/AuthToken\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { AuthenticationResult } from \"./AuthenticationResult\";\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\nimport { Authority } from \"../authority/Authority\";\nimport { AuthorityType } from \"../authority/AuthorityType\";\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { RefreshTokenEntity } from \"../cache/entities/RefreshTokenEntity\";\nimport { InteractionRequiredAuthError } from \"../error/InteractionRequiredAuthError\";\nimport { CacheRecord } from \"../cache/entities/CacheRecord\";\nimport { CacheManager } from \"../cache/CacheManager\";\nimport { ProtocolUtils, RequestStateObject } from \"../utils/ProtocolUtils\";\nimport { AuthenticationScheme, Constants, THE_FAMILY_ID } from \"../utils/Constants\";\nimport { PopTokenGenerator } from \"../crypto/PopTokenGenerator\";\nimport { AppMetadataEntity } from \"../cache/entities/AppMetadataEntity\";\nimport { ICachePlugin } from \"../cache/interface/ICachePlugin\";\nimport { TokenCacheContext } from \"../cache/persistence/TokenCacheContext\";\nimport { ISerializableTokenCache } from \"../cache/interface/ISerializableTokenCache\";\nimport { AuthorizationCodePayload } from \"./AuthorizationCodePayload\";\nimport { BaseAuthRequest } from \"../request/BaseAuthRequest\";\n\n/**\n * Class that handles response parsing.\n */\nexport class ResponseHandler {\n private clientId: string;\n private cacheStorage: CacheManager;\n private cryptoObj: ICrypto;\n private logger: Logger;\n private homeAccountIdentifier: string;\n private serializableCache: ISerializableTokenCache | null;\n private persistencePlugin: ICachePlugin | null;\n\n constructor(clientId: string, cacheStorage: CacheManager, cryptoObj: ICrypto, logger: Logger, serializableCache: ISerializableTokenCache | null, persistencePlugin: ICachePlugin | null) {\n this.clientId = clientId;\n this.cacheStorage = cacheStorage;\n this.cryptoObj = cryptoObj;\n this.logger = logger;\n this.serializableCache = serializableCache;\n this.persistencePlugin = persistencePlugin;\n }\n\n /**\n * Function which validates server authorization code response.\n * @param serverResponseHash\n * @param cachedState\n * @param cryptoObj\n */\n validateServerAuthorizationCodeResponse(serverResponseHash: ServerAuthorizationCodeResponse, cachedState: string, cryptoObj: ICrypto): void {\n\n if (!serverResponseHash.state || !cachedState) {\n throw !serverResponseHash.state ? ClientAuthError.createStateNotFoundError(\"Server State\") : ClientAuthError.createStateNotFoundError(\"Cached State\");\n }\n\n if (decodeURIComponent(serverResponseHash.state) !== decodeURIComponent(cachedState)) {\n throw ClientAuthError.createStateMismatchError();\n }\n\n // Check for error\n if (serverResponseHash.error || serverResponseHash.error_description || serverResponseHash.suberror) {\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponseHash.error, serverResponseHash.error_description, serverResponseHash.suberror)) {\n throw new InteractionRequiredAuthError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\n }\n\n throw new ServerError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\n }\n\n if (serverResponseHash.client_info) {\n buildClientInfo(serverResponseHash.client_info, cryptoObj);\n }\n }\n\n /**\n * Function which validates server authorization token response.\n * @param serverResponse\n */\n validateTokenResponse(serverResponse: ServerAuthorizationTokenResponse): void {\n // Check for error\n if (serverResponse.error || serverResponse.error_description || serverResponse.suberror) {\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponse.error, serverResponse.error_description, serverResponse.suberror)) {\n throw new InteractionRequiredAuthError(serverResponse.error, serverResponse.error_description, serverResponse.suberror);\n }\n\n const errString = `${serverResponse.error_codes} - [${serverResponse.timestamp}]: ${serverResponse.error_description} - Correlation ID: ${serverResponse.correlation_id} - Trace ID: ${serverResponse.trace_id}`;\n throw new ServerError(serverResponse.error, errString, serverResponse.suberror);\n }\n }\n\n /**\n * Returns a constructed token response based on given string. Also manages the cache updates and cleanups.\n * @param serverTokenResponse\n * @param authority\n */\n async handleServerTokenResponse(\n serverTokenResponse: ServerAuthorizationTokenResponse,\n authority: Authority,\n reqTimestamp: number,\n request: BaseAuthRequest,\n authCodePayload?: AuthorizationCodePayload,\n oboAssertion?: string,\n handlingRefreshTokenResponse?: boolean): Promise<AuthenticationResult> {\n\n // create an idToken object (not entity)\n let idTokenObj: AuthToken | undefined;\n if (serverTokenResponse.id_token) {\n idTokenObj = new AuthToken(serverTokenResponse.id_token || Constants.EMPTY_STRING, this.cryptoObj);\n \n // token nonce check (TODO: Add a warning if no nonce is given?)\n if (authCodePayload && !StringUtils.isEmpty(authCodePayload.nonce)) {\n if (idTokenObj.claims.nonce !== authCodePayload.nonce) {\n throw ClientAuthError.createNonceMismatchError();\n }\n }\n }\n\n // generate homeAccountId\n this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);\n\n // save the response tokens\n let requestStateObj: RequestStateObject | undefined;\n if (!!authCodePayload && !!authCodePayload.state) {\n requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);\n }\n\n // Add keyId from request to serverTokenResponse if defined\n serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;\n\n const cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);\n let cacheContext;\n try {\n if (this.persistencePlugin && this.serializableCache) {\n this.logger.verbose(\"Persistence enabled, calling beforeCacheAccess\");\n cacheContext = new TokenCacheContext(this.serializableCache, true);\n await this.persistencePlugin.beforeCacheAccess(cacheContext);\n }\n /*\n * When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.\n * If not present, we should return null, as it's the case that another application called removeAccount in between\n * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal.\n */\n if (handlingRefreshTokenResponse && cacheRecord.account) {\n const key = cacheRecord.account.generateAccountKey();\n const account = this.cacheStorage.getAccount(key);\n if (!account) {\n this.logger.warning(\"Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache\");\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj);\n }\n }\n await this.cacheStorage.saveCacheRecord(cacheRecord);\n } finally {\n if (this.persistencePlugin && this.serializableCache && cacheContext) {\n this.logger.verbose(\"Persistence enabled, calling afterCacheAccess\");\n await this.persistencePlugin.afterCacheAccess(cacheContext);\n }\n }\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj);\n }\n\n /**\n * Generates CacheRecord\n * @param serverTokenResponse\n * @param idTokenObj\n * @param authority\n */\n private generateCacheRecord(serverTokenResponse: ServerAuthorizationTokenResponse, authority: Authority, reqTimestamp: number, idTokenObj?: AuthToken, requestScopes?: string[], oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): CacheRecord {\n const env = authority.getPreferredCache();\n if (StringUtils.isEmpty(env)) {\n throw ClientAuthError.createInvalidCacheEnvironmentError();\n }\n\n // IdToken: non AAD scenarios can have empty realm\n let cachedIdToken: IdTokenEntity | undefined;\n let cachedAccount: AccountEntity | undefined;\n if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {\n cachedIdToken = IdTokenEntity.createIdTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.id_token || Constants.EMPTY_STRING,\n this.clientId,\n idTokenObj.claims.tid || Constants.EMPTY_STRING,\n oboAssertion\n );\n\n cachedAccount = this.generateAccountEntity(\n serverTokenResponse,\n idTokenObj,\n authority,\n oboAssertion,\n authCodePayload\n );\n }\n\n // AccessToken\n let cachedAccessToken: AccessTokenEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {\n\n // If scopes not returned in server response, use request scopes\n const responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(requestScopes || []);\n\n /*\n * Use timestamp calculated before request\n * Server may return timestamps as strings, parse to numbers if so.\n */\n const expiresIn: number = (typeof serverTokenResponse.expires_in === \"string\" ? parseInt(serverTokenResponse.expires_in, 10) : serverTokenResponse.expires_in) || 0;\n const extExpiresIn: number = (typeof serverTokenResponse.ext_expires_in === \"string\" ? parseInt(serverTokenResponse.ext_expires_in, 10) : serverTokenResponse.ext_expires_in) || 0;\n const refreshIn: number | undefined = (typeof serverTokenResponse.refresh_in === \"string\" ? parseInt(serverTokenResponse.refresh_in, 10) : serverTokenResponse.refresh_in) || undefined;\n const tokenExpirationSeconds = reqTimestamp + expiresIn;\n const extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;\n const refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;\n\n // non AAD scenarios can have empty realm\n cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.access_token || Constants.EMPTY_STRING,\n this.clientId,\n idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant,\n responseScopes.printScopes(),\n tokenExpirationSeconds,\n extendedTokenExpirationSeconds,\n this.cryptoObj,\n refreshOnSeconds,\n serverTokenResponse.token_type,\n oboAssertion,\n serverTokenResponse.key_id\n );\n }\n\n // refreshToken\n let cachedRefreshToken: RefreshTokenEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {\n cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.refresh_token || Constants.EMPTY_STRING,\n this.clientId,\n serverTokenResponse.foci,\n oboAssertion\n );\n }\n\n // appMetadata\n let cachedAppMetadata: AppMetadataEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.foci)) {\n cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);\n }\n\n return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);\n }\n\n /**\n * Generate Account\n * @param serverTokenResponse\n * @param idToken\n * @param authority\n */\n private generateAccountEntity(serverTokenResponse: ServerAuthorizationTokenResponse, idToken: AuthToken, authority: Authority, oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): AccountEntity {\n const authorityType = authority.authorityType;\n const cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : \"\";\n const msGraphhost = authCodePayload ? authCodePayload.msgraph_host : \"\";\n\n // ADFS does not require client_info in the response\n if (authorityType === AuthorityType.Adfs) {\n this.logger.verbose(\"Authority type is ADFS, creating ADFS account\");\n return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);\n }\n\n // This fallback applies to B2C as well as they fall under an AAD account type.\n if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === \"AAD\") {\n throw ClientAuthError.createClientInfoEmptyError();\n }\n\n return serverTokenResponse.client_info ?\n AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :\n AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);\n }\n\n /**\n * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.\n *\n * Optionally takes a state string that is set as-is in the response.\n *\n * @param cacheRecord\n * @param idTokenObj\n * @param fromTokenCache\n * @param stateString\n */\n static async generateAuthenticationResult(\n cryptoObj: ICrypto, \n authority: Authority,\n cacheRecord: CacheRecord, \n fromTokenCache: boolean, \n request: BaseAuthRequest,\n idTokenObj?: AuthToken,\n requestState?: RequestStateObject): Promise<AuthenticationResult> {\n let accessToken: string = \"\";\n let responseScopes: Array<string> = [];\n let expiresOn: Date | null = null;\n let extExpiresOn: Date | undefined;\n let familyId: string = Constants.EMPTY_STRING;\n\n if (cacheRecord.accessToken) {\n if (cacheRecord.accessToken.tokenType === AuthenticationScheme.POP) {\n const popTokenGenerator: PopTokenGenerator = new PopTokenGenerator(cryptoObj);\n accessToken = await popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request);\n } else {\n accessToken = cacheRecord.accessToken.secret;\n }\n responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();\n expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);\n extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);\n }\n\n if (cacheRecord.appMetadata) {\n familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;\n }\n const uid = idTokenObj?.claims.oid || idTokenObj?.claims.sub || Constants.EMPTY_STRING;\n const tid = idTokenObj?.claims.tid || Constants.EMPTY_STRING;\n\n return {\n authority: authority.canonicalAuthority,\n uniqueId: uid,\n tenantId: tid,\n scopes: responseScopes,\n account: cacheRecord.account ? cacheRecord.account.getAccountInfo() : null,\n idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,\n idTokenClaims: idTokenObj ? idTokenObj.claims : {},\n accessToken: accessToken,\n fromCache: fromTokenCache,\n expiresOn: expiresOn,\n correlationId: request.correlationId,\n extExpiresOn: extExpiresOn,\n familyId: familyId,\n tokenType: cacheRecord.accessToken?.tokenType || Constants.EMPTY_STRING,\n state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,\n cloudGraphHostName: cacheRecord.account?.cloudGraphHostName || Constants.EMPTY_STRING,\n msGraphHost: cacheRecord.account?.msGraphHost || Constants.EMPTY_STRING\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAmCA;;;;IAYI,yBAAY,QAAgB,EAAE,YAA0B,EAAE,SAAkB,EAAE,MAAc,EAAE,iBAAiD,EAAE,iBAAsC;QACnL,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;KAC9C;;;;;;;IAQD,iEAAuC,GAAvC,UAAwC,kBAAmD,EAAE,WAAmB,EAAE,SAAk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S;gCACpB,aAAa,EAAE,OAAO,CAAC,aAAa;gCACpC,YAAY,EAAE,YAAY;gCAC1B,QAAQ,EAAE,QAAQ;gCAClB,SAAS,EAAE,OAAA,WAAW,CAAC,WAAW,0CAAE,SAAS,KAAI,SAAS,CAAC,YAAY;gCACvE,KAAK,EAAE,YAAY,GAAG,YAAY,CAAC,gBAAgB,GAAG,SAAS,CAAC,YAAY;gCAC5E,kBAAkB,EAAE,OAAA,WAAW,CAAC,OAAO,0CAAE,kBAAkB,KAAI,SAAS,CAAC,YAAY;gCACrF,WAAW,EAAE,OAAA,WAAW,CAAC,OAAO,0CAAE,WAAW,KAAI,SAAS,CAAC,YAAY;6BAC1E,EAAC;;;;KACL;IACL,sBAAC;AAAD,CAAC;;;;"}
@@ -1,6 +1,7 @@
1
+ import { AuthenticationScheme } from "../utils/Constants";
1
2
  /**
2
3
  * Deserialized response object from server authorization code request.
3
- * - token_type: Indicates the token type value. The only type that Azure AD supports is Bearer.
4
+ * - token_type: Indicates the token type value. Can be either Bearer or pop.
4
5
  * - scope: The scopes that the access_token is valid for.
5
6
  * - expires_in: How long the access token is valid (in seconds).
6
7
  * - refresh_in: Duration afer which a token should be renewed, regardless of expiration.
@@ -8,6 +9,7 @@
8
9
  * - access_token: The requested access token. The app can use this token to authenticate to the secured resource, such as a web API.
9
10
  * - refresh_token: An OAuth 2.0 refresh token. The app can use this token acquire additional access tokens after the current access token expires.
10
11
  * - id_token: A JSON Web Token (JWT). The app can decode the segments of this token to request information about the user who signed in.
12
+ * - key_id: A string that uniquely identifies a public key that the request is bound to.
11
13
  *
12
14
  * In case of error:
13
15
  * - error: An error code string that can be used to classify types of errors that occur, and can be used to react to errors.
@@ -18,7 +20,7 @@
18
20
  * - correlation_id: A unique identifier for the request that can help in diagnostics across components.
19
21
  */
20
22
  export declare type ServerAuthorizationTokenResponse = {
21
- token_type?: string;
23
+ token_type?: AuthenticationScheme;
22
24
  scope?: string;
23
25
  expires_in?: number;
24
26
  refresh_in?: number;
@@ -28,6 +30,7 @@ export declare type ServerAuthorizationTokenResponse = {
28
30
  id_token?: string;
29
31
  client_info?: string;
30
32
  foci?: string;
33
+ key_id?: string;
31
34
  error?: string;
32
35
  error_description?: string;
33
36
  error_codes?: Array<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"ServerAuthorizationTokenResponse.d.ts","sourceRoot":"","sources":["../../src/response/ServerAuthorizationTokenResponse.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,oBAAY,gCAAgC,GAAG;IAE3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC"}
1
+ {"version":3,"file":"ServerAuthorizationTokenResponse.d.ts","sourceRoot":"","sources":["../../src/response/ServerAuthorizationTokenResponse.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,oBAAY,gCAAgC,GAAG;IAE3C,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC"}
@@ -1,8 +1,8 @@
1
- /*! @azure/msal-common v4.5.0 2021-07-22 */
1
+ /*! @azure/msal-common v5.1.0 2021-11-02 */
2
2
  'use strict';
3
- import { SERVER_TELEM_CONSTANTS, CacheOutcome, Constants as Constants$1, Separators } from '../../utils/Constants.js';
4
- import { StringUtils as StringUtils$1 } from '../../utils/StringUtils.js';
5
- import { ServerTelemetryEntity as ServerTelemetryEntity$1 } from '../../cache/entities/ServerTelemetryEntity.js';
3
+ import { SERVER_TELEM_CONSTANTS, CacheOutcome, Constants, Separators } from '../../utils/Constants.js';
4
+ import { ServerTelemetryEntity } from '../../cache/entities/ServerTelemetryEntity.js';
5
+ import { StringUtils } from '../../utils/StringUtils.js';
6
6
 
7
7
  /*
8
8
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -14,8 +14,8 @@ var ServerTelemetryManager = /** @class */ (function () {
14
14
  this.cacheManager = cacheManager;
15
15
  this.apiId = telemetryRequest.apiId;
16
16
  this.correlationId = telemetryRequest.correlationId;
17
- this.wrapperSKU = telemetryRequest.wrapperSKU || Constants$1.EMPTY_STRING;
18
- this.wrapperVer = telemetryRequest.wrapperVer || Constants$1.EMPTY_STRING;
17
+ this.wrapperSKU = telemetryRequest.wrapperSKU || Constants.EMPTY_STRING;
18
+ this.wrapperVer = telemetryRequest.wrapperVer || Constants.EMPTY_STRING;
19
19
  this.telemetryCacheKey = SERVER_TELEM_CONSTANTS.CACHE_KEY + Separators.CACHE_KEY_SEPARATOR + telemetryRequest.clientId;
20
20
  }
21
21
  /**
@@ -55,10 +55,10 @@ var ServerTelemetryManager = /** @class */ (function () {
55
55
  lastRequests.errors.shift();
56
56
  }
57
57
  lastRequests.failedRequests.push(this.apiId, this.correlationId);
58
- if (!StringUtils$1.isEmpty(error.subError)) {
58
+ if (!StringUtils.isEmpty(error.subError)) {
59
59
  lastRequests.errors.push(error.subError);
60
60
  }
61
- else if (!StringUtils$1.isEmpty(error.errorCode)) {
61
+ else if (!StringUtils.isEmpty(error.errorCode)) {
62
62
  lastRequests.errors.push(error.errorCode);
63
63
  }
64
64
  else if (!!error && error.toString()) {
@@ -83,7 +83,7 @@ var ServerTelemetryManager = /** @class */ (function () {
83
83
  * Get the server telemetry entity from cache or initialize a new one
84
84
  */
85
85
  ServerTelemetryManager.prototype.getLastRequests = function () {
86
- var initialValue = new ServerTelemetryEntity$1();
86
+ var initialValue = new ServerTelemetryEntity();
87
87
  var lastRequests = this.cacheManager.getServerTelemetry(this.telemetryCacheKey);
88
88
  return lastRequests || initialValue;
89
89
  };
@@ -100,7 +100,7 @@ var ServerTelemetryManager = /** @class */ (function () {
100
100
  }
101
101
  else {
102
102
  // Partial data was flushed to server, construct a new telemetry cache item with errors that were not flushed
103
- var serverTelemEntity = new ServerTelemetryEntity$1();
103
+ var serverTelemEntity = new ServerTelemetryEntity();
104
104
  serverTelemEntity.failedRequests = lastRequests.failedRequests.slice(numErrorsFlushed * 2); // failedRequests contains 2 items for each error
105
105
  serverTelemEntity.errors = lastRequests.errors.slice(numErrorsFlushed);
106
106
  this.cacheManager.setServerTelemetry(this.telemetryCacheKey, serverTelemEntity);
@@ -117,9 +117,9 @@ var ServerTelemetryManager = /** @class */ (function () {
117
117
  var errorCount = serverTelemetryEntity.errors.length;
118
118
  for (i = 0; i < errorCount; i++) {
119
119
  // failedRequests parameter contains pairs of apiId and correlationId, multiply index by 2 to preserve pairs
120
- var apiId = serverTelemetryEntity.failedRequests[2 * i] || Constants$1.EMPTY_STRING;
121
- var correlationId = serverTelemetryEntity.failedRequests[2 * i + 1] || Constants$1.EMPTY_STRING;
122
- var errorCode = serverTelemetryEntity.errors[i] || Constants$1.EMPTY_STRING;
120
+ var apiId = serverTelemetryEntity.failedRequests[2 * i] || Constants.EMPTY_STRING;
121
+ var correlationId = serverTelemetryEntity.failedRequests[2 * i + 1] || Constants.EMPTY_STRING;
122
+ var errorCode = serverTelemetryEntity.errors[i] || Constants.EMPTY_STRING;
123
123
  // Count number of characters that would be added to header, each character is 1 byte. Add 3 at the end to account for separators
124
124
  dataSize += apiId.toString().length + correlationId.toString().length + errorCode.length + 3;
125
125
  if (dataSize < SERVER_TELEM_CONSTANTS.MAX_LAST_HEADER_BYTES) {
@@ -1 +1 @@
1
- {"version":3,"file":"ServerTelemetryManager.js","sources":["../../../src/telemetry/server/ServerTelemetryManager.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { SERVER_TELEM_CONSTANTS, Separators, CacheOutcome, Constants, RegionDiscoverySources, RegionDiscoveryOutcomes } from \"../../utils/Constants\";\r\nimport { CacheManager } from \"../../cache/CacheManager\";\r\nimport { AuthError } from \"../../error/AuthError\";\r\nimport { ServerTelemetryRequest } from \"./ServerTelemetryRequest\";\r\nimport { ServerTelemetryEntity } from \"../../cache/entities/ServerTelemetryEntity\";\r\nimport { StringUtils } from \"../../utils/StringUtils\";\r\nimport { RegionDiscoveryMetadata } from \"../../authority/RegionDiscoveryMetadata\";\r\n\r\nexport class ServerTelemetryManager {\r\n private cacheManager: CacheManager;\r\n private apiId: number;\r\n private correlationId: string;\r\n private telemetryCacheKey: string;\r\n private wrapperSKU: String;\r\n private wrapperVer: String;\r\n private regionUsed: string | undefined;\r\n private regionSource: RegionDiscoverySources | undefined;\r\n private regionOutcome: RegionDiscoveryOutcomes | undefined;\r\n private cacheOutcome: CacheOutcome = CacheOutcome.NO_CACHE_HIT;\r\n\r\n constructor(telemetryRequest: ServerTelemetryRequest, cacheManager: CacheManager) {\r\n this.cacheManager = cacheManager;\r\n this.apiId = telemetryRequest.apiId;\r\n this.correlationId = telemetryRequest.correlationId;\r\n this.wrapperSKU = telemetryRequest.wrapperSKU || Constants.EMPTY_STRING;\r\n this.wrapperVer = telemetryRequest.wrapperVer || Constants.EMPTY_STRING;\r\n\r\n this.telemetryCacheKey = SERVER_TELEM_CONSTANTS.CACHE_KEY + Separators.CACHE_KEY_SEPARATOR + telemetryRequest.clientId;\r\n }\r\n\r\n /**\r\n * API to add MSER Telemetry to request\r\n */\r\n generateCurrentRequestHeaderValue(): string {\r\n const request = `${this.apiId}${SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR}${this.cacheOutcome}`;\r\n const platformFields = [this.wrapperSKU, this.wrapperVer].join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\r\n const regionDiscoveryFields = this.getRegionDiscoveryFields();\r\n const requestWithRegionDiscoveryFields = [request, regionDiscoveryFields].join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\r\n\r\n return [SERVER_TELEM_CONSTANTS.SCHEMA_VERSION, requestWithRegionDiscoveryFields, platformFields].join(SERVER_TELEM_CONSTANTS.CATEGORY_SEPARATOR);\r\n }\r\n\r\n /**\r\n * API to add MSER Telemetry for the last failed request\r\n */\r\n generateLastRequestHeaderValue(): string {\r\n const lastRequests = this.getLastRequests();\r\n\r\n const maxErrors = ServerTelemetryManager.maxErrorsToSend(lastRequests);\r\n const failedRequests = lastRequests.failedRequests.slice(0, 2*maxErrors).join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\r\n const errors = lastRequests.errors.slice(0, maxErrors).join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\r\n const errorCount = lastRequests.errors.length;\r\n\r\n // Indicate whether this header contains all data or partial data\r\n const overflow = maxErrors < errorCount ? SERVER_TELEM_CONSTANTS.OVERFLOW_TRUE : SERVER_TELEM_CONSTANTS.OVERFLOW_FALSE;\r\n const platformFields = [errorCount, overflow].join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\r\n\r\n return [SERVER_TELEM_CONSTANTS.SCHEMA_VERSION, lastRequests.cacheHits, failedRequests, errors, platformFields].join(SERVER_TELEM_CONSTANTS.CATEGORY_SEPARATOR);\r\n }\r\n\r\n /**\r\n * API to cache token failures for MSER data capture\r\n * @param error\r\n */\r\n cacheFailedRequest(error: AuthError): void {\r\n const lastRequests = this.getLastRequests();\r\n if (lastRequests.errors.length >= SERVER_TELEM_CONSTANTS.MAX_CACHED_ERRORS) {\r\n // Remove a cached error to make room, first in first out\r\n lastRequests.failedRequests.shift(); // apiId\r\n lastRequests.failedRequests.shift(); // correlationId\r\n lastRequests.errors.shift();\r\n }\r\n \r\n lastRequests.failedRequests.push(this.apiId, this.correlationId);\r\n\r\n if (!StringUtils.isEmpty(error.subError)) {\r\n lastRequests.errors.push(error.subError);\r\n } else if (!StringUtils.isEmpty(error.errorCode)) {\r\n lastRequests.errors.push(error.errorCode);\r\n } else if (!!error && error.toString()) {\r\n lastRequests.errors.push(error.toString());\r\n } else {\r\n lastRequests.errors.push(SERVER_TELEM_CONSTANTS.UNKNOWN_ERROR);\r\n }\r\n\r\n this.cacheManager.setServerTelemetry(this.telemetryCacheKey, lastRequests);\r\n\r\n return;\r\n }\r\n\r\n /**\r\n * Update server telemetry cache entry by incrementing cache hit counter\r\n */\r\n incrementCacheHits(): number {\r\n const lastRequests = this.getLastRequests();\r\n lastRequests.cacheHits += 1;\r\n\r\n this.cacheManager.setServerTelemetry(this.telemetryCacheKey, lastRequests);\r\n return lastRequests.cacheHits;\r\n }\r\n\r\n /**\r\n * Get the server telemetry entity from cache or initialize a new one\r\n */\r\n getLastRequests(): ServerTelemetryEntity {\r\n const initialValue: ServerTelemetryEntity = new ServerTelemetryEntity();\r\n const lastRequests = this.cacheManager.getServerTelemetry(this.telemetryCacheKey) as ServerTelemetryEntity;\r\n\r\n return lastRequests || initialValue;\r\n }\r\n\r\n /**\r\n * Remove server telemetry cache entry\r\n */\r\n clearTelemetryCache(): void {\r\n const lastRequests = this.getLastRequests();\r\n const numErrorsFlushed = ServerTelemetryManager.maxErrorsToSend(lastRequests);\r\n const errorCount = lastRequests.errors.length;\r\n if (numErrorsFlushed === errorCount) {\r\n // All errors were sent on last request, clear Telemetry cache\r\n this.cacheManager.removeItem(this.telemetryCacheKey);\r\n } else {\r\n // Partial data was flushed to server, construct a new telemetry cache item with errors that were not flushed\r\n const serverTelemEntity = new ServerTelemetryEntity();\r\n serverTelemEntity.failedRequests = lastRequests.failedRequests.slice(numErrorsFlushed*2); // failedRequests contains 2 items for each error\r\n serverTelemEntity.errors = lastRequests.errors.slice(numErrorsFlushed);\r\n\r\n this.cacheManager.setServerTelemetry(this.telemetryCacheKey, serverTelemEntity);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the maximum number of errors that can be flushed to the server in the next network request\r\n * @param serverTelemetryEntity\r\n */\r\n static maxErrorsToSend(serverTelemetryEntity: ServerTelemetryEntity): number {\r\n let i;\r\n let maxErrors = 0;\r\n let dataSize = 0;\r\n const errorCount = serverTelemetryEntity.errors.length;\r\n for (i = 0; i < errorCount; i++) {\r\n // failedRequests parameter contains pairs of apiId and correlationId, multiply index by 2 to preserve pairs\r\n const apiId = serverTelemetryEntity.failedRequests[2*i] || Constants.EMPTY_STRING;\r\n const correlationId = serverTelemetryEntity.failedRequests[2*i + 1] || Constants.EMPTY_STRING;\r\n const errorCode = serverTelemetryEntity.errors[i] || Constants.EMPTY_STRING;\r\n\r\n // Count number of characters that would be added to header, each character is 1 byte. Add 3 at the end to account for separators\r\n dataSize += apiId.toString().length + correlationId.toString().length + errorCode.length + 3;\r\n\r\n if (dataSize < SERVER_TELEM_CONSTANTS.MAX_LAST_HEADER_BYTES) {\r\n // Adding this entry to the header would still keep header size below the limit\r\n maxErrors += 1;\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n return maxErrors;\r\n }\r\n\r\n /**\r\n * Get the region discovery fields\r\n * \r\n * @returns string\r\n */\r\n getRegionDiscoveryFields(): string {\r\n const regionDiscoveryFields: string[] = [];\r\n\r\n regionDiscoveryFields.push(this.regionUsed || \"\");\r\n regionDiscoveryFields.push(this.regionSource || \"\");\r\n regionDiscoveryFields.push(this.regionOutcome || \"\");\r\n\r\n return regionDiscoveryFields.join(\",\");\r\n }\r\n\r\n /**\r\n * Update the region discovery metadata\r\n * \r\n * @param regionDiscoveryMetadata\r\n * @returns void\r\n */\r\n updateRegionDiscoveryMetadata(regionDiscoveryMetadata: RegionDiscoveryMetadata): void {\r\n this.regionUsed = regionDiscoveryMetadata.region_used;\r\n this.regionSource = regionDiscoveryMetadata.region_source;\r\n this.regionOutcome = regionDiscoveryMetadata.region_outcome;\r\n }\r\n\r\n /**\r\n * Set cache outcome \r\n */\r\n setCacheOutcome(cacheOutcome: CacheOutcome): void {\r\n this.cacheOutcome = cacheOutcome;\r\n }\r\n}\r\n"],"names":["Constants","StringUtils","ServerTelemetryEntity"],"mappings":";;;;;;AAAA;;;;;IAyBI,gCAAY,gBAAwC,EAAE,YAA0B;QAFxE,iBAAY,GAAiB,YAAY,CAAC,YAAY,CAAC;QAG3D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,aAAa,CAAC;QACpD,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I,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QAClD,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QACpD,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;QAErD,OAAO,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC1C;;;;;;;IAQD,8DAA6B,GAA7B,UAA8B,uBAAgD;QAC1E,IAAI,CAAC,UAAU,GAAG,uBAAuB,CAAC,WAAW,CAAC;QACtD,IAAI,CAAC,YAAY,GAAG,uBAAuB,CAAC,aAAa,CAAC;QAC1D,IAAI,CAAC,aAAa,GAAG,uBAAuB,CAAC,cAAc,CAAC;KAC/D;;;;IAKD,gDAAe,GAAf,UAAgB,YAA0B;QACtC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;KACpC;IACL,6BAAC;AAAD,CAAC;;;;"}
1
+ {"version":3,"file":"ServerTelemetryManager.js","sources":["../../../src/telemetry/server/ServerTelemetryManager.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { SERVER_TELEM_CONSTANTS, Separators, CacheOutcome, Constants, RegionDiscoverySources, RegionDiscoveryOutcomes } from \"../../utils/Constants\";\nimport { CacheManager } from \"../../cache/CacheManager\";\nimport { AuthError } from \"../../error/AuthError\";\nimport { ServerTelemetryRequest } from \"./ServerTelemetryRequest\";\nimport { ServerTelemetryEntity } from \"../../cache/entities/ServerTelemetryEntity\";\nimport { StringUtils } from \"../../utils/StringUtils\";\nimport { RegionDiscoveryMetadata } from \"../../authority/RegionDiscoveryMetadata\";\n\nexport class ServerTelemetryManager {\n private cacheManager: CacheManager;\n private apiId: number;\n private correlationId: string;\n private telemetryCacheKey: string;\n private wrapperSKU: String;\n private wrapperVer: String;\n private regionUsed: string | undefined;\n private regionSource: RegionDiscoverySources | undefined;\n private regionOutcome: RegionDiscoveryOutcomes | undefined;\n private cacheOutcome: CacheOutcome = CacheOutcome.NO_CACHE_HIT;\n\n constructor(telemetryRequest: ServerTelemetryRequest, cacheManager: CacheManager) {\n this.cacheManager = cacheManager;\n this.apiId = telemetryRequest.apiId;\n this.correlationId = telemetryRequest.correlationId;\n this.wrapperSKU = telemetryRequest.wrapperSKU || Constants.EMPTY_STRING;\n this.wrapperVer = telemetryRequest.wrapperVer || Constants.EMPTY_STRING;\n\n this.telemetryCacheKey = SERVER_TELEM_CONSTANTS.CACHE_KEY + Separators.CACHE_KEY_SEPARATOR + telemetryRequest.clientId;\n }\n\n /**\n * API to add MSER Telemetry to request\n */\n generateCurrentRequestHeaderValue(): string {\n const request = `${this.apiId}${SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR}${this.cacheOutcome}`;\n const platformFields = [this.wrapperSKU, this.wrapperVer].join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\n const regionDiscoveryFields = this.getRegionDiscoveryFields();\n const requestWithRegionDiscoveryFields = [request, regionDiscoveryFields].join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\n\n return [SERVER_TELEM_CONSTANTS.SCHEMA_VERSION, requestWithRegionDiscoveryFields, platformFields].join(SERVER_TELEM_CONSTANTS.CATEGORY_SEPARATOR);\n }\n\n /**\n * API to add MSER Telemetry for the last failed request\n */\n generateLastRequestHeaderValue(): string {\n const lastRequests = this.getLastRequests();\n\n const maxErrors = ServerTelemetryManager.maxErrorsToSend(lastRequests);\n const failedRequests = lastRequests.failedRequests.slice(0, 2*maxErrors).join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\n const errors = lastRequests.errors.slice(0, maxErrors).join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\n const errorCount = lastRequests.errors.length;\n\n // Indicate whether this header contains all data or partial data\n const overflow = maxErrors < errorCount ? SERVER_TELEM_CONSTANTS.OVERFLOW_TRUE : SERVER_TELEM_CONSTANTS.OVERFLOW_FALSE;\n const platformFields = [errorCount, overflow].join(SERVER_TELEM_CONSTANTS.VALUE_SEPARATOR);\n\n return [SERVER_TELEM_CONSTANTS.SCHEMA_VERSION, lastRequests.cacheHits, failedRequests, errors, platformFields].join(SERVER_TELEM_CONSTANTS.CATEGORY_SEPARATOR);\n }\n\n /**\n * API to cache token failures for MSER data capture\n * @param error\n */\n cacheFailedRequest(error: AuthError): void {\n const lastRequests = this.getLastRequests();\n if (lastRequests.errors.length >= SERVER_TELEM_CONSTANTS.MAX_CACHED_ERRORS) {\n // Remove a cached error to make room, first in first out\n lastRequests.failedRequests.shift(); // apiId\n lastRequests.failedRequests.shift(); // correlationId\n lastRequests.errors.shift();\n }\n \n lastRequests.failedRequests.push(this.apiId, this.correlationId);\n\n if (!StringUtils.isEmpty(error.subError)) {\n lastRequests.errors.push(error.subError);\n } else if (!StringUtils.isEmpty(error.errorCode)) {\n lastRequests.errors.push(error.errorCode);\n } else if (!!error && error.toString()) {\n lastRequests.errors.push(error.toString());\n } else {\n lastRequests.errors.push(SERVER_TELEM_CONSTANTS.UNKNOWN_ERROR);\n }\n\n this.cacheManager.setServerTelemetry(this.telemetryCacheKey, lastRequests);\n\n return;\n }\n\n /**\n * Update server telemetry cache entry by incrementing cache hit counter\n */\n incrementCacheHits(): number {\n const lastRequests = this.getLastRequests();\n lastRequests.cacheHits += 1;\n\n this.cacheManager.setServerTelemetry(this.telemetryCacheKey, lastRequests);\n return lastRequests.cacheHits;\n }\n\n /**\n * Get the server telemetry entity from cache or initialize a new one\n */\n getLastRequests(): ServerTelemetryEntity {\n const initialValue: ServerTelemetryEntity = new ServerTelemetryEntity();\n const lastRequests = this.cacheManager.getServerTelemetry(this.telemetryCacheKey) as ServerTelemetryEntity;\n\n return lastRequests || initialValue;\n }\n\n /**\n * Remove server telemetry cache entry\n */\n clearTelemetryCache(): void {\n const lastRequests = this.getLastRequests();\n const numErrorsFlushed = ServerTelemetryManager.maxErrorsToSend(lastRequests);\n const errorCount = lastRequests.errors.length;\n if (numErrorsFlushed === errorCount) {\n // All errors were sent on last request, clear Telemetry cache\n this.cacheManager.removeItem(this.telemetryCacheKey);\n } else {\n // Partial data was flushed to server, construct a new telemetry cache item with errors that were not flushed\n const serverTelemEntity = new ServerTelemetryEntity();\n serverTelemEntity.failedRequests = lastRequests.failedRequests.slice(numErrorsFlushed*2); // failedRequests contains 2 items for each error\n serverTelemEntity.errors = lastRequests.errors.slice(numErrorsFlushed);\n\n this.cacheManager.setServerTelemetry(this.telemetryCacheKey, serverTelemEntity);\n }\n }\n\n /**\n * Returns the maximum number of errors that can be flushed to the server in the next network request\n * @param serverTelemetryEntity\n */\n static maxErrorsToSend(serverTelemetryEntity: ServerTelemetryEntity): number {\n let i;\n let maxErrors = 0;\n let dataSize = 0;\n const errorCount = serverTelemetryEntity.errors.length;\n for (i = 0; i < errorCount; i++) {\n // failedRequests parameter contains pairs of apiId and correlationId, multiply index by 2 to preserve pairs\n const apiId = serverTelemetryEntity.failedRequests[2*i] || Constants.EMPTY_STRING;\n const correlationId = serverTelemetryEntity.failedRequests[2*i + 1] || Constants.EMPTY_STRING;\n const errorCode = serverTelemetryEntity.errors[i] || Constants.EMPTY_STRING;\n\n // Count number of characters that would be added to header, each character is 1 byte. Add 3 at the end to account for separators\n dataSize += apiId.toString().length + correlationId.toString().length + errorCode.length + 3;\n\n if (dataSize < SERVER_TELEM_CONSTANTS.MAX_LAST_HEADER_BYTES) {\n // Adding this entry to the header would still keep header size below the limit\n maxErrors += 1;\n } else {\n break;\n }\n }\n\n return maxErrors;\n }\n\n /**\n * Get the region discovery fields\n * \n * @returns string\n */\n getRegionDiscoveryFields(): string {\n const regionDiscoveryFields: string[] = [];\n\n regionDiscoveryFields.push(this.regionUsed || \"\");\n regionDiscoveryFields.push(this.regionSource || \"\");\n regionDiscoveryFields.push(this.regionOutcome || \"\");\n\n return regionDiscoveryFields.join(\",\");\n }\n\n /**\n * Update the region discovery metadata\n * \n * @param regionDiscoveryMetadata\n * @returns void\n */\n updateRegionDiscoveryMetadata(regionDiscoveryMetadata: RegionDiscoveryMetadata): void {\n this.regionUsed = regionDiscoveryMetadata.region_used;\n this.regionSource = regionDiscoveryMetadata.region_source;\n this.regionOutcome = regionDiscoveryMetadata.region_outcome;\n }\n\n /**\n * Set cache outcome \n */\n setCacheOutcome(cacheOutcome: CacheOutcome): void {\n this.cacheOutcome = cacheOutcome;\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA;;;;;IAyBI,gCAAY,gBAAwC,EAAE,YAA0B;QAFxE,iBAAY,GAAiB,YAAY,CAAC,YAAY,CAAC;QAG3D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,aAAa,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,UAAU,IAAI,SAAS,CAAC,YAAY,CAAC;QACxE,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,UAAU,IAAI,SAAS,CAAC,YAAY,CAAC;QAExE,IAAI,CAAC,iBAAiB,GAAG,sBAAsB,CAAC,SAAS,GAAG,UAAU,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,QAAQ,CAAC;KAC1H;;;;IAKD,kEAAiC,GAAjC;QACI,IAAM,OAAO,GAAG,KAAG,IAAI,CAAC,KAAK,GAAG,sBAAsB,CAAC,eAAe,GAAG,IAAI,CAAC,YAAc,CAAC;QAC7F,IAAM,cAAc,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC;QACvG,IAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9D,IAAM,gCAAgC,GAAG,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC;Q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