@azure/msal-common 14.1.0 → 14.2.0-alpha.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 (230) hide show
  1. package/dist/account/AccountInfo.d.ts +31 -31
  2. package/dist/account/AuthToken.d.ts +17 -17
  3. package/dist/account/AuthToken.mjs +58 -58
  4. package/dist/account/CcsCredential.d.ts +9 -9
  5. package/dist/account/CcsCredential.mjs +8 -8
  6. package/dist/account/ClientCredentials.d.ts +14 -14
  7. package/dist/account/ClientInfo.d.ts +19 -19
  8. package/dist/account/ClientInfo.mjs +37 -37
  9. package/dist/account/TokenClaims.d.ts +65 -65
  10. package/dist/authority/Authority.d.ts +250 -235
  11. package/dist/authority/Authority.d.ts.map +1 -1
  12. package/dist/authority/Authority.mjs +795 -740
  13. package/dist/authority/Authority.mjs.map +1 -1
  14. package/dist/authority/AuthorityFactory.d.ts +31 -31
  15. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  16. package/dist/authority/AuthorityFactory.mjs +48 -48
  17. package/dist/authority/AuthorityMetadata.d.ts +646 -623
  18. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  19. package/dist/authority/AuthorityMetadata.mjs +941 -885
  20. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  21. package/dist/authority/AuthorityOptions.d.ts +27 -21
  22. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  23. package/dist/authority/AuthorityOptions.mjs +18 -18
  24. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  25. package/dist/authority/AuthorityType.d.ts +10 -10
  26. package/dist/authority/AuthorityType.mjs +13 -13
  27. package/dist/authority/AzureRegion.d.ts +1 -1
  28. package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
  29. package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
  30. package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
  31. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +8 -8
  32. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
  33. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +8 -8
  34. package/dist/authority/ImdsOptions.d.ts +5 -5
  35. package/dist/authority/OIDCOptions.d.ts +8 -8
  36. package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
  37. package/dist/authority/OpenIdConfigResponse.mjs +10 -10
  38. package/dist/authority/ProtocolMode.d.ts +8 -8
  39. package/dist/authority/ProtocolMode.mjs +11 -11
  40. package/dist/authority/RegionDiscovery.d.ts +32 -32
  41. package/dist/authority/RegionDiscovery.mjs +106 -106
  42. package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
  43. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
  44. package/dist/cache/CacheManager.d.ts +480 -464
  45. package/dist/cache/CacheManager.d.ts.map +1 -1
  46. package/dist/cache/CacheManager.mjs +1089 -1049
  47. package/dist/cache/CacheManager.mjs.map +1 -1
  48. package/dist/cache/entities/AccessTokenEntity.d.ts +56 -56
  49. package/dist/cache/entities/AccessTokenEntity.mjs +109 -109
  50. package/dist/cache/entities/AccountEntity.d.ts +101 -101
  51. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  52. package/dist/cache/entities/AccountEntity.mjs +218 -220
  53. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  54. package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
  55. package/dist/cache/entities/AppMetadataEntity.mjs +66 -66
  56. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -48
  57. package/dist/cache/entities/AuthorityMetadataEntity.mjs +78 -78
  58. package/dist/cache/entities/CacheRecord.d.ts +14 -14
  59. package/dist/cache/entities/CacheRecord.mjs +14 -14
  60. package/dist/cache/entities/CredentialEntity.d.ts +88 -88
  61. package/dist/cache/entities/CredentialEntity.mjs +136 -136
  62. package/dist/cache/entities/IdTokenEntity.d.ts +34 -34
  63. package/dist/cache/entities/IdTokenEntity.mjs +56 -56
  64. package/dist/cache/entities/RefreshTokenEntity.d.ts +36 -36
  65. package/dist/cache/entities/RefreshTokenEntity.mjs +59 -59
  66. package/dist/cache/entities/ServerTelemetryEntity.d.ts +12 -12
  67. package/dist/cache/entities/ServerTelemetryEntity.mjs +27 -27
  68. package/dist/cache/entities/ThrottlingEntity.d.ts +13 -13
  69. package/dist/cache/entities/ThrottlingEntity.mjs +23 -23
  70. package/dist/cache/interface/ICacheManager.d.ts +166 -166
  71. package/dist/cache/interface/ICachePlugin.d.ts +5 -5
  72. package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
  73. package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
  74. package/dist/cache/persistence/TokenCacheContext.mjs +25 -25
  75. package/dist/cache/utils/CacheTypes.d.ts +67 -66
  76. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  77. package/dist/client/AuthorizationCodeClient.d.ts +73 -73
  78. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  79. package/dist/client/AuthorizationCodeClient.mjs +408 -408
  80. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  81. package/dist/client/BaseClient.d.ts +51 -51
  82. package/dist/client/BaseClient.d.ts.map +1 -1
  83. package/dist/client/BaseClient.mjs +100 -99
  84. package/dist/client/BaseClient.mjs.map +1 -1
  85. package/dist/client/RefreshTokenClient.d.ts +35 -35
  86. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  87. package/dist/client/RefreshTokenClient.mjs +187 -187
  88. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  89. package/dist/client/SilentFlowClient.d.ts +27 -26
  90. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  91. package/dist/client/SilentFlowClient.mjs +118 -125
  92. package/dist/client/SilentFlowClient.mjs.map +1 -1
  93. package/dist/config/AppTokenProvider.d.ts +38 -38
  94. package/dist/config/ClientConfiguration.d.ts +150 -150
  95. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  96. package/dist/config/ClientConfiguration.mjs +96 -98
  97. package/dist/config/ClientConfiguration.mjs.map +1 -1
  98. package/dist/crypto/ICrypto.d.ts +58 -58
  99. package/dist/crypto/ICrypto.mjs +30 -30
  100. package/dist/crypto/IGuidGenerator.d.ts +4 -4
  101. package/dist/crypto/JoseHeader.d.ts +22 -22
  102. package/dist/crypto/JoseHeader.mjs +37 -37
  103. package/dist/crypto/PopTokenGenerator.d.ts +60 -60
  104. package/dist/crypto/PopTokenGenerator.mjs +82 -82
  105. package/dist/crypto/SignedHttpRequest.d.ts +11 -11
  106. package/dist/error/AuthError.d.ts +44 -44
  107. package/dist/error/AuthError.mjs +46 -46
  108. package/dist/error/AuthErrorCodes.d.ts +5 -5
  109. package/dist/error/AuthErrorCodes.mjs +9 -9
  110. package/dist/error/ClientAuthError.d.ts +237 -232
  111. package/dist/error/ClientAuthError.d.ts.map +1 -1
  112. package/dist/error/ClientAuthError.mjs +250 -245
  113. package/dist/error/ClientAuthError.mjs.map +1 -1
  114. package/dist/error/ClientAuthErrorCodes.d.ts +44 -43
  115. package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -1
  116. package/dist/error/ClientAuthErrorCodes.mjs +50 -49
  117. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
  118. package/dist/error/ClientConfigurationError.d.ts +128 -128
  119. package/dist/error/ClientConfigurationError.mjs +135 -135
  120. package/dist/error/ClientConfigurationErrorCodes.d.ts +22 -22
  121. package/dist/error/ClientConfigurationErrorCodes.mjs +26 -26
  122. package/dist/error/InteractionRequiredAuthError.d.ts +57 -57
  123. package/dist/error/InteractionRequiredAuthError.mjs +76 -76
  124. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +5 -5
  125. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +11 -11
  126. package/dist/error/JoseHeaderError.d.ts +15 -15
  127. package/dist/error/JoseHeaderError.mjs +22 -22
  128. package/dist/error/JoseHeaderErrorCodes.d.ts +2 -2
  129. package/dist/error/JoseHeaderErrorCodes.mjs +6 -6
  130. package/dist/error/ServerError.d.ts +7 -7
  131. package/dist/error/ServerError.mjs +14 -14
  132. package/dist/index.cjs +8840 -8677
  133. package/dist/index.cjs.map +1 -1
  134. package/dist/index.d.ts +96 -96
  135. package/dist/index.d.ts.map +1 -1
  136. package/dist/index.mjs +3 -3
  137. package/dist/logger/Logger.d.ts +95 -95
  138. package/dist/logger/Logger.mjs +188 -188
  139. package/dist/network/INetworkModule.d.ts +29 -29
  140. package/dist/network/INetworkModule.mjs +12 -12
  141. package/dist/network/NetworkManager.d.ts +33 -33
  142. package/dist/network/NetworkManager.mjs +34 -34
  143. package/dist/network/RequestThumbprint.d.ts +16 -16
  144. package/dist/network/ThrottlingUtils.d.ts +42 -42
  145. package/dist/network/ThrottlingUtils.mjs +95 -95
  146. package/dist/packageMetadata.d.ts +2 -2
  147. package/dist/packageMetadata.d.ts.map +1 -1
  148. package/dist/packageMetadata.mjs +4 -4
  149. package/dist/packageMetadata.mjs.map +1 -1
  150. package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
  151. package/dist/request/AuthenticationHeaderParser.mjs +55 -55
  152. package/dist/request/BaseAuthRequest.d.ts +40 -40
  153. package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
  154. package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
  155. package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
  156. package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
  157. package/dist/request/CommonEndSessionRequest.d.ts +21 -21
  158. package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
  159. package/dist/request/CommonRefreshTokenRequest.d.ts +22 -22
  160. package/dist/request/CommonSilentFlowRequest.d.ts +20 -20
  161. package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
  162. package/dist/request/NativeRequest.d.ts +19 -19
  163. package/dist/request/NativeSignOutRequest.d.ts +5 -5
  164. package/dist/request/RequestParameterBuilder.d.ts +217 -217
  165. package/dist/request/RequestParameterBuilder.mjs +381 -381
  166. package/dist/request/RequestValidator.d.ts +33 -33
  167. package/dist/request/RequestValidator.mjs +81 -81
  168. package/dist/request/ScopeSet.d.ts +88 -88
  169. package/dist/request/ScopeSet.mjs +197 -197
  170. package/dist/request/StoreInCache.d.ts +8 -8
  171. package/dist/response/AuthenticationResult.d.ts +41 -41
  172. package/dist/response/AuthorizationCodePayload.d.ts +13 -13
  173. package/dist/response/DeviceCodeResponse.d.ts +25 -25
  174. package/dist/response/ExternalTokenResponse.d.ts +15 -15
  175. package/dist/response/IMDSBadResponse.d.ts +4 -4
  176. package/dist/response/ResponseHandler.d.ts +67 -67
  177. package/dist/response/ResponseHandler.d.ts.map +1 -1
  178. package/dist/response/ResponseHandler.mjs +315 -311
  179. package/dist/response/ResponseHandler.mjs.map +1 -1
  180. package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
  181. package/dist/response/ServerAuthorizationTokenResponse.d.ts +46 -46
  182. package/dist/telemetry/performance/IPerformanceClient.d.ts +51 -51
  183. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
  184. package/dist/telemetry/performance/PerformanceClient.d.ts +191 -191
  185. package/dist/telemetry/performance/PerformanceClient.mjs +409 -409
  186. package/dist/telemetry/performance/PerformanceEvent.d.ts +457 -441
  187. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  188. package/dist/telemetry/performance/PerformanceEvent.mjs +249 -242
  189. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  190. package/dist/telemetry/performance/StubPerformanceClient.d.ts +24 -24
  191. package/dist/telemetry/performance/StubPerformanceClient.mjs +76 -76
  192. package/dist/telemetry/server/ServerTelemetryManager.d.ts +66 -66
  193. package/dist/telemetry/server/ServerTelemetryManager.mjs +197 -197
  194. package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
  195. package/dist/url/IUri.d.ts +12 -12
  196. package/dist/url/UrlString.d.ts +83 -83
  197. package/dist/url/UrlString.mjs +279 -279
  198. package/dist/utils/Constants.d.ts +368 -366
  199. package/dist/utils/Constants.d.ts.map +1 -1
  200. package/dist/utils/Constants.mjs +381 -378
  201. package/dist/utils/Constants.mjs.map +1 -1
  202. package/dist/utils/FunctionWrappers.d.ts +27 -27
  203. package/dist/utils/FunctionWrappers.mjs +84 -84
  204. package/dist/utils/MsalTypes.d.ts +6 -6
  205. package/dist/utils/ProtocolUtils.d.ts +42 -42
  206. package/dist/utils/ProtocolUtils.mjs +69 -69
  207. package/dist/utils/StringUtils.d.ts +40 -40
  208. package/dist/utils/StringUtils.mjs +95 -95
  209. package/dist/utils/TimeUtils.d.ts +27 -27
  210. package/dist/utils/TimeUtils.mjs +45 -45
  211. package/package.json +1 -1
  212. package/src/authority/Authority.ts +216 -130
  213. package/src/authority/AuthorityFactory.ts +4 -4
  214. package/src/authority/AuthorityMetadata.ts +87 -0
  215. package/src/authority/AuthorityOptions.ts +9 -0
  216. package/src/cache/CacheManager.ts +120 -52
  217. package/src/cache/entities/AccountEntity.ts +0 -3
  218. package/src/cache/utils/CacheTypes.ts +1 -0
  219. package/src/client/AuthorizationCodeClient.ts +9 -2
  220. package/src/client/BaseClient.ts +9 -6
  221. package/src/client/RefreshTokenClient.ts +17 -7
  222. package/src/client/SilentFlowClient.ts +49 -49
  223. package/src/config/ClientConfiguration.ts +4 -4
  224. package/src/error/ClientAuthError.ts +8 -0
  225. package/src/error/ClientAuthErrorCodes.ts +1 -0
  226. package/src/index.ts +7 -1
  227. package/src/packageMetadata.ts +1 -1
  228. package/src/response/ResponseHandler.ts +9 -3
  229. package/src/telemetry/performance/PerformanceEvent.ts +24 -2
  230. package/src/utils/Constants.ts +4 -0
@@ -1,139 +1,132 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0-alpha.0 2023-12-07 */
2
2
  'use strict';
3
3
  import { BaseClient } from './BaseClient.mjs';
4
4
  import { TimeUtils } from '../utils/TimeUtils.mjs';
5
5
  import { RefreshTokenClient } from './RefreshTokenClient.mjs';
6
6
  import { ClientAuthError, createClientAuthError } from '../error/ClientAuthError.mjs';
7
- import { createClientConfigurationError } from '../error/ClientConfigurationError.mjs';
8
7
  import { ResponseHandler } from '../response/ResponseHandler.mjs';
9
8
  import { CacheOutcome } from '../utils/Constants.mjs';
10
9
  import { StringUtils } from '../utils/StringUtils.mjs';
11
10
  import { extractTokenClaims, checkMaxAge } from '../account/AuthToken.mjs';
11
+ import { PerformanceEvents } from '../telemetry/performance/PerformanceEvent.mjs';
12
+ import { invokeAsync } from '../utils/FunctionWrappers.mjs';
12
13
  import { tokenRefreshRequired, noAccountInSilentRequest, authTimeNotFound } from '../error/ClientAuthErrorCodes.mjs';
13
- import { tokenRequestEmpty } from '../error/ClientConfigurationErrorCodes.mjs';
14
14
 
15
- /*
16
- * Copyright (c) Microsoft Corporation. All rights reserved.
17
- * Licensed under the MIT License.
18
- */
19
- /** @internal */
20
- class SilentFlowClient extends BaseClient {
21
- constructor(configuration, performanceClient) {
22
- super(configuration, performanceClient);
23
- }
24
- /**
25
- * Retrieves a token from cache if it is still valid, or uses the cached refresh token to renew
26
- * the given token and returns the renewed token
27
- * @param request
28
- */
29
- async acquireToken(request) {
30
- try {
31
- const [authResponse, cacheOutcome] = await this.acquireCachedToken(request);
32
- // if the token is not expired but must be refreshed; get a new one in the background
33
- if (cacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
34
- this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
35
- // refresh the access token in the background
36
- const refreshTokenClient = new RefreshTokenClient(this.config, this.performanceClient);
37
- refreshTokenClient
38
- .acquireTokenByRefreshToken(request)
39
- .catch(() => {
40
- // do nothing, this is running in the background and no action is to be taken upon success or failure
41
- });
42
- }
43
- // return the cached token
44
- return authResponse;
45
- }
46
- catch (e) {
47
- if (e instanceof ClientAuthError &&
48
- e.errorCode === tokenRefreshRequired) {
49
- const refreshTokenClient = new RefreshTokenClient(this.config, this.performanceClient);
50
- return refreshTokenClient.acquireTokenByRefreshToken(request);
51
- }
52
- else {
53
- throw e;
54
- }
55
- }
56
- }
57
- /**
58
- * Retrieves token from cache or throws an error if it must be refreshed.
59
- * @param request
60
- */
61
- async acquireCachedToken(request) {
62
- let lastCacheOutcome = CacheOutcome.NOT_APPLICABLE;
63
- // Cannot renew token if no request object is given.
64
- if (!request) {
65
- throw createClientConfigurationError(tokenRequestEmpty);
66
- }
67
- if (request.forceRefresh) {
68
- // Must refresh due to present force_refresh flag.
69
- lastCacheOutcome = CacheOutcome.FORCE_REFRESH_OR_CLAIMS;
70
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.FORCE_REFRESH_OR_CLAIMS);
71
- this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
72
- throw createClientAuthError(tokenRefreshRequired);
73
- }
74
- else if (!this.config.cacheOptions.claimsBasedCachingEnabled &&
75
- !StringUtils.isEmptyObj(request.claims)) {
76
- lastCacheOutcome = CacheOutcome.FORCE_REFRESH_OR_CLAIMS;
77
- // Must refresh due to request parameters.
78
- this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because claims-based caching is disabled and claims were requested.");
79
- throw createClientAuthError(tokenRefreshRequired);
80
- }
81
- // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
82
- if (!request.account) {
83
- throw createClientAuthError(noAccountInSilentRequest);
84
- }
85
- const environment = request.authority || this.authority.getPreferredCache();
86
- const cacheRecord = this.cacheManager.readCacheRecord(request.account, request, environment);
87
- if (!cacheRecord.accessToken) {
88
- // must refresh due to non-existent access_token
89
- lastCacheOutcome = CacheOutcome.NO_CACHED_ACCESS_TOKEN;
90
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
91
- this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
92
- throw createClientAuthError(tokenRefreshRequired);
93
- }
94
- else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
95
- TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
96
- // must refresh due to the expires_in value
97
- lastCacheOutcome = CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED;
98
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
99
- this.logger.info(`SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`);
100
- throw createClientAuthError(tokenRefreshRequired);
101
- }
102
- else if (cacheRecord.accessToken.refreshOn &&
103
- TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
104
- // must refresh (in the background) due to the refresh_in value
105
- lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
106
- this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.PROACTIVELY_REFRESHED);
107
- this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'.");
108
- // don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead
109
- }
110
- if (this.config.serverTelemetryManager) {
111
- this.config.serverTelemetryManager.incrementCacheHits();
112
- }
113
- return [
114
- await this.generateResultFromCacheRecord(cacheRecord, request),
115
- lastCacheOutcome,
116
- ];
117
- }
118
- /**
119
- * Helper function to build response object from the CacheRecord
120
- * @param cacheRecord
121
- */
122
- async generateResultFromCacheRecord(cacheRecord, request) {
123
- let idTokenClaims;
124
- if (cacheRecord.idToken) {
125
- idTokenClaims = extractTokenClaims(cacheRecord.idToken.secret, this.config.cryptoInterface.base64Decode);
126
- }
127
- // token max_age check
128
- if (request.maxAge || request.maxAge === 0) {
129
- const authTime = idTokenClaims?.auth_time;
130
- if (!authTime) {
131
- throw createClientAuthError(authTimeNotFound);
132
- }
133
- checkMaxAge(authTime, request.maxAge);
134
- }
135
- return await ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, cacheRecord, true, request, idTokenClaims);
136
- }
15
+ /*
16
+ * Copyright (c) Microsoft Corporation. All rights reserved.
17
+ * Licensed under the MIT License.
18
+ */
19
+ /** @internal */
20
+ class SilentFlowClient extends BaseClient {
21
+ constructor(configuration, performanceClient) {
22
+ super(configuration, performanceClient);
23
+ }
24
+ /**
25
+ * Retrieves a token from cache if it is still valid, or uses the cached refresh token to renew
26
+ * the given token and returns the renewed token
27
+ * @param request
28
+ */
29
+ async acquireToken(request) {
30
+ try {
31
+ const [authResponse, cacheOutcome] = await this.acquireCachedToken(request);
32
+ // if the token is not expired but must be refreshed; get a new one in the background
33
+ if (cacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
34
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
35
+ // refresh the access token in the background
36
+ const refreshTokenClient = new RefreshTokenClient(this.config, this.performanceClient);
37
+ refreshTokenClient
38
+ .acquireTokenByRefreshToken(request)
39
+ .catch(() => {
40
+ // do nothing, this is running in the background and no action is to be taken upon success or failure
41
+ });
42
+ }
43
+ // return the cached token
44
+ return authResponse;
45
+ }
46
+ catch (e) {
47
+ if (e instanceof ClientAuthError &&
48
+ e.errorCode === tokenRefreshRequired) {
49
+ const refreshTokenClient = new RefreshTokenClient(this.config, this.performanceClient);
50
+ return refreshTokenClient.acquireTokenByRefreshToken(request);
51
+ }
52
+ else {
53
+ throw e;
54
+ }
55
+ }
56
+ }
57
+ /**
58
+ * Retrieves token from cache or throws an error if it must be refreshed.
59
+ * @param request
60
+ */
61
+ async acquireCachedToken(request) {
62
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.SilentFlowClientAcquireCachedToken, request.correlationId);
63
+ let lastCacheOutcome = CacheOutcome.NOT_APPLICABLE;
64
+ if (request.forceRefresh ||
65
+ (!this.config.cacheOptions.claimsBasedCachingEnabled &&
66
+ !StringUtils.isEmptyObj(request.claims))) {
67
+ // Must refresh due to present force_refresh flag.
68
+ this.setCacheOutcome(CacheOutcome.FORCE_REFRESH_OR_CLAIMS, request.correlationId);
69
+ throw createClientAuthError(tokenRefreshRequired);
70
+ }
71
+ // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
72
+ if (!request.account) {
73
+ throw createClientAuthError(noAccountInSilentRequest);
74
+ }
75
+ const environment = request.authority || this.authority.getPreferredCache();
76
+ const cacheRecord = this.cacheManager.readCacheRecord(request.account, request, environment);
77
+ if (!cacheRecord.accessToken) {
78
+ // must refresh due to non-existent access_token
79
+ this.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN, request.correlationId);
80
+ throw createClientAuthError(tokenRefreshRequired);
81
+ }
82
+ else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
83
+ TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
84
+ // must refresh due to the expires_in value
85
+ this.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED, request.correlationId);
86
+ throw createClientAuthError(tokenRefreshRequired);
87
+ }
88
+ else if (cacheRecord.accessToken.refreshOn &&
89
+ TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
90
+ // must refresh (in the background) due to the refresh_in value
91
+ lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
92
+ // don't throw ClientAuthError.createRefreshRequiredError(), return cached token instead
93
+ }
94
+ this.setCacheOutcome(lastCacheOutcome, request.correlationId);
95
+ if (this.config.serverTelemetryManager) {
96
+ this.config.serverTelemetryManager.incrementCacheHits();
97
+ }
98
+ return [
99
+ await invokeAsync(this.generateResultFromCacheRecord.bind(this), PerformanceEvents.SilentFlowClientGenerateResultFromCacheRecord, this.logger, this.performanceClient, request.correlationId)(cacheRecord, request),
100
+ lastCacheOutcome,
101
+ ];
102
+ }
103
+ setCacheOutcome(cacheOutcome, correlationId) {
104
+ this.serverTelemetryManager?.setCacheOutcome(cacheOutcome);
105
+ this.performanceClient?.addFields({
106
+ cacheOutcome: cacheOutcome,
107
+ }, correlationId);
108
+ this.logger.info(`Token refresh is required due to cache outcome: ${cacheOutcome}`);
109
+ }
110
+ /**
111
+ * Helper function to build response object from the CacheRecord
112
+ * @param cacheRecord
113
+ */
114
+ async generateResultFromCacheRecord(cacheRecord, request) {
115
+ this.performanceClient?.addQueueMeasurement(PerformanceEvents.SilentFlowClientGenerateResultFromCacheRecord, request.correlationId);
116
+ let idTokenClaims;
117
+ if (cacheRecord.idToken) {
118
+ idTokenClaims = extractTokenClaims(cacheRecord.idToken.secret, this.config.cryptoInterface.base64Decode);
119
+ }
120
+ // token max_age check
121
+ if (request.maxAge || request.maxAge === 0) {
122
+ const authTime = idTokenClaims?.auth_time;
123
+ if (!authTime) {
124
+ throw createClientAuthError(authTimeNotFound);
125
+ }
126
+ checkMaxAge(authTime, request.maxAge);
127
+ }
128
+ return await ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, cacheRecord, true, request, idTokenClaims);
129
+ }
137
130
  }
138
131
 
139
132
  export { SilentFlowClient };
@@ -1 +1 @@
1
- {"version":3,"file":"SilentFlowClient.mjs","sources":["../../src/client/SilentFlowClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;AAKA;AACA;AACA;AACA;AAiCO;AACe,MAAA,gBACL,SAAA,UAAA,CAAuB;AA4CpC,IAAA,WAAA,CAAA,aAAA,EAAA,iBAAA,EAAA;;;AAGG;AACG;AA8GN;;;AAGG,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;YACW;AAiCjB,YAAA,MAAA,CAAA,YAAA,EAAA,YAAA,CAAA,GAAA,MAAA,IAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"SilentFlowClient.mjs","sources":["../../src/client/SilentFlowClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;AAKA;AACA;AACA;AACA;;AA6EI,MAAA,gBAAA,SAAA,UAAA,CAAA;;;AAGG,KAAA;AACG;AA4FN;AAgBA;;;AAGG,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;YACW;AAqCjB,YAAA,MAAA,CAAA,YAAA,EAAA,YAAA,CAAA,GAAA,MAAA,IAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,39 +1,39 @@
1
- /**
2
- * Extensibility interface, which allows the app developer to return a token, based on the passed-in parameters, instead of fetching tokens from
3
- * the Identity Provider (AAD).
4
- * Developers need to construct and return an AppTokenProviderResult object back to MSAL. MSAL will cache the token response
5
- * in the same way it would do if the result were comming from AAD.
6
- * This extensibility point is only defined for the client_credential flow, i.e. acquireTokenByClientCredential and
7
- * meant for Azure SDK to enhance Managed Identity support.
8
- */
9
- export interface IAppTokenProvider {
10
- (appTokenProviderParameters: AppTokenProviderParameters): Promise<AppTokenProviderResult>;
11
- }
12
- /**
13
- * Input object for the IAppTokenProvider extensiblity. MSAL will create this object, which can be used
14
- * to help create an AppTokenProviderResult.
15
- *
16
- * - correlationId - the correlation Id associated with the request
17
- * - tenantId - the tenant Id for which the token must be provided
18
- * - scopes - the scopes for which the token must be provided
19
- * - claims - any extra claims that the token must satisfy
20
- */
21
- export type AppTokenProviderParameters = {
22
- readonly correlationId?: string;
23
- readonly tenantId: string;
24
- readonly scopes: Array<string>;
25
- readonly claims?: string;
26
- };
27
- /**
28
- * Output object for IAppTokenProvider extensiblity.
29
- *
30
- * - accessToken - the actual access token, typically in JWT format, that satisfies the request data AppTokenProviderParameters
31
- * - expiresInSeconds - how long the tokens has before expiry, in seconds. Similar to the "expires_in" field in an AAD token response.
32
- * - refreshInSeconds - how long the token has before it should be proactively refreshed. Similar to the "refresh_in" field in an AAD token response.
33
- */
34
- export type AppTokenProviderResult = {
35
- accessToken: string;
36
- expiresInSeconds: number;
37
- refreshInSeconds?: number;
38
- };
1
+ /**
2
+ * Extensibility interface, which allows the app developer to return a token, based on the passed-in parameters, instead of fetching tokens from
3
+ * the Identity Provider (AAD).
4
+ * Developers need to construct and return an AppTokenProviderResult object back to MSAL. MSAL will cache the token response
5
+ * in the same way it would do if the result were comming from AAD.
6
+ * This extensibility point is only defined for the client_credential flow, i.e. acquireTokenByClientCredential and
7
+ * meant for Azure SDK to enhance Managed Identity support.
8
+ */
9
+ export interface IAppTokenProvider {
10
+ (appTokenProviderParameters: AppTokenProviderParameters): Promise<AppTokenProviderResult>;
11
+ }
12
+ /**
13
+ * Input object for the IAppTokenProvider extensiblity. MSAL will create this object, which can be used
14
+ * to help create an AppTokenProviderResult.
15
+ *
16
+ * - correlationId - the correlation Id associated with the request
17
+ * - tenantId - the tenant Id for which the token must be provided
18
+ * - scopes - the scopes for which the token must be provided
19
+ * - claims - any extra claims that the token must satisfy
20
+ */
21
+ export type AppTokenProviderParameters = {
22
+ readonly correlationId?: string;
23
+ readonly tenantId: string;
24
+ readonly scopes: Array<string>;
25
+ readonly claims?: string;
26
+ };
27
+ /**
28
+ * Output object for IAppTokenProvider extensiblity.
29
+ *
30
+ * - accessToken - the actual access token, typically in JWT format, that satisfies the request data AppTokenProviderParameters
31
+ * - expiresInSeconds - how long the tokens has before expiry, in seconds. Similar to the "expires_in" field in an AAD token response.
32
+ * - refreshInSeconds - how long the token has before it should be proactively refreshed. Similar to the "refresh_in" field in an AAD token response.
33
+ */
34
+ export type AppTokenProviderResult = {
35
+ accessToken: string;
36
+ expiresInSeconds: number;
37
+ refreshInSeconds?: number;
38
+ };
39
39
  //# sourceMappingURL=AppTokenProvider.d.ts.map