@microsoft/agents-hosting 1.6.0-beta.9.gce9d8facd2 → 1.7.0-beta.1.g8bcd4f11a7

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 (149) hide show
  1. package/dist/package.json +4 -9
  2. package/dist/src/agent-client/agentClient.js +2 -2
  3. package/dist/src/agent-client/agentClient.js.map +1 -1
  4. package/dist/src/agent-client/agentResponseHandler.js +2 -2
  5. package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
  6. package/dist/src/app/agentApplication.js +28 -2
  7. package/dist/src/app/agentApplication.js.map +1 -1
  8. package/dist/src/app/agentApplicationOptions.d.ts +10 -0
  9. package/dist/src/app/attachmentDownloader.js +5 -10
  10. package/dist/src/app/attachmentDownloader.js.map +1 -1
  11. package/dist/src/app/auth/authorizationManager.d.ts +4 -0
  12. package/dist/src/app/auth/authorizationManager.js +94 -67
  13. package/dist/src/app/auth/authorizationManager.js.map +1 -1
  14. package/dist/src/app/auth/handlers/azureBotAuthorization.js +2 -2
  15. package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
  16. package/dist/src/app/proactive/createConversationOptionsBuilder.js +10 -6
  17. package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
  18. package/dist/src/app/proactive/proactive.d.ts +1 -0
  19. package/dist/src/app/proactive/proactive.js +30 -15
  20. package/dist/src/app/proactive/proactive.js.map +1 -1
  21. package/dist/src/app/streaming/streamingResponse.d.ts +11 -0
  22. package/dist/src/app/streaming/streamingResponse.js +21 -0
  23. package/dist/src/app/streaming/streamingResponse.js.map +1 -1
  24. package/dist/src/app/teamsAttachmentDownloader.js +6 -14
  25. package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
  26. package/dist/src/auth/MemoryCache.d.ts +2 -1
  27. package/dist/src/auth/MemoryCache.js +7 -1
  28. package/dist/src/auth/MemoryCache.js.map +1 -1
  29. package/dist/src/auth/authConfiguration.d.ts +2 -143
  30. package/dist/src/auth/authConfiguration.js +336 -257
  31. package/dist/src/auth/authConfiguration.js.map +1 -1
  32. package/dist/src/auth/authConstants.d.ts +7 -7
  33. package/dist/src/auth/authConstants.js.map +1 -1
  34. package/dist/src/auth/connectionManager.d.ts +92 -0
  35. package/dist/src/auth/{msalConnectionManager.js → connectionManager.js} +48 -33
  36. package/dist/src/auth/connectionManager.js.map +1 -0
  37. package/dist/src/auth/index.d.ts +5 -3
  38. package/dist/src/auth/index.js +5 -3
  39. package/dist/src/auth/index.js.map +1 -1
  40. package/dist/src/auth/jwt-middleware.d.ts +6 -0
  41. package/dist/src/auth/jwt-middleware.js +34 -2
  42. package/dist/src/auth/jwt-middleware.js.map +1 -1
  43. package/dist/src/auth/msal/msalConnectionManager.d.ts +17 -0
  44. package/dist/src/auth/msal/msalConnectionManager.js +50 -0
  45. package/dist/src/auth/msal/msalConnectionManager.js.map +1 -0
  46. package/dist/src/auth/msal/msalConnectionSettings.d.ts +68 -0
  47. package/dist/src/auth/msal/msalConnectionSettings.js +7 -0
  48. package/dist/src/auth/msal/msalConnectionSettings.js.map +1 -0
  49. package/dist/src/auth/{msalTokenCredential.d.ts → msal/msalTokenCredential.d.ts} +1 -1
  50. package/dist/src/auth/{msalTokenCredential.js → msal/msalTokenCredential.js} +2 -2
  51. package/dist/src/auth/msal/msalTokenCredential.js.map +1 -0
  52. package/dist/src/auth/{msalTokenProvider.d.ts → msal/msalTokenProvider.d.ts} +30 -3
  53. package/dist/src/auth/msal/msalTokenProvider.js +733 -0
  54. package/dist/src/auth/msal/msalTokenProvider.js.map +1 -0
  55. package/dist/src/auth/settings.d.ts +336 -0
  56. package/dist/src/auth/settings.js +202 -0
  57. package/dist/src/auth/settings.js.map +1 -0
  58. package/dist/src/auth/sidecar/sidecarAuthProvider.d.ts +74 -0
  59. package/dist/src/auth/sidecar/sidecarAuthProvider.js +181 -0
  60. package/dist/src/auth/sidecar/sidecarAuthProvider.js.map +1 -0
  61. package/dist/src/auth/sidecar/sidecarConnectionSettings.d.ts +65 -0
  62. package/dist/src/auth/sidecar/sidecarConnectionSettings.js +7 -0
  63. package/dist/src/auth/sidecar/sidecarConnectionSettings.js.map +1 -0
  64. package/dist/src/auth/sidecar/sidecarHttpClient.d.ts +95 -0
  65. package/dist/src/auth/sidecar/sidecarHttpClient.js +406 -0
  66. package/dist/src/auth/sidecar/sidecarHttpClient.js.map +1 -0
  67. package/dist/src/auth/sidecar/sidecarModels.d.ts +110 -0
  68. package/dist/src/auth/sidecar/sidecarModels.js +48 -0
  69. package/dist/src/auth/sidecar/sidecarModels.js.map +1 -0
  70. package/dist/src/auth/sidecar/sidecarTokenExpiry.d.ts +13 -0
  71. package/dist/src/auth/sidecar/sidecarTokenExpiry.js +39 -0
  72. package/dist/src/auth/sidecar/sidecarTokenExpiry.js.map +1 -0
  73. package/dist/src/cloudAdapter.d.ts +58 -1
  74. package/dist/src/cloudAdapter.js +233 -53
  75. package/dist/src/cloudAdapter.js.map +1 -1
  76. package/dist/src/connector-client/connectorClient.d.ts +12 -8
  77. package/dist/src/connector-client/connectorClient.js +99 -82
  78. package/dist/src/connector-client/connectorClient.js.map +1 -1
  79. package/dist/src/errorHelper.js +181 -7
  80. package/dist/src/errorHelper.js.map +1 -1
  81. package/dist/src/getProductInfo.d.ts +23 -0
  82. package/dist/src/getProductInfo.js +71 -1
  83. package/dist/src/getProductInfo.js.map +1 -1
  84. package/dist/src/headerPropagation.d.ts +17 -2
  85. package/dist/src/headerPropagation.js +46 -24
  86. package/dist/src/headerPropagation.js.map +1 -1
  87. package/dist/src/httpClient.d.ts +60 -0
  88. package/dist/src/httpClient.js +173 -0
  89. package/dist/src/httpClient.js.map +1 -0
  90. package/dist/src/index.d.ts +3 -2
  91. package/dist/src/index.js +8 -2
  92. package/dist/src/index.js.map +1 -1
  93. package/dist/src/oauth/userTokenClient.d.ts +17 -4
  94. package/dist/src/oauth/userTokenClient.js +119 -80
  95. package/dist/src/oauth/userTokenClient.js.map +1 -1
  96. package/dist/src/observability/traces.d.ts +11 -4
  97. package/dist/src/observability/traces.js +39 -7
  98. package/dist/src/observability/traces.js.map +1 -1
  99. package/dist/src/utils/env.d.ts +50 -0
  100. package/dist/src/utils/env.js +113 -0
  101. package/dist/src/utils/env.js.map +1 -0
  102. package/dist/src/utils.d.ts +10 -0
  103. package/dist/src/utils.js +18 -0
  104. package/dist/src/utils.js.map +1 -0
  105. package/package.json +4 -9
  106. package/src/agent-client/agentClient.ts +2 -2
  107. package/src/agent-client/agentResponseHandler.ts +2 -2
  108. package/src/app/agentApplication.ts +30 -3
  109. package/src/app/agentApplicationOptions.ts +11 -0
  110. package/src/app/attachmentDownloader.ts +6 -8
  111. package/src/app/auth/authorizationManager.ts +84 -41
  112. package/src/app/auth/handlers/azureBotAuthorization.ts +2 -2
  113. package/src/app/proactive/createConversationOptionsBuilder.ts +8 -4
  114. package/src/app/proactive/proactive.ts +39 -23
  115. package/src/app/streaming/streamingResponse.ts +24 -1
  116. package/src/app/teamsAttachmentDownloader.ts +7 -11
  117. package/src/auth/MemoryCache.ts +7 -1
  118. package/src/auth/authConfiguration.ts +350 -356
  119. package/src/auth/authConstants.ts +7 -7
  120. package/src/auth/{msalConnectionManager.ts → connectionManager.ts} +65 -44
  121. package/src/auth/index.ts +5 -3
  122. package/src/auth/jwt-middleware.ts +32 -2
  123. package/src/auth/msal/msalConnectionManager.ts +55 -0
  124. package/src/auth/msal/msalConnectionSettings.ts +79 -0
  125. package/src/auth/{msalTokenCredential.ts → msal/msalTokenCredential.ts} +2 -1
  126. package/src/auth/msal/msalTokenProvider.ts +881 -0
  127. package/src/auth/settings.ts +378 -0
  128. package/src/auth/sidecar/sidecarAuthProvider.ts +234 -0
  129. package/src/auth/sidecar/sidecarConnectionSettings.ts +72 -0
  130. package/src/auth/sidecar/sidecarHttpClient.ts +443 -0
  131. package/src/auth/sidecar/sidecarModels.ts +153 -0
  132. package/src/auth/sidecar/sidecarTokenExpiry.ts +35 -0
  133. package/src/cloudAdapter.ts +292 -13
  134. package/src/connector-client/connectorClient.ts +116 -94
  135. package/src/errorHelper.ts +206 -7
  136. package/src/getProductInfo.ts +79 -1
  137. package/src/headerPropagation.ts +55 -23
  138. package/src/httpClient.ts +223 -0
  139. package/src/index.ts +6 -2
  140. package/src/oauth/userTokenClient.ts +137 -84
  141. package/src/observability/traces.ts +39 -8
  142. package/src/utils/env.ts +105 -0
  143. package/src/utils.ts +14 -0
  144. package/dist/src/auth/msalConnectionManager.d.ts +0 -64
  145. package/dist/src/auth/msalConnectionManager.js.map +0 -1
  146. package/dist/src/auth/msalTokenCredential.js.map +0 -1
  147. package/dist/src/auth/msalTokenProvider.js +0 -485
  148. package/dist/src/auth/msalTokenProvider.js.map +0 -1
  149. package/src/auth/msalTokenProvider.ts +0 -562
@@ -0,0 +1,733 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MsalTokenProvider = void 0;
11
+ const msal_node_1 = require("@azure/msal-node");
12
+ const authConfiguration_1 = require("../authConfiguration");
13
+ const agents_telemetry_1 = require("@microsoft/agents-telemetry");
14
+ const crypto_1 = require("crypto");
15
+ const MemoryCache_1 = require("../MemoryCache");
16
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const crypto_2 = __importDefault(require("crypto"));
19
+ const observability_1 = require("../../observability");
20
+ const agents_activity_1 = require("@microsoft/agents-activity");
21
+ const errorHelper_1 = require("../../errorHelper");
22
+ const audience = 'api://AzureADTokenExchange';
23
+ const logger = (0, agents_telemetry_1.debug)('agents:msal');
24
+ const agenticTokenRequestTimeoutMs = 30000;
25
+ function isAbortError(error) {
26
+ return error instanceof Error && error.name === 'AbortError';
27
+ }
28
+ function createTokenRequestTimeoutError(timeoutMs) {
29
+ return agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.TokenRequestTimeout, undefined, { timeoutMs: timeoutMs.toString() });
30
+ }
31
+ /**
32
+ * Provides tokens using MSAL.
33
+ */
34
+ class MsalTokenProvider {
35
+ constructor(connectionSettings) {
36
+ this.sysOptions = {
37
+ loggerOptions: {
38
+ logLevel: msal_node_1.LogLevel.Trace,
39
+ loggerCallback: (level, message, containsPii) => {
40
+ if (containsPii) {
41
+ return;
42
+ }
43
+ switch (level) {
44
+ case msal_node_1.LogLevel.Error:
45
+ logger.error(message);
46
+ return;
47
+ case msal_node_1.LogLevel.Info:
48
+ logger.debug(message);
49
+ return;
50
+ case msal_node_1.LogLevel.Warning:
51
+ if (!message.includes('Warning - No client info in response')) {
52
+ logger.warn(message);
53
+ }
54
+ return;
55
+ case msal_node_1.LogLevel.Verbose:
56
+ logger.debug(message);
57
+ }
58
+ },
59
+ piiLoggingEnabled: false
60
+ }
61
+ };
62
+ this.connectionSettings = connectionSettings;
63
+ }
64
+ /**
65
+ * Clears process-wide auth caches.
66
+ */
67
+ static clearSharedCaches() {
68
+ MsalTokenProvider._accessTokenCache.clear();
69
+ MsalTokenProvider._agenticTokenCache.clear();
70
+ MsalTokenProvider._confidentialClients.clear();
71
+ }
72
+ static cacheKey(...parts) {
73
+ return JSON.stringify(parts.map(part => part !== null && part !== void 0 ? part : ''));
74
+ }
75
+ static digest(value) {
76
+ return value ? crypto_2.default.createHash('sha256').update(value).digest('base64url') : '';
77
+ }
78
+ getOrCreateConfidentialClient(cacheKey, createClient) {
79
+ const existing = MsalTokenProvider._confidentialClients.get(cacheKey);
80
+ if (existing) {
81
+ MsalTokenProvider._confidentialClients.delete(cacheKey);
82
+ MsalTokenProvider._confidentialClients.set(cacheKey, existing);
83
+ return existing;
84
+ }
85
+ const created = createClient();
86
+ MsalTokenProvider._confidentialClients.set(cacheKey, created);
87
+ while (MsalTokenProvider._confidentialClients.size > MsalTokenProvider._maxConfidentialClients) {
88
+ const oldestKey = MsalTokenProvider._confidentialClients.keys().next().value;
89
+ if (oldestKey === undefined) {
90
+ break;
91
+ }
92
+ MsalTokenProvider._confidentialClients.delete(oldestKey);
93
+ }
94
+ return created;
95
+ }
96
+ getFileCacheIdentity(path) {
97
+ if (!path) {
98
+ return '';
99
+ }
100
+ try {
101
+ const stat = fs_1.default.statSync(path);
102
+ return `${path}:${stat.size}:${stat.mtimeMs}`;
103
+ }
104
+ catch {
105
+ return path;
106
+ }
107
+ }
108
+ getAccessTokenCacheKey(authConfig, scope) {
109
+ var _a, _b, _c, _d, _e;
110
+ const authType = (0, authConfiguration_1.resolveAuthType)(authConfig);
111
+ let authority = (0, authConfiguration_1.resolveAuthority)((_a = authConfig.authorityEndpoint) !== null && _a !== void 0 ? _a : authConfig.authority, authConfig.tenantId);
112
+ let credentialIdentity = '';
113
+ switch (authType) {
114
+ case authConfiguration_1.AuthType.ClientSecret:
115
+ credentialIdentity = MsalTokenProvider.digest(authConfig.clientSecret);
116
+ break;
117
+ case authConfiguration_1.AuthType.Certificate:
118
+ case authConfiguration_1.AuthType.CertificateSubjectName:
119
+ credentialIdentity = MsalTokenProvider.cacheKey(this.getFileCacheIdentity(authConfig.certPemFile), this.getFileCacheIdentity(authConfig.certKeyFile), authConfig.sendX5C);
120
+ break;
121
+ case authConfiguration_1.AuthType.WorkloadIdentity:
122
+ authority = `https://login.microsoftonline.com/${authConfig.tenantId}`;
123
+ credentialIdentity = this.getFileCacheIdentity((_b = authConfig.federatedTokenFile) !== null && _b !== void 0 ? _b : authConfig.WIDAssertionFile);
124
+ break;
125
+ case authConfiguration_1.AuthType.FederatedCredentials:
126
+ credentialIdentity = (_d = (_c = authConfig.federatedClientId) !== null && _c !== void 0 ? _c : authConfig.FICClientId) !== null && _d !== void 0 ? _d : '';
127
+ break;
128
+ case authConfiguration_1.AuthType.UserManagedIdentity:
129
+ authority = 'managed-identity';
130
+ credentialIdentity = (_e = authConfig.clientId) !== null && _e !== void 0 ? _e : '';
131
+ break;
132
+ case authConfiguration_1.AuthType.SystemManagedIdentity:
133
+ authority = 'managed-identity';
134
+ credentialIdentity = 'system';
135
+ break;
136
+ default:
137
+ credentialIdentity = 'unknown';
138
+ }
139
+ return MsalTokenProvider.cacheKey('access-token', authType, authority, authConfig.clientId, scope, authConfig.azureRegion, credentialIdentity);
140
+ }
141
+ cacheAccessToken(cacheKey, token, expiresOn) {
142
+ const ttlSeconds = this.getTokenCacheTtlSeconds(token, expiresOn);
143
+ if (ttlSeconds > 0) {
144
+ MsalTokenProvider._accessTokenCache.set(cacheKey, token, ttlSeconds);
145
+ }
146
+ }
147
+ cacheAgenticToken(cacheKey, token, ttlSeconds) {
148
+ const safeTtlSeconds = Math.floor(ttlSeconds) - 300;
149
+ if (safeTtlSeconds > 0) {
150
+ MsalTokenProvider._agenticTokenCache.set(cacheKey, token, safeTtlSeconds);
151
+ }
152
+ }
153
+ cacheAgenticAuthenticationResult(cacheKey, token) {
154
+ const ttlSeconds = this.getTokenCacheTtlSeconds(token.accessToken, token.expiresOn);
155
+ if (ttlSeconds > 0) {
156
+ MsalTokenProvider._agenticTokenCache.set(cacheKey, token.accessToken, ttlSeconds);
157
+ }
158
+ }
159
+ getAgenticTokenCacheKey(tenantId, clientId, scopes, tokenBodyParameters) {
160
+ const bodyKey = Object.keys(tokenBodyParameters)
161
+ .sort()
162
+ .filter(key => key !== 'user_federated_identity_credential')
163
+ .map(key => `${key}=${MsalTokenProvider.digest(String(tokenBodyParameters[key]))}`)
164
+ .join('&');
165
+ return MsalTokenProvider.cacheKey('agentic-token', this.resolveAuthority(tenantId), clientId, scopes.join(' '), bodyKey);
166
+ }
167
+ getTokenCacheTtlSeconds(token, expiresOn) {
168
+ var _a;
169
+ const expiresAtMs = (_a = expiresOn === null || expiresOn === void 0 ? void 0 : expiresOn.getTime()) !== null && _a !== void 0 ? _a : this.getJwtExpiresAtMs(token);
170
+ if (!expiresAtMs) {
171
+ return 0;
172
+ }
173
+ return Math.floor((expiresAtMs - Date.now()) / 1000) - 300;
174
+ }
175
+ getJwtExpiresAtMs(token) {
176
+ const payload = jsonwebtoken_1.default.decode(token);
177
+ if (!payload || typeof payload === 'string' || typeof payload.exp !== 'number') {
178
+ return undefined;
179
+ }
180
+ return payload.exp * 1000;
181
+ }
182
+ getClientSecretClient(authConfig) {
183
+ var _a;
184
+ const cacheKey = MsalTokenProvider.cacheKey('confidential-client', authConfiguration_1.AuthType.ClientSecret, authConfig.clientId, (0, authConfiguration_1.resolveAuthority)((_a = authConfig.authorityEndpoint) !== null && _a !== void 0 ? _a : authConfig.authority, authConfig.tenantId), MsalTokenProvider.digest(authConfig.clientSecret));
185
+ return this.getOrCreateConfidentialClient(cacheKey, () => {
186
+ var _a;
187
+ return new msal_node_1.ConfidentialClientApplication({
188
+ auth: {
189
+ clientId: authConfig.clientId,
190
+ authority: (0, authConfiguration_1.resolveAuthority)((_a = authConfig.authorityEndpoint) !== null && _a !== void 0 ? _a : authConfig.authority, authConfig.tenantId),
191
+ clientSecret: authConfig.clientSecret
192
+ },
193
+ system: this.sysOptions
194
+ });
195
+ });
196
+ }
197
+ getCertificateClient(authConfig) {
198
+ var _a, _b;
199
+ const cacheKey = MsalTokenProvider.cacheKey('confidential-client', (_a = authConfig.authType) !== null && _a !== void 0 ? _a : authConfiguration_1.AuthType.Certificate, authConfig.clientId, (0, authConfiguration_1.resolveAuthority)((_b = authConfig.authorityEndpoint) !== null && _b !== void 0 ? _b : authConfig.authority, authConfig.tenantId), this.getFileCacheIdentity(authConfig.certPemFile), this.getFileCacheIdentity(authConfig.certKeyFile), authConfig.sendX5C);
200
+ return this.getOrCreateConfidentialClient(cacheKey, () => {
201
+ var _a;
202
+ const privateKeySource = fs_1.default.readFileSync(authConfig.certKeyFile);
203
+ const privateKeyObject = crypto_2.default.createPrivateKey({
204
+ key: privateKeySource,
205
+ format: 'pem'
206
+ });
207
+ const privateKey = privateKeyObject.export({
208
+ format: 'pem',
209
+ type: 'pkcs8'
210
+ });
211
+ const pemFile = fs_1.default.readFileSync(authConfig.certPemFile);
212
+ const pubKeyObject = new crypto_2.default.X509Certificate(pemFile);
213
+ return new msal_node_1.ConfidentialClientApplication({
214
+ auth: {
215
+ clientId: authConfig.clientId || '',
216
+ authority: (0, authConfiguration_1.resolveAuthority)((_a = authConfig.authorityEndpoint) !== null && _a !== void 0 ? _a : authConfig.authority, authConfig.tenantId),
217
+ clientCertificate: {
218
+ privateKey: privateKey,
219
+ thumbprint: pubKeyObject.fingerprint.replaceAll(':', ''),
220
+ x5c: pemFile.toString()
221
+ }
222
+ },
223
+ system: this.sysOptions
224
+ });
225
+ });
226
+ }
227
+ async getAccessToken(authConfigOrScope, scope) {
228
+ return (0, agents_telemetry_1.trace)(observability_1.AuthenticationTraceDefinitions.getAccessToken, async ({ record }) => {
229
+ var _a;
230
+ let authConfig;
231
+ let actualScope;
232
+ if (typeof authConfigOrScope === 'string') {
233
+ // Called as getAccessToken(scope)
234
+ if (!this.connectionSettings) {
235
+ throw new Error('Connection settings must be provided to constructor when calling getAccessToken(scope)');
236
+ }
237
+ authConfig = this.connectionSettings;
238
+ actualScope = authConfigOrScope;
239
+ }
240
+ else {
241
+ // Called as getAccessToken(authConfig, scope)
242
+ authConfig = authConfigOrScope;
243
+ actualScope = scope;
244
+ }
245
+ record({ scope: actualScope });
246
+ if (!authConfig.clientId && process.env.NODE_ENV !== 'production') {
247
+ record({ method: 'unknown' });
248
+ return '';
249
+ }
250
+ const accessTokenCacheKey = this.getAccessTokenCacheKey(authConfig, actualScope);
251
+ const cachedAccessToken = MsalTokenProvider._accessTokenCache.get(accessTokenCacheKey);
252
+ if (cachedAccessToken) {
253
+ logger.debug('getAccessToken cache hit clientId=%s scope=%s', authConfig.clientId, actualScope);
254
+ return cachedAccessToken;
255
+ }
256
+ let token;
257
+ const authType = (0, authConfiguration_1.resolveAuthType)(authConfig);
258
+ record({ method: authType });
259
+ logger.debug('getAccessToken via method=%s clientId=%s scope=%s', authType, authConfig.clientId, actualScope);
260
+ switch (authType) {
261
+ case authConfiguration_1.AuthType.WorkloadIdentity: {
262
+ const tokenFilePath = (_a = authConfig.federatedTokenFile) !== null && _a !== void 0 ? _a : authConfig.WIDAssertionFile;
263
+ if (!tokenFilePath) {
264
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.WorkloadIdentityTokenFileRequired);
265
+ }
266
+ token = await this.acquireAccessTokenViaWID(authConfig, actualScope);
267
+ break;
268
+ }
269
+ case authConfiguration_1.AuthType.FederatedCredentials:
270
+ if (!authConfig.federatedClientId && !authConfig.FICClientId) {
271
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.FICClientIdRequired);
272
+ }
273
+ token = await this.acquireAccessTokenViaFIC(authConfig, actualScope);
274
+ break;
275
+ case authConfiguration_1.AuthType.ClientSecret:
276
+ if (!authConfig.clientSecret) {
277
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.ClientSecretRequired);
278
+ }
279
+ token = await this.acquireAccessTokenViaSecret(authConfig, actualScope);
280
+ break;
281
+ case authConfiguration_1.AuthType.Certificate:
282
+ case authConfiguration_1.AuthType.CertificateSubjectName:
283
+ if (!authConfig.certPemFile || !authConfig.certKeyFile) {
284
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.CertificateFilesRequired);
285
+ }
286
+ token = await this.acquireTokenWithCertificate(authConfig, actualScope);
287
+ break;
288
+ case authConfiguration_1.AuthType.UserManagedIdentity:
289
+ if (!authConfig.clientId) {
290
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.ClientIdRequiredForUserManagedIdentity);
291
+ }
292
+ token = await this.acquireTokenWithUserAssignedIdentity(authConfig, actualScope);
293
+ break;
294
+ case authConfiguration_1.AuthType.SystemManagedIdentity:
295
+ token = await this.acquireTokenWithSystemAssignedIdentity(authConfig, actualScope);
296
+ break;
297
+ default:
298
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.UnsupportedAuthType, undefined, { authType });
299
+ }
300
+ if (token === undefined) {
301
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.FailedToAcquireToken);
302
+ }
303
+ this.cacheAccessToken(accessTokenCacheKey, token);
304
+ return token;
305
+ });
306
+ }
307
+ async acquireTokenOnBehalfOf(authConfigOrScopes, scopesOrOboAssertion, oboAssertion) {
308
+ return (0, agents_telemetry_1.trace)(observability_1.AuthenticationTraceDefinitions.acquireTokenOnBehalfOf, async ({ record }) => {
309
+ let authConfig;
310
+ let actualScopes;
311
+ let actualOboAssertion;
312
+ if (Array.isArray(authConfigOrScopes)) {
313
+ // Called as acquireTokenOnBehalfOf(scopes, oboAssertion)
314
+ if (!this.connectionSettings) {
315
+ throw new Error('Connection settings must be provided to constructor when calling acquireTokenOnBehalfOf(scopes, oboAssertion)');
316
+ }
317
+ authConfig = this.connectionSettings;
318
+ actualScopes = authConfigOrScopes;
319
+ actualOboAssertion = scopesOrOboAssertion;
320
+ }
321
+ else {
322
+ // Called as acquireTokenOnBehalfOf(authConfig, scopes, oboAssertion)
323
+ authConfig = authConfigOrScopes;
324
+ actualScopes = scopesOrOboAssertion;
325
+ actualOboAssertion = oboAssertion;
326
+ }
327
+ record({ scopes: actualScopes });
328
+ logger.debug('acquireTokenOnBehalfOf clientId=%s scopes=%o', authConfig.clientId, actualScopes);
329
+ const cca = this.getClientSecretClient(authConfig);
330
+ const token = await cca.acquireTokenOnBehalfOf({
331
+ oboAssertion: actualOboAssertion,
332
+ scopes: actualScopes
333
+ });
334
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
335
+ throw new Error('Failed to acquire token on behalf of user');
336
+ }
337
+ return token.accessToken;
338
+ });
339
+ }
340
+ async getAgenticInstanceToken(tenantId, agentAppInstanceId) {
341
+ return (0, agents_telemetry_1.trace)(observability_1.AuthenticationTraceDefinitions.getAgenticInstanceToken, async ({ record }) => {
342
+ var _a;
343
+ logger.debug('getAgenticInstanceToken tenantId=%s agentAppInstanceId=%s', tenantId, agentAppInstanceId);
344
+ record({ agenticInstanceId: agentAppInstanceId });
345
+ if (!this.connectionSettings) {
346
+ throw new Error('Connection settings must be provided when calling getAgenticInstanceToken');
347
+ }
348
+ const instanceTokenCacheKey = MsalTokenProvider.cacheKey('agentic-instance-token', this.resolveAuthority(tenantId), agentAppInstanceId, this.connectionSettings.clientId, this.connectionSettings.azureRegion);
349
+ const cachedInstanceToken = MsalTokenProvider._agenticTokenCache.get(instanceTokenCacheKey);
350
+ if (cachedInstanceToken) {
351
+ return cachedInstanceToken;
352
+ }
353
+ const appToken = await this.getAgenticApplicationToken(tenantId, agentAppInstanceId);
354
+ const cca = new msal_node_1.ConfidentialClientApplication({
355
+ auth: {
356
+ clientId: agentAppInstanceId,
357
+ clientAssertion: appToken,
358
+ authority: this.resolveAuthority(tenantId),
359
+ },
360
+ system: this.sysOptions
361
+ });
362
+ const token = await cca.acquireTokenByClientCredential({
363
+ scopes: ['api://AzureAdTokenExchange/.default'],
364
+ correlationId: (0, crypto_1.randomUUID)(),
365
+ azureRegion: (_a = this.connectionSettings) === null || _a === void 0 ? void 0 : _a.azureRegion
366
+ });
367
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
368
+ throw new Error(`Failed to acquire instance token for agent instance: ${agentAppInstanceId}`);
369
+ }
370
+ this.cacheAgenticAuthenticationResult(instanceTokenCacheKey, token);
371
+ return token.accessToken;
372
+ });
373
+ }
374
+ /**
375
+ * This method can optionally accept a tenant ID that overrides the tenant ID in the connection settings.
376
+ * The passed tenantId is always preferred over the configured tenantId when present.
377
+ * @param tenantId
378
+ * @returns
379
+ */
380
+ resolveAuthority(tenantId) {
381
+ var _a;
382
+ const { authorityEndpoint: configuredAuth, authority, tenantId: configuredTenantId } = (_a = this.connectionSettings) !== null && _a !== void 0 ? _a : {};
383
+ if (!tenantId) {
384
+ // No agentic tenant override — delegate to shared utility
385
+ return (0, authConfiguration_1.resolveAuthority)(configuredAuth !== null && configuredAuth !== void 0 ? configuredAuth : authority, configuredTenantId);
386
+ }
387
+ // Agentic override: build a clean base using the override tenant, then replace any
388
+ // /common or GUID placeholder left in the authority (e.g. from a multi-tenant config)
389
+ const base = (0, authConfiguration_1.resolveAuthority)(configuredAuth !== null && configuredAuth !== void 0 ? configuredAuth : authority, tenantId);
390
+ const guidPattern = /\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
391
+ if (base.endsWith('/common') || guidPattern.test(base)) {
392
+ return base.replace(/\/(?:common|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})(?=\/|$)/, `/${tenantId}`);
393
+ }
394
+ return base;
395
+ }
396
+ /**
397
+ * Does a direct HTTP call to acquire a token for agentic scenarios - do not use this directly!
398
+ * This method will be removed once MSAL is updated with the necessary features.
399
+ * (This is required in order to pass additional parameters into the auth call)
400
+ * @param tenantId
401
+ * @param clientId
402
+ * @param clientAssertion
403
+ * @param scopes
404
+ * @param tokenBodyParameters
405
+ * @returns
406
+ */
407
+ async acquireTokenForAgenticScenarios(tenantId, clientId, clientAssertion, scopes, tokenBodyParameters) {
408
+ if (!this.connectionSettings) {
409
+ throw new Error('Connection settings must be provided when calling getAgenticInstanceToken');
410
+ }
411
+ logger.debug('acquireTokenForAgenticScenarios clientId=%s tenantId=%s scopes=%o grant_type=%s', clientId, tenantId, scopes, tokenBodyParameters.grant_type);
412
+ // Check cache first
413
+ const cacheKey = this.getAgenticTokenCacheKey(tenantId, clientId, scopes, tokenBodyParameters);
414
+ if (MsalTokenProvider._agenticTokenCache.get(cacheKey)) {
415
+ return MsalTokenProvider._agenticTokenCache.get(cacheKey);
416
+ }
417
+ const url = `${this.resolveAuthority(tenantId)}/oauth2/v2.0/token`;
418
+ const data = {
419
+ client_id: clientId,
420
+ scope: scopes.join(' '),
421
+ ...tokenBodyParameters
422
+ };
423
+ if (clientAssertion) {
424
+ data.client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
425
+ data.client_assertion = clientAssertion;
426
+ }
427
+ else {
428
+ data.client_secret = this.connectionSettings.clientSecret;
429
+ }
430
+ if (data.grant_type !== 'user_fic') {
431
+ data.client_info = '2';
432
+ }
433
+ const controller = new AbortController();
434
+ const timeoutId = setTimeout(() => {
435
+ controller.abort(createTokenRequestTimeoutError(agenticTokenRequestTimeoutMs));
436
+ }, agenticTokenRequestTimeoutMs);
437
+ const token = await fetch(url, {
438
+ method: 'POST',
439
+ headers: {
440
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
441
+ },
442
+ body: new URLSearchParams(data).toString(),
443
+ signal: controller.signal
444
+ }).then(async (response) => {
445
+ if (!response.ok) {
446
+ const errorBody = await response.text();
447
+ const error = new Error(`Token request failed with status ${response.status}: ${errorBody}`);
448
+ error.toJSON = () => ({ status: response.status, body: errorBody });
449
+ throw error;
450
+ }
451
+ return response.json();
452
+ }).catch((error) => {
453
+ const resolvedError = isAbortError(error)
454
+ ? (controller.signal.reason instanceof Error ? controller.signal.reason : createTokenRequestTimeoutError(agenticTokenRequestTimeoutMs))
455
+ : error;
456
+ logger.error('Error acquiring token: ', resolvedError.toJSON ? resolvedError.toJSON() : resolvedError);
457
+ throw resolvedError;
458
+ }).finally(() => {
459
+ clearTimeout(timeoutId);
460
+ });
461
+ // capture token, expire local cache 5 minutes early
462
+ this.cacheAgenticToken(cacheKey, token.access_token, token.expires_in);
463
+ return token.access_token;
464
+ }
465
+ async getAgenticUserToken(tenantId, agentAppInstanceId, agenticUserId, scopes) {
466
+ return (0, agents_telemetry_1.trace)(observability_1.AuthenticationTraceDefinitions.getAgenticUserToken, async ({ record }) => {
467
+ logger.debug('getAgenticUserToken tenantId=%s agentAppInstanceId=%s scopes=%o', tenantId, agentAppInstanceId, scopes);
468
+ record({ agenticInstanceId: agentAppInstanceId, agenticUserId, scopes });
469
+ const userTokenParameters = {
470
+ user_id: agenticUserId,
471
+ grant_type: 'user_fic',
472
+ };
473
+ const userTokenCacheKey = this.getAgenticTokenCacheKey(tenantId, agentAppInstanceId, scopes, userTokenParameters);
474
+ const cachedUserToken = MsalTokenProvider._agenticTokenCache.get(userTokenCacheKey);
475
+ if (cachedUserToken) {
476
+ return cachedUserToken;
477
+ }
478
+ const agentToken = await this.getAgenticApplicationToken(tenantId, agentAppInstanceId);
479
+ const instanceToken = await this.getAgenticInstanceToken(tenantId, agentAppInstanceId);
480
+ const token = await this.acquireTokenForAgenticScenarios(tenantId, agentAppInstanceId, agentToken, scopes, {
481
+ ...userTokenParameters,
482
+ user_federated_identity_credential: instanceToken,
483
+ });
484
+ if (!token) {
485
+ throw new Error(`Failed to acquire instance token for user token: ${agentAppInstanceId}`);
486
+ }
487
+ return token;
488
+ });
489
+ }
490
+ async getAgenticApplicationToken(tenantId, agentAppInstanceId) {
491
+ var _a, _b;
492
+ if (!((_a = this.connectionSettings) === null || _a === void 0 ? void 0 : _a.clientId)) {
493
+ throw new Error('Connection settings must be provided when calling getAgenticApplicationToken');
494
+ }
495
+ logger.debug('getAgenticApplicationToken clientId=%s tenantId=%s agentAppInstanceId=%s', this.connectionSettings.clientId, tenantId, agentAppInstanceId);
496
+ const authType = (0, authConfiguration_1.resolveAuthType)(this.connectionSettings);
497
+ if (authType === authConfiguration_1.AuthType.IdentityProxyManager) {
498
+ let resource;
499
+ if (!this.connectionSettings.idpmResource) {
500
+ resource = 'api://AzureAdTokenExchange/.default';
501
+ }
502
+ else if (!URL.canParse(this.connectionSettings.idpmResource)) {
503
+ throw new Error('idpmResource must be a valid absolute URI');
504
+ }
505
+ else {
506
+ resource = this.connectionSettings.idpmResource;
507
+ }
508
+ const msiApp = new msal_node_1.ManagedIdentityApplication({
509
+ managedIdentityIdParams: {
510
+ userAssignedClientId: this.connectionSettings.clientId
511
+ },
512
+ system: this.sysOptions
513
+ });
514
+ const tokenResult = await msiApp.acquireToken({ resource });
515
+ if (!(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.accessToken)) {
516
+ throw new Error(`Failed to acquire token via IdentityProxyManager for agent instance: ${agentAppInstanceId}`);
517
+ }
518
+ logger.debug('getAgenticApplicationToken via IdentityProxyManager clientId=%s resource=%s', this.connectionSettings.clientId, resource);
519
+ return tokenResult.accessToken;
520
+ }
521
+ let clientAssertion;
522
+ switch (authType) {
523
+ case authConfiguration_1.AuthType.WorkloadIdentity: {
524
+ const tokenFilePath = (_b = this.connectionSettings.federatedTokenFile) !== null && _b !== void 0 ? _b : this.connectionSettings.WIDAssertionFile;
525
+ if (tokenFilePath === undefined) {
526
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.WorkloadIdentityTokenFileRequired);
527
+ }
528
+ clientAssertion = fs_1.default.readFileSync(tokenFilePath, 'utf8');
529
+ break;
530
+ }
531
+ case authConfiguration_1.AuthType.FederatedCredentials:
532
+ if (!this.connectionSettings.federatedClientId && !this.connectionSettings.FICClientId) {
533
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.FICClientIdRequired);
534
+ }
535
+ clientAssertion = await this.fetchExternalToken(this.connectionSettings.federatedClientId || this.connectionSettings.FICClientId);
536
+ break;
537
+ case authConfiguration_1.AuthType.Certificate:
538
+ case authConfiguration_1.AuthType.CertificateSubjectName:
539
+ if (!this.connectionSettings.certPemFile || !this.connectionSettings.certKeyFile) {
540
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.CertificateFilesRequired);
541
+ }
542
+ clientAssertion = this.getAssertionFromCert(this.connectionSettings);
543
+ break;
544
+ }
545
+ const token = await this.acquireTokenForAgenticScenarios(tenantId, this.connectionSettings.clientId, clientAssertion, ['api://AzureAdTokenExchange/.default'], {
546
+ grant_type: 'client_credentials',
547
+ fmi_path: agentAppInstanceId,
548
+ });
549
+ if (!token) {
550
+ throw new Error(`Failed to acquire token for agent instance: ${agentAppInstanceId}`);
551
+ }
552
+ return token;
553
+ }
554
+ /**
555
+ * Generates the client assertion using the provided certificate.
556
+ * @param authConfig The authentication configuration.
557
+ * @returns The client assertion.
558
+ */
559
+ getAssertionFromCert(authConfig) {
560
+ const base64url = (buf) => buf.toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
561
+ const privateKeyPem = fs_1.default.readFileSync(authConfig.certKeyFile);
562
+ const pemFile = fs_1.default.readFileSync(authConfig.certPemFile);
563
+ const pubKeyObject = new crypto_2.default.X509Certificate(pemFile);
564
+ const der = pubKeyObject.raw;
565
+ const x5tS256 = base64url(crypto_2.default.createHash('sha256').update(der).digest());
566
+ let x5c;
567
+ if (authConfig.sendX5C) {
568
+ x5c = pemFile.toString();
569
+ }
570
+ const now = Math.floor(Date.now() / 1000);
571
+ const payload = {
572
+ aud: `${this.resolveAuthority(authConfig.tenantId)}/oauth2/v2.0/token`,
573
+ iss: authConfig.clientId,
574
+ sub: authConfig.clientId,
575
+ jti: (0, crypto_1.randomUUID)(),
576
+ nbf: now,
577
+ iat: now,
578
+ exp: now + 600, // 10 minutes
579
+ };
580
+ return jsonwebtoken_1.default.sign(payload, privateKeyPem, {
581
+ algorithm: 'PS256',
582
+ header: { alg: 'PS256', typ: 'JWT', 'x5t#S256': x5tS256, x5c }
583
+ });
584
+ }
585
+ /**
586
+ * Acquires a token using a user-assigned identity.
587
+ * @param authConfig The authentication configuration.
588
+ * @param scope The scope for the token.
589
+ * @returns A promise that resolves to the access token.
590
+ */
591
+ async acquireTokenWithUserAssignedIdentity(authConfig, scope) {
592
+ const mia = new msal_node_1.ManagedIdentityApplication({
593
+ managedIdentityIdParams: {
594
+ userAssignedClientId: authConfig.clientId || ''
595
+ },
596
+ system: this.sysOptions
597
+ });
598
+ const token = await mia.acquireToken({
599
+ resource: scope
600
+ });
601
+ return token === null || token === void 0 ? void 0 : token.accessToken;
602
+ }
603
+ /**
604
+ * Acquires a token using a system-assigned identity.
605
+ * @param authConfig The authentication configuration.
606
+ * @param scope The scope for the token.
607
+ * @returns A promise that resolves to the access token.
608
+ */
609
+ async acquireTokenWithSystemAssignedIdentity(authConfig, scope) {
610
+ const mia = new msal_node_1.ManagedIdentityApplication({
611
+ system: this.sysOptions
612
+ });
613
+ const token = await mia.acquireToken({
614
+ resource: scope
615
+ });
616
+ return token === null || token === void 0 ? void 0 : token.accessToken;
617
+ }
618
+ /**
619
+ * Acquires a token using a certificate.
620
+ * @param authConfig The authentication configuration.
621
+ * @param scope The scope for the token.
622
+ * @returns A promise that resolves to the access token.
623
+ */
624
+ async acquireTokenWithCertificate(authConfig, scope) {
625
+ const cca = this.getCertificateClient(authConfig);
626
+ const token = await cca.acquireTokenByClientCredential({
627
+ scopes: [`${scope}/.default`],
628
+ correlationId: (0, crypto_1.randomUUID)(),
629
+ azureRegion: authConfig.azureRegion
630
+ });
631
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
632
+ throw new Error('Failed to acquire token using certificate');
633
+ }
634
+ return token.accessToken;
635
+ }
636
+ /**
637
+ * Acquires a token using a client secret.
638
+ * @param authConfig The authentication configuration.
639
+ * @param scope The scope for the token.
640
+ * @returns A promise that resolves to the access token.
641
+ */
642
+ async acquireAccessTokenViaSecret(authConfig, scope) {
643
+ const cca = this.getClientSecretClient(authConfig);
644
+ const token = await cca.acquireTokenByClientCredential({
645
+ scopes: [`${scope}/.default`],
646
+ correlationId: (0, crypto_1.randomUUID)(),
647
+ azureRegion: authConfig.azureRegion
648
+ });
649
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
650
+ throw new Error('Failed to acquire token using client secret');
651
+ }
652
+ return token.accessToken;
653
+ }
654
+ /**
655
+ * Acquires a token using a FIC client assertion.
656
+ * @param authConfig The authentication configuration.
657
+ * @param scope The scope for the token.
658
+ * @returns A promise that resolves to the access token.
659
+ */
660
+ async acquireAccessTokenViaFIC(authConfig, scope) {
661
+ var _a;
662
+ const scopes = [`${scope}/.default`];
663
+ const clientAssertion = await this.fetchExternalToken(authConfig.federatedClientId || authConfig.FICClientId);
664
+ const cca = new msal_node_1.ConfidentialClientApplication({
665
+ auth: {
666
+ clientId: authConfig.clientId,
667
+ authority: `${(_a = authConfig.authorityEndpoint) !== null && _a !== void 0 ? _a : authConfig.authority}/${authConfig.tenantId}`,
668
+ clientAssertion
669
+ },
670
+ system: this.sysOptions
671
+ });
672
+ const token = await cca.acquireTokenByClientCredential({ scopes, azureRegion: authConfig.azureRegion });
673
+ logger.debug('got token using FIC client assertion');
674
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
675
+ throw new Error('Failed to acquire token using FIC client assertion');
676
+ }
677
+ return token.accessToken;
678
+ }
679
+ /**
680
+ * Acquires a token using a Workload Identity client assertion.
681
+ * @param authConfig The authentication configuration.
682
+ * @param scope The scope for the token.
683
+ * @returns A promise that resolves to the access token.
684
+ */
685
+ async acquireAccessTokenViaWID(authConfig, scope) {
686
+ var _a;
687
+ const scopes = [`${scope}/.default`];
688
+ const tokenFilePath = (_a = authConfig.federatedTokenFile) !== null && _a !== void 0 ? _a : authConfig.WIDAssertionFile;
689
+ const clientAssertion = fs_1.default.readFileSync(tokenFilePath, 'utf8');
690
+ const cca = new msal_node_1.ConfidentialClientApplication({
691
+ auth: {
692
+ clientId: authConfig.clientId,
693
+ authority: `https://login.microsoftonline.com/${authConfig.tenantId}`,
694
+ clientAssertion
695
+ },
696
+ system: this.sysOptions
697
+ });
698
+ const token = await cca.acquireTokenByClientCredential({ scopes, azureRegion: authConfig.azureRegion });
699
+ logger.debug('got token using WID client assertion');
700
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
701
+ throw new Error('Failed to acquire token using WID client assertion');
702
+ }
703
+ return token.accessToken;
704
+ }
705
+ /**
706
+ * Fetches an external token.
707
+ * @param FICClientId The FIC client ID.
708
+ * @returns A promise that resolves to the external token.
709
+ */
710
+ async fetchExternalToken(FICClientId) {
711
+ const managedIdentityClientAssertion = new msal_node_1.ManagedIdentityApplication({
712
+ managedIdentityIdParams: {
713
+ userAssignedClientId: FICClientId
714
+ },
715
+ system: this.sysOptions
716
+ });
717
+ const response = await managedIdentityClientAssertion.acquireToken({
718
+ resource: audience,
719
+ forceRefresh: true
720
+ });
721
+ logger.debug('got token for FIC');
722
+ if (!(response === null || response === void 0 ? void 0 : response.accessToken)) {
723
+ throw new Error('Failed to acquire external token for FIC client assertion');
724
+ }
725
+ return response.accessToken;
726
+ }
727
+ }
728
+ exports.MsalTokenProvider = MsalTokenProvider;
729
+ MsalTokenProvider._accessTokenCache = new MemoryCache_1.MemoryCache();
730
+ MsalTokenProvider._agenticTokenCache = new MemoryCache_1.MemoryCache();
731
+ MsalTokenProvider._confidentialClients = new Map();
732
+ MsalTokenProvider._maxConfidentialClients = 100;
733
+ //# sourceMappingURL=msalTokenProvider.js.map