@azure/msal-node 2.2.0 → 2.3.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 (216) hide show
  1. package/dist/cache/ITokenCache.d.ts +15 -15
  2. package/dist/cache/NodeStorage.cjs +401 -401
  3. package/dist/cache/NodeStorage.cjs.map +1 -1
  4. package/dist/cache/NodeStorage.d.ts +182 -182
  5. package/dist/cache/NodeStorage.d.ts.map +1 -1
  6. package/dist/cache/NodeStorage.mjs +401 -401
  7. package/dist/cache/NodeStorage.mjs.map +1 -1
  8. package/dist/cache/TokenCache.cjs +265 -265
  9. package/dist/cache/TokenCache.d.ts +90 -90
  10. package/dist/cache/TokenCache.mjs +265 -265
  11. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  12. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  13. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  14. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  15. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  16. package/dist/cache/serializer/Deserializer.cjs +173 -173
  17. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  18. package/dist/cache/serializer/Deserializer.mjs +173 -173
  19. package/dist/cache/serializer/Serializer.cjs +134 -134
  20. package/dist/cache/serializer/Serializer.d.ts +39 -39
  21. package/dist/cache/serializer/Serializer.mjs +134 -134
  22. package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
  23. package/dist/client/ClientApplication.cjs +333 -333
  24. package/dist/client/ClientApplication.cjs.map +1 -1
  25. package/dist/client/ClientApplication.d.ts +142 -142
  26. package/dist/client/ClientApplication.d.ts.map +1 -1
  27. package/dist/client/ClientApplication.mjs +334 -334
  28. package/dist/client/ClientApplication.mjs.map +1 -1
  29. package/dist/client/ClientAssertion.cjs +116 -116
  30. package/dist/client/ClientAssertion.d.ts +46 -46
  31. package/dist/client/ClientAssertion.mjs +116 -116
  32. package/dist/client/ClientCredentialClient.cjs +193 -189
  33. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  34. package/dist/client/ClientCredentialClient.d.ts +33 -33
  35. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  36. package/dist/client/ClientCredentialClient.mjs +194 -190
  37. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  38. package/dist/client/ConfidentialClientApplication.cjs +163 -163
  39. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  40. package/dist/client/ConfidentialClientApplication.mjs +163 -163
  41. package/dist/client/DeviceCodeClient.cjs +207 -207
  42. package/dist/client/DeviceCodeClient.d.ts +53 -53
  43. package/dist/client/DeviceCodeClient.mjs +207 -207
  44. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  45. package/dist/client/IPublicClientApplication.d.ts +42 -42
  46. package/dist/client/ManagedIdentityApplication.cjs +96 -0
  47. package/dist/client/ManagedIdentityApplication.cjs.map +1 -0
  48. package/dist/client/ManagedIdentityApplication.d.ts +24 -0
  49. package/dist/client/ManagedIdentityApplication.d.ts.map +1 -0
  50. package/dist/client/ManagedIdentityApplication.mjs +94 -0
  51. package/dist/client/ManagedIdentityApplication.mjs.map +1 -0
  52. package/dist/client/ManagedIdentityClient.cjs +49 -0
  53. package/dist/client/ManagedIdentityClient.cjs.map +1 -0
  54. package/dist/client/ManagedIdentityClient.d.ts +25 -0
  55. package/dist/client/ManagedIdentityClient.d.ts.map +1 -0
  56. package/dist/client/ManagedIdentityClient.mjs +47 -0
  57. package/dist/client/ManagedIdentityClient.mjs.map +1 -0
  58. package/dist/client/ManagedIdentitySources/AppService.cjs +79 -0
  59. package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -0
  60. package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -0
  61. package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -0
  62. package/dist/client/ManagedIdentitySources/AppService.mjs +77 -0
  63. package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -0
  64. package/dist/client/ManagedIdentitySources/AzureArc.cjs +107 -0
  65. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -0
  66. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +19 -0
  67. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -0
  68. package/dist/client/ManagedIdentitySources/AzureArc.mjs +104 -0
  69. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -0
  70. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +87 -0
  71. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -0
  72. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +19 -0
  73. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -0
  74. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +85 -0
  75. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -0
  76. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +7 -0
  77. package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -0
  78. package/dist/client/ManagedIdentitySources/Imds.cjs +63 -0
  79. package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -0
  80. package/dist/client/ManagedIdentitySources/Imds.d.ts +13 -0
  81. package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -0
  82. package/dist/client/ManagedIdentitySources/Imds.mjs +61 -0
  83. package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -0
  84. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +7 -0
  85. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -0
  86. package/dist/client/OnBehalfOfClient.cjs +202 -202
  87. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  88. package/dist/client/OnBehalfOfClient.mjs +202 -202
  89. package/dist/client/PublicClientApplication.cjs +229 -229
  90. package/dist/client/PublicClientApplication.d.ts +71 -71
  91. package/dist/client/PublicClientApplication.mjs +229 -229
  92. package/dist/client/UsernamePasswordClient.cjs +95 -95
  93. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  94. package/dist/client/UsernamePasswordClient.mjs +95 -95
  95. package/dist/config/Configuration.cjs +88 -72
  96. package/dist/config/Configuration.cjs.map +1 -1
  97. package/dist/config/Configuration.d.ts +122 -107
  98. package/dist/config/Configuration.d.ts.map +1 -1
  99. package/dist/config/Configuration.mjs +88 -73
  100. package/dist/config/Configuration.mjs.map +1 -1
  101. package/dist/config/ManagedIdentityId.cjs +59 -0
  102. package/dist/config/ManagedIdentityId.cjs.map +1 -0
  103. package/dist/config/ManagedIdentityId.d.ts +12 -0
  104. package/dist/config/ManagedIdentityId.d.ts.map +1 -0
  105. package/dist/config/ManagedIdentityId.mjs +57 -0
  106. package/dist/config/ManagedIdentityId.mjs.map +1 -0
  107. package/dist/config/ManagedIdentityRequestParameters.cjs +38 -0
  108. package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -0
  109. package/dist/config/ManagedIdentityRequestParameters.d.ts +12 -0
  110. package/dist/config/ManagedIdentityRequestParameters.d.ts.map +1 -0
  111. package/dist/config/ManagedIdentityRequestParameters.mjs +36 -0
  112. package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -0
  113. package/dist/crypto/CryptoProvider.cjs +75 -75
  114. package/dist/crypto/CryptoProvider.d.ts +52 -52
  115. package/dist/crypto/CryptoProvider.mjs +75 -75
  116. package/dist/crypto/GuidGenerator.cjs +22 -22
  117. package/dist/crypto/GuidGenerator.d.ts +14 -14
  118. package/dist/crypto/GuidGenerator.mjs +22 -22
  119. package/dist/crypto/HashUtils.cjs +13 -13
  120. package/dist/crypto/HashUtils.d.ts +8 -8
  121. package/dist/crypto/HashUtils.mjs +13 -13
  122. package/dist/crypto/PkceGenerator.cjs +49 -49
  123. package/dist/crypto/PkceGenerator.d.ts +22 -22
  124. package/dist/crypto/PkceGenerator.mjs +49 -49
  125. package/dist/error/ManagedIdentityError.cjs +40 -0
  126. package/dist/error/ManagedIdentityError.cjs.map +1 -0
  127. package/dist/error/ManagedIdentityError.d.ts +22 -0
  128. package/dist/error/ManagedIdentityError.d.ts.map +1 -0
  129. package/dist/error/ManagedIdentityError.mjs +36 -0
  130. package/dist/error/ManagedIdentityError.mjs.map +1 -0
  131. package/dist/error/ManagedIdentityErrorCodes.cjs +28 -0
  132. package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -0
  133. package/dist/error/ManagedIdentityErrorCodes.d.ts +10 -0
  134. package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -0
  135. package/dist/error/ManagedIdentityErrorCodes.mjs +18 -0
  136. package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -0
  137. package/dist/error/NodeAuthError.cjs +85 -85
  138. package/dist/error/NodeAuthError.d.ts +65 -65
  139. package/dist/error/NodeAuthError.mjs +85 -85
  140. package/dist/index.cjs +3 -1
  141. package/dist/index.cjs.map +1 -1
  142. package/dist/index.d.ts +44 -42
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.mjs +2 -1
  145. package/dist/index.mjs.map +1 -1
  146. package/dist/internals.cjs +8 -8
  147. package/dist/internals.d.ts +6 -6
  148. package/dist/internals.mjs +8 -8
  149. package/dist/network/HttpClient.cjs +283 -276
  150. package/dist/network/HttpClient.cjs.map +1 -1
  151. package/dist/network/HttpClient.d.ts +26 -25
  152. package/dist/network/HttpClient.d.ts.map +1 -1
  153. package/dist/network/HttpClient.mjs +283 -276
  154. package/dist/network/HttpClient.mjs.map +1 -1
  155. package/dist/network/ILoopbackClient.d.ts +10 -10
  156. package/dist/network/LoopbackClient.cjs +76 -76
  157. package/dist/network/LoopbackClient.d.ts +21 -21
  158. package/dist/network/LoopbackClient.mjs +76 -76
  159. package/dist/packageMetadata.cjs +4 -4
  160. package/dist/packageMetadata.cjs.map +1 -1
  161. package/dist/packageMetadata.d.ts +2 -2
  162. package/dist/packageMetadata.d.ts.map +1 -1
  163. package/dist/packageMetadata.mjs +4 -4
  164. package/dist/packageMetadata.mjs.map +1 -1
  165. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  166. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  167. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  168. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  169. package/dist/request/InteractiveRequest.d.ts +22 -22
  170. package/dist/request/ManagedIdentityRequest.d.ts +9 -0
  171. package/dist/request/ManagedIdentityRequest.d.ts.map +1 -0
  172. package/dist/request/ManagedIdentityRequestParams.d.ts +10 -0
  173. package/dist/request/ManagedIdentityRequestParams.d.ts.map +1 -0
  174. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  175. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  176. package/dist/request/SignOutRequest.d.ts +5 -5
  177. package/dist/request/SilentFlowRequest.d.ts +16 -16
  178. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  179. package/dist/response/ManagedIdentityTokenResponse.d.ts +25 -0
  180. package/dist/response/ManagedIdentityTokenResponse.d.ts.map +1 -0
  181. package/dist/utils/Constants.cjs +109 -80
  182. package/dist/utils/Constants.cjs.map +1 -1
  183. package/dist/utils/Constants.d.ts +106 -86
  184. package/dist/utils/Constants.d.ts.map +1 -1
  185. package/dist/utils/Constants.mjs +100 -81
  186. package/dist/utils/Constants.mjs.map +1 -1
  187. package/dist/utils/EncodingUtils.cjs +44 -44
  188. package/dist/utils/EncodingUtils.d.ts +26 -26
  189. package/dist/utils/EncodingUtils.mjs +44 -44
  190. package/dist/utils/NetworkUtils.cjs +38 -38
  191. package/dist/utils/NetworkUtils.d.ts +5 -5
  192. package/dist/utils/NetworkUtils.mjs +38 -38
  193. package/package.json +2 -2
  194. package/src/cache/NodeStorage.ts +8 -2
  195. package/src/client/ClientApplication.ts +3 -1
  196. package/src/client/ClientCredentialClient.ts +65 -25
  197. package/src/client/ManagedIdentityApplication.ts +194 -0
  198. package/src/client/ManagedIdentityClient.ts +111 -0
  199. package/src/client/ManagedIdentitySources/AppService.ts +151 -0
  200. package/src/client/ManagedIdentitySources/AzureArc.ts +208 -0
  201. package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +169 -0
  202. package/src/client/ManagedIdentitySources/CloudShell.ts +19 -0
  203. package/src/client/ManagedIdentitySources/Imds.ts +112 -0
  204. package/src/client/ManagedIdentitySources/ServiceFabric.ts +19 -0
  205. package/src/config/Configuration.ts +47 -1
  206. package/src/config/ManagedIdentityId.ts +73 -0
  207. package/src/config/ManagedIdentityRequestParameters.ts +53 -0
  208. package/src/error/ManagedIdentityError.ts +46 -0
  209. package/src/error/ManagedIdentityErrorCodes.ts +15 -0
  210. package/src/index.ts +2 -0
  211. package/src/network/HttpClient.ts +17 -5
  212. package/src/packageMetadata.ts +1 -1
  213. package/src/request/ManagedIdentityRequest.ts +15 -0
  214. package/src/request/ManagedIdentityRequestParams.ts +14 -0
  215. package/src/response/ManagedIdentityTokenResponse.ts +33 -0
  216. package/src/utils/Constants.ts +27 -0
@@ -1,197 +1,201 @@
1
- /*! @azure/msal-node v2.2.0 2023-10-05 */
1
+ /*! @azure/msal-node v2.3.0-alpha.0 2023-12-07 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
5
5
  var msalCommon = require('@azure/msal-common');
6
6
 
7
- /*
8
- * Copyright (c) Microsoft Corporation. All rights reserved.
9
- * Licensed under the MIT License.
10
- */
11
- /**
12
- * OAuth2.0 client credential grant
13
- */
14
- class ClientCredentialClient extends msalCommon.BaseClient {
15
- constructor(configuration, appTokenProvider) {
16
- super(configuration);
17
- this.appTokenProvider = appTokenProvider;
18
- }
19
- /**
20
- * Public API to acquire a token with ClientCredential Flow for Confidential clients
21
- * @param request
22
- */
23
- async acquireToken(request) {
24
- this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
25
- if (request.skipCache) {
26
- return await this.executeTokenRequest(request, this.authority);
27
- }
28
- const [cachedAuthenticationResult, lastCacheOutcome] = await this.getCachedAuthenticationResult(request);
29
- if (cachedAuthenticationResult) {
30
- // if the token is not expired but must be refreshed; get a new one in the background
31
- if (lastCacheOutcome === msalCommon.CacheOutcome.PROACTIVELY_REFRESHED) {
32
- this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
33
- // refresh the access token in the background
34
- const refreshAccessToken = true;
35
- await this.executeTokenRequest(request, this.authority, refreshAccessToken);
36
- }
37
- // return the cached token
38
- return cachedAuthenticationResult;
39
- }
40
- else {
41
- return await this.executeTokenRequest(request, this.authority);
42
- }
43
- }
44
- /**
45
- * looks up cache if the tokens are cached already
46
- */
47
- async getCachedAuthenticationResult(request) {
48
- let lastCacheOutcome = msalCommon.CacheOutcome.NOT_APPLICABLE;
49
- // read the user-supplied cache into memory, if applicable
50
- let cacheContext;
51
- if (this.config.serializableCache && this.config.persistencePlugin) {
52
- cacheContext = new msalCommon.TokenCacheContext(this.config.serializableCache, false);
53
- await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
54
- }
55
- const cachedAccessToken = this.readAccessTokenFromCache();
56
- if (this.config.serializableCache &&
57
- this.config.persistencePlugin &&
58
- cacheContext) {
59
- await this.config.persistencePlugin.afterCacheAccess(cacheContext);
60
- }
61
- // must refresh due to non-existent access_token
62
- if (!cachedAccessToken) {
63
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
64
- return [null, msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN];
65
- }
66
- // must refresh due to the expires_in value
67
- if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
68
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
69
- return [null, msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
70
- }
71
- // must refresh (in the background) due to the refresh_in value
72
- if (cachedAccessToken.refreshOn &&
73
- msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
74
- lastCacheOutcome = msalCommon.CacheOutcome.PROACTIVELY_REFRESHED;
75
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.PROACTIVELY_REFRESHED);
76
- }
77
- return [
78
- await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
79
- account: null,
80
- idToken: null,
81
- accessToken: cachedAccessToken,
82
- refreshToken: null,
83
- appMetadata: null,
84
- }, true, request),
85
- lastCacheOutcome,
86
- ];
87
- }
88
- /**
89
- * Reads access token from the cache
90
- */
91
- readAccessTokenFromCache() {
92
- const accessTokenFilter = {
93
- homeAccountId: msalCommon.Constants.EMPTY_STRING,
94
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
95
- credentialType: msalCommon.CredentialType.ACCESS_TOKEN,
96
- clientId: this.config.authOptions.clientId,
97
- realm: this.authority.tenant,
98
- target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
99
- };
100
- const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
101
- if (accessTokens.length < 1) {
102
- return null;
103
- }
104
- else if (accessTokens.length > 1) {
105
- throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.multipleMatchingTokens);
106
- }
107
- return accessTokens[0];
108
- }
109
- /**
110
- * Makes a network call to request the token from the service
111
- * @param request
112
- * @param authority
113
- */
114
- async executeTokenRequest(request, authority, refreshAccessToken) {
115
- let serverTokenResponse;
116
- let reqTimestamp;
117
- if (this.appTokenProvider) {
118
- this.logger.info("Using appTokenProvider extensibility.");
119
- const appTokenPropviderParameters = {
120
- correlationId: request.correlationId,
121
- tenantId: this.config.authOptions.authority.tenant,
122
- scopes: request.scopes,
123
- claims: request.claims,
124
- };
125
- reqTimestamp = msalCommon.TimeUtils.nowSeconds();
126
- const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
127
- serverTokenResponse = {
128
- access_token: appTokenProviderResult.accessToken,
129
- expires_in: appTokenProviderResult.expiresInSeconds,
130
- refresh_in: appTokenProviderResult.refreshInSeconds,
131
- token_type: msalCommon.AuthenticationScheme.BEARER,
132
- };
133
- }
134
- else {
135
- const queryParametersString = this.createTokenQueryParameters(request);
136
- const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
137
- const requestBody = this.createTokenRequestBody(request);
138
- const headers = this.createTokenRequestHeaders();
139
- const thumbprint = {
140
- clientId: this.config.authOptions.clientId,
141
- authority: request.authority,
142
- scopes: request.scopes,
143
- claims: request.claims,
144
- authenticationScheme: request.authenticationScheme,
145
- resourceRequestMethod: request.resourceRequestMethod,
146
- resourceRequestUri: request.resourceRequestUri,
147
- shrClaims: request.shrClaims,
148
- sshKid: request.sshKid,
149
- };
150
- reqTimestamp = msalCommon.TimeUtils.nowSeconds();
151
- const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
152
- serverTokenResponse = response.body;
153
- serverTokenResponse.status = response.status;
154
- }
155
- const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
156
- responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
157
- const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
158
- return tokenResponse;
159
- }
160
- /**
161
- * generate the request to the server in the acceptable format
162
- * @param request
163
- */
164
- createTokenRequestBody(request) {
165
- const parameterBuilder = new msalCommon.RequestParameterBuilder();
166
- parameterBuilder.addClientId(this.config.authOptions.clientId);
167
- parameterBuilder.addScopes(request.scopes, false);
168
- parameterBuilder.addGrantType(msalCommon.GrantType.CLIENT_CREDENTIALS_GRANT);
169
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
170
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
171
- parameterBuilder.addThrottling();
172
- if (this.serverTelemetryManager) {
173
- parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
174
- }
175
- const correlationId = request.correlationId ||
176
- this.config.cryptoInterface.createNewGuid();
177
- parameterBuilder.addCorrelationId(correlationId);
178
- if (this.config.clientCredentials.clientSecret) {
179
- parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
180
- }
181
- // Use clientAssertion from request, fallback to client assertion in base configuration
182
- const clientAssertion = request.clientAssertion ||
183
- this.config.clientCredentials.clientAssertion;
184
- if (clientAssertion) {
185
- parameterBuilder.addClientAssertion(clientAssertion.assertion);
186
- parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
187
- }
188
- if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
189
- (this.config.authOptions.clientCapabilities &&
190
- this.config.authOptions.clientCapabilities.length > 0)) {
191
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
192
- }
193
- return parameterBuilder.createQueryString();
194
- }
7
+ /*
8
+ * Copyright (c) Microsoft Corporation. All rights reserved.
9
+ * Licensed under the MIT License.
10
+ */
11
+ /**
12
+ * OAuth2.0 client credential grant
13
+ */
14
+ class ClientCredentialClient extends msalCommon.BaseClient {
15
+ constructor(configuration, appTokenProvider) {
16
+ super(configuration);
17
+ this.appTokenProvider = appTokenProvider;
18
+ }
19
+ /**
20
+ * Public API to acquire a token with ClientCredential Flow for Confidential clients
21
+ * @param request
22
+ */
23
+ async acquireToken(request) {
24
+ if (request.skipCache) {
25
+ return await this.executeTokenRequest(request, this.authority);
26
+ }
27
+ const [cachedAuthenticationResult, lastCacheOutcome] = await this.getCachedAuthenticationResult(request, this.config, this.cryptoUtils, this.authority, this.cacheManager, this.serverTelemetryManager);
28
+ if (cachedAuthenticationResult) {
29
+ // if the token is not expired but must be refreshed; get a new one in the background
30
+ if (lastCacheOutcome === msalCommon.CacheOutcome.PROACTIVELY_REFRESHED) {
31
+ this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
32
+ // refresh the access token in the background
33
+ const refreshAccessToken = true;
34
+ await this.executeTokenRequest(request, this.authority, refreshAccessToken);
35
+ }
36
+ // return the cached token
37
+ return cachedAuthenticationResult;
38
+ }
39
+ else {
40
+ return await this.executeTokenRequest(request, this.authority);
41
+ }
42
+ }
43
+ /**
44
+ * looks up cache if the tokens are cached already
45
+ */
46
+ async getCachedAuthenticationResult(request, config, cryptoUtils, authority, cacheManager, serverTelemetryManager) {
47
+ const clientConfiguration = config;
48
+ const managedIdentityConfiguration = config;
49
+ let lastCacheOutcome = msalCommon.CacheOutcome.NOT_APPLICABLE;
50
+ // read the user-supplied cache into memory, if applicable
51
+ let cacheContext;
52
+ if (clientConfiguration.serializableCache &&
53
+ clientConfiguration.persistencePlugin) {
54
+ cacheContext = new msalCommon.TokenCacheContext(clientConfiguration.serializableCache, false);
55
+ await clientConfiguration.persistencePlugin.beforeCacheAccess(cacheContext);
56
+ }
57
+ const cachedAccessToken = this.readAccessTokenFromCache(authority, managedIdentityConfiguration.managedIdentityId?.id ||
58
+ clientConfiguration.authOptions.clientId, new msalCommon.ScopeSet(request.scopes || []), cacheManager);
59
+ if (clientConfiguration.serializableCache &&
60
+ clientConfiguration.persistencePlugin &&
61
+ cacheContext) {
62
+ await clientConfiguration.persistencePlugin.afterCacheAccess(cacheContext);
63
+ }
64
+ // must refresh due to non-existent access_token
65
+ if (!cachedAccessToken) {
66
+ serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
67
+ return [null, msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN];
68
+ }
69
+ // must refresh due to the expires_in value
70
+ if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, clientConfiguration.systemOptions?.tokenRenewalOffsetSeconds ||
71
+ msalCommon.DEFAULT_TOKEN_RENEWAL_OFFSET_SEC)) {
72
+ serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
73
+ return [null, msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
74
+ }
75
+ // must refresh (in the background) due to the refresh_in value
76
+ if (cachedAccessToken.refreshOn &&
77
+ msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
78
+ lastCacheOutcome = msalCommon.CacheOutcome.PROACTIVELY_REFRESHED;
79
+ serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.PROACTIVELY_REFRESHED);
80
+ }
81
+ return [
82
+ await msalCommon.ResponseHandler.generateAuthenticationResult(cryptoUtils, authority, {
83
+ account: null,
84
+ idToken: null,
85
+ accessToken: cachedAccessToken,
86
+ refreshToken: null,
87
+ appMetadata: null,
88
+ }, true, request),
89
+ lastCacheOutcome,
90
+ ];
91
+ }
92
+ /**
93
+ * Reads access token from the cache
94
+ */
95
+ readAccessTokenFromCache(authority, id, scopeSet, cacheManager) {
96
+ const accessTokenFilter = {
97
+ homeAccountId: msalCommon.Constants.EMPTY_STRING,
98
+ environment: authority.canonicalAuthorityUrlComponents.HostNameAndPort,
99
+ credentialType: msalCommon.CredentialType.ACCESS_TOKEN,
100
+ clientId: id,
101
+ realm: authority.tenant,
102
+ target: msalCommon.ScopeSet.createSearchScopes(scopeSet.asArray()),
103
+ };
104
+ const accessTokens = cacheManager.getAccessTokensByFilter(accessTokenFilter);
105
+ if (accessTokens.length < 1) {
106
+ return null;
107
+ }
108
+ else if (accessTokens.length > 1) {
109
+ throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.multipleMatchingTokens);
110
+ }
111
+ return accessTokens[0];
112
+ }
113
+ /**
114
+ * Makes a network call to request the token from the service
115
+ * @param request
116
+ * @param authority
117
+ */
118
+ async executeTokenRequest(request, authority, refreshAccessToken) {
119
+ let serverTokenResponse;
120
+ let reqTimestamp;
121
+ if (this.appTokenProvider) {
122
+ this.logger.info("Using appTokenProvider extensibility.");
123
+ const appTokenPropviderParameters = {
124
+ correlationId: request.correlationId,
125
+ tenantId: this.config.authOptions.authority.tenant,
126
+ scopes: request.scopes,
127
+ claims: request.claims,
128
+ };
129
+ reqTimestamp = msalCommon.TimeUtils.nowSeconds();
130
+ const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
131
+ serverTokenResponse = {
132
+ access_token: appTokenProviderResult.accessToken,
133
+ expires_in: appTokenProviderResult.expiresInSeconds,
134
+ refresh_in: appTokenProviderResult.refreshInSeconds,
135
+ token_type: msalCommon.AuthenticationScheme.BEARER,
136
+ };
137
+ }
138
+ else {
139
+ const queryParametersString = this.createTokenQueryParameters(request);
140
+ const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
141
+ const requestBody = this.createTokenRequestBody(request);
142
+ const headers = this.createTokenRequestHeaders();
143
+ const thumbprint = {
144
+ clientId: this.config.authOptions.clientId,
145
+ authority: request.authority,
146
+ scopes: request.scopes,
147
+ claims: request.claims,
148
+ authenticationScheme: request.authenticationScheme,
149
+ resourceRequestMethod: request.resourceRequestMethod,
150
+ resourceRequestUri: request.resourceRequestUri,
151
+ shrClaims: request.shrClaims,
152
+ sshKid: request.sshKid,
153
+ };
154
+ reqTimestamp = msalCommon.TimeUtils.nowSeconds();
155
+ const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
156
+ serverTokenResponse = response.body;
157
+ serverTokenResponse.status = response.status;
158
+ }
159
+ const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
160
+ responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
161
+ const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
162
+ return tokenResponse;
163
+ }
164
+ /**
165
+ * generate the request to the server in the acceptable format
166
+ * @param request
167
+ */
168
+ createTokenRequestBody(request) {
169
+ const parameterBuilder = new msalCommon.RequestParameterBuilder();
170
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
171
+ parameterBuilder.addScopes(request.scopes, false);
172
+ parameterBuilder.addGrantType(msalCommon.GrantType.CLIENT_CREDENTIALS_GRANT);
173
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
174
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
175
+ parameterBuilder.addThrottling();
176
+ if (this.serverTelemetryManager) {
177
+ parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
178
+ }
179
+ const correlationId = request.correlationId ||
180
+ this.config.cryptoInterface.createNewGuid();
181
+ parameterBuilder.addCorrelationId(correlationId);
182
+ if (this.config.clientCredentials.clientSecret) {
183
+ parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
184
+ }
185
+ // Use clientAssertion from request, fallback to client assertion in base configuration
186
+ const clientAssertion = request.clientAssertion ||
187
+ this.config.clientCredentials.clientAssertion;
188
+ if (clientAssertion) {
189
+ parameterBuilder.addClientAssertion(clientAssertion.assertion);
190
+ parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
191
+ }
192
+ if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
193
+ (this.config.authOptions.clientCapabilities &&
194
+ this.config.authOptions.clientCapabilities.length > 0)) {
195
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
196
+ }
197
+ return parameterBuilder.createQueryString();
198
+ }
195
199
  }
196
200
 
197
201
  exports.ClientCredentialClient = ClientCredentialClient;
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.cjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":["BaseClient","CacheOutcome"],"mappings":";;;;;;AAKA;AA2BA;;AAEG;;AAGC;AAGI;AAOJ,MAAA,sBAAA,SAAAA,qBAAA,CAAA;;;AAGG,QAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA,CAAA;KACsB;AAmCzB;;AAEG;;AA4EH,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;;AAEG,QAAA,IAAA,OAAA,CAAA,SAAA,EAAA;AACH,YAAQ,OAAwB,MAAA,IAAA,CAAA,mBAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,CAAA;AAuBhC,SAAA;;;;AAIG,YAAA,IAAA,gBAAA,KAAAC,uBAAA,CAAA,qBAAA,EAAA;gBAC8B,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;AAwFjC;;;AAGG,aAAA;AACH;AA0DH,YAAA,OAAA,0BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ClientCredentialClient.cjs","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":[null],"names":["BaseClient"],"mappings":";;;;;;AAKA;AA8BA;AAKA;;AAGA;AACI;AAGI;AAOJ,MAAA,sBAAA,SAAAA,qBAAA,CAAA;;;AAGG,QAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA,CAAA;KACsB;AAwCzB;;AAEG;AACU;AAkGb,IAAA,MAAA,YAAA,CAAA,OAAA,EAAA;;AAEG,YAAA,OAAA,MAAA,IAAA,CAAA,mBAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,CAAA;AACH,SAAA;AA4BA,QAAA,MAAA,CAAA,0BAAA,EAAA,gBAAA,CAAA,GAAA,MAAA,IAAA,CAAA,6BAAA,CAAA,OAAA,EAAA,IAAA,CAAA,MAAA,EAAA,IAAA,CAAA,WAAA,EAAA,IAAA,CAAA,SAAA,EAAA,IAAA,CAAA,YAAA,EAAA,IAAA,CAAA,sBAAA,CAAA,CAAA;;;;AAIG,gBAAA,IAAA,CAAA,MAAA,CAAA,IAAA,CAAA,8JAAA,CAAA,CAAA;;AAyFH,gBAAA,MAAA,kBAAA,GAAA,IAAA,CAAA;;;AAGG;AACH,YAAQ,OAAsB,0BAAA,CAAA;AA0DjC,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,34 +1,34 @@
1
- import { AuthenticationResult, BaseClient, ClientConfiguration, CommonClientCredentialRequest, IAppTokenProvider } from "@azure/msal-common";
2
- /**
3
- * OAuth2.0 client credential grant
4
- */
5
- export declare class ClientCredentialClient extends BaseClient {
6
- private scopeSet;
7
- private readonly appTokenProvider?;
8
- constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
9
- /**
10
- * Public API to acquire a token with ClientCredential Flow for Confidential clients
11
- * @param request
12
- */
13
- acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
14
- /**
15
- * looks up cache if the tokens are cached already
16
- */
17
- private getCachedAuthenticationResult;
18
- /**
19
- * Reads access token from the cache
20
- */
21
- private readAccessTokenFromCache;
22
- /**
23
- * Makes a network call to request the token from the service
24
- * @param request
25
- * @param authority
26
- */
27
- private executeTokenRequest;
28
- /**
29
- * generate the request to the server in the acceptable format
30
- * @param request
31
- */
32
- private createTokenRequestBody;
33
- }
1
+ import { AuthenticationResult, Authority, BaseClient, CacheManager, CacheOutcome, ClientConfiguration, CommonClientCredentialRequest, IAppTokenProvider, ICrypto, ServerTelemetryManager } from "@azure/msal-common";
2
+ import { ManagedIdentityConfiguration } from "../config/Configuration";
3
+ /**
4
+ * OAuth2.0 client credential grant
5
+ */
6
+ export declare class ClientCredentialClient extends BaseClient {
7
+ private readonly appTokenProvider?;
8
+ constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
9
+ /**
10
+ * Public API to acquire a token with ClientCredential Flow for Confidential clients
11
+ * @param request
12
+ */
13
+ acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
14
+ /**
15
+ * looks up cache if the tokens are cached already
16
+ */
17
+ getCachedAuthenticationResult(request: CommonClientCredentialRequest, config: ClientConfiguration | ManagedIdentityConfiguration, cryptoUtils: ICrypto, authority: Authority, cacheManager: CacheManager, serverTelemetryManager?: ServerTelemetryManager | null): Promise<[AuthenticationResult | null, CacheOutcome]>;
18
+ /**
19
+ * Reads access token from the cache
20
+ */
21
+ private readAccessTokenFromCache;
22
+ /**
23
+ * Makes a network call to request the token from the service
24
+ * @param request
25
+ * @param authority
26
+ */
27
+ private executeTokenRequest;
28
+ /**
29
+ * generate the request to the server in the acceptable format
30
+ * @param request
31
+ */
32
+ private createTokenRequestBody;
33
+ }
34
34
  //# sourceMappingURL=ClientCredentialClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,oBAAoB,EAGpB,UAAU,EAGV,mBAAmB,EACnB,6BAA6B,EAK7B,iBAAiB,EAWpB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;gBAGlD,aAAa,EAAE,mBAAmB,EAClC,gBAAgB,CAAC,EAAE,iBAAiB;IAMxC;;;OAGG;IACU,YAAY,CACrB,OAAO,EAAE,6BAA6B,GACvC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAiCvC;;OAEG;YACW,6BAA6B;IA2E3C;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAuBhC;;;;OAIG;YACW,mBAAmB;IAwFjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CA0DjC"}
1
+ {"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,oBAAoB,EAEpB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,YAAY,EAEZ,mBAAmB,EACnB,6BAA6B,EAM7B,iBAAiB,EACjB,OAAO,EAMP,sBAAsB,EAMzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACH,4BAA4B,EAE/B,MAAM,yBAAyB,CAAC;AAEjC;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;gBAGlD,aAAa,EAAE,mBAAmB,EAClC,gBAAgB,CAAC,EAAE,iBAAiB;IAMxC;;;OAGG;IACU,YAAY,CACrB,OAAO,EAAE,6BAA6B,GACvC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAsCvC;;OAEG;IACU,6BAA6B,CACtC,OAAO,EAAE,6BAA6B,EACtC,MAAM,EAAE,mBAAmB,GAAG,4BAA4B,EAC1D,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,YAAY,EAC1B,sBAAsB,CAAC,EAAE,sBAAsB,GAAG,IAAI,GACvD,OAAO,CAAC,CAAC,oBAAoB,GAAG,IAAI,EAAE,YAAY,CAAC,CAAC;IA2FvD;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA4BhC;;;;OAIG;YACW,mBAAmB;IAwFjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CA0DjC"}