@microsoft/agents-hosting 1.6.0-beta.4.g8ab0e486bc → 1.6.0-beta.41.g36be9b7b46
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.
- package/dist/package.json +5 -9
- package/dist/src/agent-client/agentClient.js +2 -2
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.js +2 -2
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/agentApplication.js +27 -2
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +4 -0
- package/dist/src/app/auth/authorizationManager.js +94 -67
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +2 -2
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +10 -6
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +7 -1
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +2 -143
- package/dist/src/auth/authConfiguration.js +301 -257
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.js +27 -14
- package/dist/src/auth/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.d.ts +7 -0
- package/dist/src/auth/msalTokenProvider.js +156 -38
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/auth/settings.d.ts +327 -0
- package/dist/src/auth/settings.js +158 -0
- package/dist/src/auth/settings.js.map +1 -0
- package/dist/src/cloudAdapter.d.ts +51 -1
- package/dist/src/cloudAdapter.js +219 -50
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +2 -2
- package/dist/src/connector-client/connectorClient.js +7 -8
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +50 -0
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +1 -1
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/traces.d.ts +1 -1
- package/dist/src/observability/traces.js +2 -2
- package/dist/src/observability/traces.js.map +1 -1
- package/dist/src/utils/env.d.ts +50 -0
- package/dist/src/utils/env.js +113 -0
- package/dist/src/utils/env.js.map +1 -0
- package/dist/src/utils.d.ts +10 -0
- package/dist/src/utils.js +18 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +5 -9
- package/src/agent-client/agentClient.ts +2 -2
- package/src/agent-client/agentResponseHandler.ts +2 -2
- package/src/app/agentApplication.ts +28 -3
- package/src/app/auth/authorizationManager.ts +84 -41
- package/src/app/auth/handlers/azureBotAuthorization.ts +2 -2
- package/src/app/proactive/createConversationOptionsBuilder.ts +8 -4
- package/src/app/teamsAttachmentDownloader.ts +6 -1
- package/src/auth/authConfiguration.ts +317 -356
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalConnectionManager.ts +27 -10
- package/src/auth/msalTokenProvider.ts +143 -33
- package/src/auth/settings.ts +323 -0
- package/src/cloudAdapter.ts +272 -10
- package/src/connector-client/connectorClient.ts +8 -8
- package/src/errorHelper.ts +57 -0
- package/src/index.ts +4 -1
- package/src/oauth/userTokenClient.ts +1 -1
- package/src/observability/traces.ts +2 -2
- package/src/utils/env.ts +105 -0
- package/src/utils.ts +14 -0
|
@@ -21,7 +21,7 @@ const logger = debug('agents:jwt-middleware')
|
|
|
21
21
|
export function buildJwksUri (iss: string, authConfig: AuthConfiguration): string {
|
|
22
22
|
return iss === 'https://api.botframework.com'
|
|
23
23
|
? 'https://login.botframework.com/v1/.well-known/keys'
|
|
24
|
-
: `${resolveAuthority(authConfig.authority, authConfig.tenantId)}/discovery/v2.0/keys`
|
|
24
|
+
: `${resolveAuthority(authConfig.authorityEndpoint ?? authConfig.authority, authConfig.tenantId)}/discovery/v2.0/keys`
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { Activity, RoleTypes } from '@microsoft/agents-activity'
|
|
7
7
|
import { debug } from '@microsoft/agents-telemetry'
|
|
8
|
-
import { AuthConfiguration, resolveAuthority } from './authConfiguration'
|
|
8
|
+
import { AuthConfiguration, AuthType, resolveAuthority } from './authConfiguration'
|
|
9
9
|
import { Connections } from './connections'
|
|
10
10
|
import { MsalTokenProvider } from './msalTokenProvider'
|
|
11
11
|
import { JwtPayload } from 'jsonwebtoken'
|
|
@@ -44,13 +44,16 @@ export class MsalConnectionManager implements Connections {
|
|
|
44
44
|
|
|
45
45
|
for (const [name, provider] of this._connections.entries()) {
|
|
46
46
|
const cfg = provider.connectionSettings
|
|
47
|
-
const authType = cfg?.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
const authType = cfg?.authType ??
|
|
48
|
+
(cfg?.certPemFile
|
|
49
|
+
? AuthType.Certificate
|
|
50
|
+
: cfg?.clientSecret
|
|
51
|
+
? AuthType.ClientSecret
|
|
52
|
+
: cfg?.WIDAssertionFile
|
|
53
|
+
? AuthType.WorkloadIdentity
|
|
54
|
+
: cfg?.federatedClientId || cfg?.FICClientId
|
|
55
|
+
? AuthType.FederatedCredentials
|
|
56
|
+
: 'none')
|
|
54
57
|
logger.debug('connection "%s" clientId=%s tenantId=%s authType=%s', name, cfg?.clientId ?? '<none>', cfg?.tenantId ?? '<none>', authType)
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -185,13 +188,27 @@ export class MsalConnectionManager implements Connections {
|
|
|
185
188
|
|
|
186
189
|
private applyConnectionDefaults (conn: MsalTokenProvider): MsalTokenProvider {
|
|
187
190
|
if (conn.connectionSettings) {
|
|
188
|
-
conn.connectionSettings.
|
|
191
|
+
conn.connectionSettings.authorityEndpoint ??= conn.connectionSettings.authority || 'https://login.microsoftonline.com'
|
|
192
|
+
conn.connectionSettings.authority ??= conn.connectionSettings.authorityEndpoint
|
|
189
193
|
conn.connectionSettings.issuers ??= [
|
|
190
194
|
'https://api.botframework.com',
|
|
191
195
|
`${resolveAuthority('https://sts.windows.net', conn.connectionSettings.tenantId)}/`,
|
|
192
|
-
`${resolveAuthority(conn.connectionSettings.
|
|
196
|
+
`${resolveAuthority(conn.connectionSettings.authorityEndpoint, conn.connectionSettings.tenantId)}/v2.0`
|
|
193
197
|
]
|
|
198
|
+
// For backward compatibility
|
|
199
|
+
if (conn.connectionSettings.federatedClientId) {
|
|
200
|
+
conn.connectionSettings.FICClientId = conn.connectionSettings.federatedClientId
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (conn.connectionSettings.scopes?.length) {
|
|
204
|
+
conn.connectionSettings.scope = conn.connectionSettings.scopes?.[0]
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (conn.connectionSettings.authorityEndpoint) {
|
|
208
|
+
conn.connectionSettings.authority = conn.connectionSettings.authorityEndpoint
|
|
209
|
+
}
|
|
194
210
|
}
|
|
211
|
+
|
|
195
212
|
return conn
|
|
196
213
|
}
|
|
197
214
|
}
|
|
@@ -5,16 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
import { ConfidentialClientApplication, LogLevel, ManagedIdentityApplication, NodeSystemOptions } from '@azure/msal-node'
|
|
7
7
|
import axios from 'axios'
|
|
8
|
-
import { AuthConfiguration, resolveAuthority as resolveAuthorityUtil } from './authConfiguration'
|
|
8
|
+
import { AuthConfiguration, AuthType, resolveAuthority as resolveAuthorityUtil } from './authConfiguration'
|
|
9
9
|
import { AuthProvider } from './authProvider'
|
|
10
10
|
import { debug, trace } from '@microsoft/agents-telemetry'
|
|
11
|
-
import {
|
|
11
|
+
import { randomUUID } from 'crypto'
|
|
12
12
|
import { MemoryCache } from './MemoryCache'
|
|
13
13
|
import jwt from 'jsonwebtoken'
|
|
14
14
|
|
|
15
15
|
import fs from 'fs'
|
|
16
16
|
import crypto from 'crypto'
|
|
17
17
|
import { AuthenticationTraceDefinitions } from '../observability'
|
|
18
|
+
import { ExceptionHelper } from '@microsoft/agents-activity'
|
|
19
|
+
import { Errors } from '../errorHelper'
|
|
18
20
|
|
|
19
21
|
const audience = 'api://AzureADTokenExchange'
|
|
20
22
|
const logger = debug('agents:msal')
|
|
@@ -70,34 +72,77 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
let token
|
|
73
|
-
if (authConfig.
|
|
74
|
-
record({ method:
|
|
75
|
-
logger.debug(
|
|
75
|
+
if (authConfig.authType) {
|
|
76
|
+
record({ method: authConfig.authType })
|
|
77
|
+
logger.debug(`getAccessToken via ${authConfig.authType} clientId=${authConfig.clientId} scope=${actualScope}`)
|
|
78
|
+
switch (authConfig.authType) {
|
|
79
|
+
case AuthType.WorkloadIdentity: {
|
|
80
|
+
const tokenFilePath = authConfig.federatedTokenFile ?? authConfig.WIDAssertionFile
|
|
81
|
+
if (!tokenFilePath) {
|
|
82
|
+
throw ExceptionHelper.generateException(Error, Errors.WorkloadIdentityTokenFileRequired)
|
|
83
|
+
}
|
|
84
|
+
token = await this.acquireAccessTokenViaWID(authConfig, actualScope)
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
case AuthType.FederatedCredentials:
|
|
88
|
+
if (!authConfig.federatedClientId && !authConfig.FICClientId) {
|
|
89
|
+
throw ExceptionHelper.generateException(Error, Errors.FICClientIdRequired)
|
|
90
|
+
}
|
|
91
|
+
token = await this.acquireAccessTokenViaFIC(authConfig, actualScope)
|
|
92
|
+
break
|
|
93
|
+
case AuthType.ClientSecret:
|
|
94
|
+
if (!authConfig.clientSecret) {
|
|
95
|
+
throw ExceptionHelper.generateException(Error, Errors.ClientSecretRequired)
|
|
96
|
+
}
|
|
97
|
+
token = await this.acquireAccessTokenViaSecret(authConfig, actualScope)
|
|
98
|
+
break
|
|
99
|
+
case AuthType.Certificate:
|
|
100
|
+
case AuthType.CertificateSubjectName:
|
|
101
|
+
if (!authConfig.certPemFile || !authConfig.certKeyFile) {
|
|
102
|
+
throw ExceptionHelper.generateException(Error, Errors.CertificateFilesRequired)
|
|
103
|
+
}
|
|
104
|
+
token = await this.acquireTokenWithCertificate(authConfig, actualScope)
|
|
105
|
+
break
|
|
106
|
+
case AuthType.UserManagedIdentity:
|
|
107
|
+
if (!authConfig.clientId) {
|
|
108
|
+
throw ExceptionHelper.generateException(Error, Errors.ClientIdRequiredForUserManagedIdentity)
|
|
109
|
+
}
|
|
110
|
+
token = await this.acquireTokenWithUserAssignedIdentity(authConfig, actualScope)
|
|
111
|
+
break
|
|
112
|
+
case AuthType.SystemManagedIdentity:
|
|
113
|
+
token = await this.acquireTokenWithSystemAssignedIdentity(authConfig, actualScope)
|
|
114
|
+
break
|
|
115
|
+
default:
|
|
116
|
+
throw ExceptionHelper.generateException(Error, Errors.UnsupportedAuthType, undefined, { authType: authConfig.authType })
|
|
117
|
+
}
|
|
118
|
+
} else if (authConfig.WIDAssertionFile !== undefined) {
|
|
119
|
+
record({ method: AuthType.WorkloadIdentity })
|
|
120
|
+
logger.debug('getAccessToken via method=%s clientId=%s scope=%s', AuthType.WorkloadIdentity, authConfig.clientId, actualScope)
|
|
76
121
|
token = await this.acquireAccessTokenViaWID(authConfig, actualScope)
|
|
77
|
-
} else if (authConfig.FICClientId !== undefined) {
|
|
78
|
-
record({ method:
|
|
79
|
-
logger.debug('getAccessToken via
|
|
122
|
+
} else if (authConfig.federatedClientId !== undefined || authConfig.FICClientId !== undefined) {
|
|
123
|
+
record({ method: AuthType.FederatedCredentials })
|
|
124
|
+
logger.debug('getAccessToken via method=%s clientId=%s scope=%s', AuthType.FederatedCredentials, authConfig.clientId, actualScope)
|
|
80
125
|
token = await this.acquireAccessTokenViaFIC(authConfig, actualScope)
|
|
81
126
|
} else if (authConfig.clientSecret !== undefined) {
|
|
82
|
-
record({ method:
|
|
83
|
-
logger.debug('getAccessToken via
|
|
127
|
+
record({ method: AuthType.ClientSecret })
|
|
128
|
+
logger.debug('getAccessToken via method=%s clientId=%s scope=%s', AuthType.ClientSecret, authConfig.clientId, actualScope)
|
|
84
129
|
token = await this.acquireAccessTokenViaSecret(authConfig, actualScope)
|
|
85
130
|
} else if (authConfig.certPemFile !== undefined &&
|
|
86
131
|
authConfig.certKeyFile !== undefined) {
|
|
87
|
-
record({ method:
|
|
88
|
-
logger.debug('getAccessToken via
|
|
132
|
+
record({ method: AuthType.Certificate })
|
|
133
|
+
logger.debug('getAccessToken via method=%s clientId=%s scope=%s', AuthType.Certificate, authConfig.clientId, actualScope)
|
|
89
134
|
token = await this.acquireTokenWithCertificate(authConfig, actualScope)
|
|
90
135
|
} else if (authConfig.clientSecret === undefined &&
|
|
91
136
|
authConfig.certPemFile === undefined &&
|
|
92
137
|
authConfig.certKeyFile === undefined) {
|
|
93
|
-
record({ method:
|
|
94
|
-
logger.debug('getAccessToken via
|
|
138
|
+
record({ method: AuthType.UserManagedIdentity })
|
|
139
|
+
logger.debug('getAccessToken via method=%s clientId=%s scope=%s', AuthType.UserManagedIdentity, authConfig.clientId, actualScope)
|
|
95
140
|
token = await this.acquireTokenWithUserAssignedIdentity(authConfig, actualScope)
|
|
96
141
|
} else {
|
|
97
|
-
throw
|
|
142
|
+
throw ExceptionHelper.generateException(Error, Errors.InvalidAuthConfig)
|
|
98
143
|
}
|
|
99
144
|
if (token === undefined) {
|
|
100
|
-
throw
|
|
145
|
+
throw ExceptionHelper.generateException(Error, Errors.FailedToAcquireToken)
|
|
101
146
|
}
|
|
102
147
|
|
|
103
148
|
return token
|
|
@@ -137,7 +182,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
137
182
|
const cca = new ConfidentialClientApplication({
|
|
138
183
|
auth: {
|
|
139
184
|
clientId: authConfig.clientId as string,
|
|
140
|
-
authority: `${authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
185
|
+
authority: `${authConfig.authorityEndpoint ?? authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
141
186
|
clientSecret: authConfig.clientSecret
|
|
142
187
|
},
|
|
143
188
|
system: this.sysOptions
|
|
@@ -174,7 +219,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
174
219
|
|
|
175
220
|
const token = await cca.acquireTokenByClientCredential({
|
|
176
221
|
scopes: ['api://AzureAdTokenExchange/.default'],
|
|
177
|
-
correlationId:
|
|
222
|
+
correlationId: randomUUID(),
|
|
178
223
|
azureRegion: this.connectionSettings?.azureRegion
|
|
179
224
|
})
|
|
180
225
|
|
|
@@ -193,16 +238,16 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
193
238
|
* @returns
|
|
194
239
|
*/
|
|
195
240
|
private resolveAuthority (tenantId?: string) : string {
|
|
196
|
-
const {
|
|
241
|
+
const { authorityEndpoint: configuredAuth, authority, tenantId: configuredTenantId } = this.connectionSettings ?? {}
|
|
197
242
|
|
|
198
243
|
if (!tenantId) {
|
|
199
244
|
// No agentic tenant override — delegate to shared utility
|
|
200
|
-
return resolveAuthorityUtil(configuredAuth, configuredTenantId)
|
|
245
|
+
return resolveAuthorityUtil(configuredAuth ?? authority, configuredTenantId)
|
|
201
246
|
}
|
|
202
247
|
|
|
203
248
|
// Agentic override: build a clean base using the override tenant, then replace any
|
|
204
249
|
// /common or GUID placeholder left in the authority (e.g. from a multi-tenant config)
|
|
205
|
-
const base = resolveAuthorityUtil(configuredAuth, tenantId)
|
|
250
|
+
const base = resolveAuthorityUtil(configuredAuth ?? authority, tenantId)
|
|
206
251
|
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}$/
|
|
207
252
|
|
|
208
253
|
if (base.endsWith('/common') || guidPattern.test(base)) {
|
|
@@ -303,12 +348,60 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
303
348
|
}
|
|
304
349
|
logger.debug('getAgenticApplicationToken clientId=%s tenantId=%s agentAppInstanceId=%s', this.connectionSettings.clientId, tenantId, agentAppInstanceId)
|
|
305
350
|
|
|
351
|
+
if (this.connectionSettings.authType === AuthType.IdentityProxyManager) {
|
|
352
|
+
let resource: string
|
|
353
|
+
if (!this.connectionSettings.idpmResource) {
|
|
354
|
+
resource = 'api://AzureAdTokenExchange/.default'
|
|
355
|
+
} else if (!URL.canParse(this.connectionSettings.idpmResource)) {
|
|
356
|
+
throw new Error('idpmResource must be a valid absolute URI')
|
|
357
|
+
} else {
|
|
358
|
+
resource = this.connectionSettings.idpmResource
|
|
359
|
+
}
|
|
360
|
+
const msiApp = new ManagedIdentityApplication({
|
|
361
|
+
managedIdentityIdParams: {
|
|
362
|
+
userAssignedClientId: this.connectionSettings.clientId
|
|
363
|
+
},
|
|
364
|
+
system: this.sysOptions
|
|
365
|
+
})
|
|
366
|
+
const tokenResult = await msiApp.acquireToken({ resource })
|
|
367
|
+
if (!tokenResult?.accessToken) {
|
|
368
|
+
throw new Error(`Failed to acquire token via IdentityProxyManager for agent instance: ${agentAppInstanceId}`)
|
|
369
|
+
}
|
|
370
|
+
logger.debug('getAgenticApplicationToken via IdentityProxyManager clientId=%s resource=%s', this.connectionSettings.clientId, resource)
|
|
371
|
+
return tokenResult.accessToken
|
|
372
|
+
}
|
|
373
|
+
|
|
306
374
|
let clientAssertion
|
|
307
375
|
|
|
308
|
-
if (this.connectionSettings.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
376
|
+
if (this.connectionSettings.authType) {
|
|
377
|
+
switch (this.connectionSettings.authType) {
|
|
378
|
+
case AuthType.WorkloadIdentity: {
|
|
379
|
+
const tokenFilePath = this.connectionSettings.federatedTokenFile ?? this.connectionSettings.WIDAssertionFile
|
|
380
|
+
if (tokenFilePath === undefined) {
|
|
381
|
+
throw ExceptionHelper.generateException(Error, Errors.WorkloadIdentityTokenFileRequired)
|
|
382
|
+
}
|
|
383
|
+
clientAssertion = fs.readFileSync(tokenFilePath as string, 'utf8')
|
|
384
|
+
break
|
|
385
|
+
}
|
|
386
|
+
case AuthType.FederatedCredentials:
|
|
387
|
+
if (!this.connectionSettings.federatedClientId && !this.connectionSettings.FICClientId) {
|
|
388
|
+
throw ExceptionHelper.generateException(Error, Errors.FICClientIdRequired)
|
|
389
|
+
}
|
|
390
|
+
clientAssertion = await this.fetchExternalToken(this.connectionSettings.federatedClientId as string || this.connectionSettings.FICClientId as string)
|
|
391
|
+
break
|
|
392
|
+
case AuthType.Certificate:
|
|
393
|
+
case AuthType.CertificateSubjectName:
|
|
394
|
+
if (!this.connectionSettings.certPemFile || !this.connectionSettings.certKeyFile) {
|
|
395
|
+
throw ExceptionHelper.generateException(Error, Errors.CertificateFilesRequired)
|
|
396
|
+
}
|
|
397
|
+
clientAssertion = this.getAssertionFromCert(this.connectionSettings)
|
|
398
|
+
break
|
|
399
|
+
}
|
|
400
|
+
} else if (this.connectionSettings.WIDAssertionFile !== undefined) {
|
|
401
|
+
const tokenFilePath = this.connectionSettings.federatedTokenFile ?? this.connectionSettings.WIDAssertionFile
|
|
402
|
+
clientAssertion = fs.readFileSync(tokenFilePath as string, 'utf8')
|
|
403
|
+
} else if (this.connectionSettings.federatedClientId !== undefined || this.connectionSettings.FICClientId !== undefined) {
|
|
404
|
+
clientAssertion = await this.fetchExternalToken(this.connectionSettings.federatedClientId as string || this.connectionSettings.FICClientId as string)
|
|
312
405
|
} else if (this.connectionSettings.certPemFile !== undefined &&
|
|
313
406
|
this.connectionSettings.certKeyFile !== undefined) {
|
|
314
407
|
clientAssertion = this.getAssertionFromCert(this.connectionSettings)
|
|
@@ -380,7 +473,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
380
473
|
aud: `${this.resolveAuthority(authConfig.tenantId)}/oauth2/v2.0/token`,
|
|
381
474
|
iss: authConfig.clientId,
|
|
382
475
|
sub: authConfig.clientId,
|
|
383
|
-
jti:
|
|
476
|
+
jti: randomUUID(),
|
|
384
477
|
nbf: now,
|
|
385
478
|
iat: now,
|
|
386
479
|
exp: now + 600, // 10 minutes
|
|
@@ -415,6 +508,22 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
415
508
|
return token?.accessToken
|
|
416
509
|
}
|
|
417
510
|
|
|
511
|
+
/**
|
|
512
|
+
* Acquires a token using a system-assigned identity.
|
|
513
|
+
* @param authConfig The authentication configuration.
|
|
514
|
+
* @param scope The scope for the token.
|
|
515
|
+
* @returns A promise that resolves to the access token.
|
|
516
|
+
*/
|
|
517
|
+
private async acquireTokenWithSystemAssignedIdentity (authConfig: AuthConfiguration, scope: string) {
|
|
518
|
+
const mia = new ManagedIdentityApplication({
|
|
519
|
+
system: this.sysOptions
|
|
520
|
+
})
|
|
521
|
+
const token = await mia.acquireToken({
|
|
522
|
+
resource: scope
|
|
523
|
+
})
|
|
524
|
+
return token?.accessToken
|
|
525
|
+
}
|
|
526
|
+
|
|
418
527
|
/**
|
|
419
528
|
* Acquires a token using a certificate.
|
|
420
529
|
* @param authConfig The authentication configuration.
|
|
@@ -440,7 +549,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
440
549
|
const cca = new ConfidentialClientApplication({
|
|
441
550
|
auth: {
|
|
442
551
|
clientId: authConfig.clientId || '',
|
|
443
|
-
authority: `${authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
552
|
+
authority: `${authConfig.authorityEndpoint ?? authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
444
553
|
clientCertificate: {
|
|
445
554
|
privateKey: privateKey as string,
|
|
446
555
|
thumbprint: pubKeyObject.fingerprint.replaceAll(':', ''),
|
|
@@ -451,7 +560,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
451
560
|
})
|
|
452
561
|
const token = await cca.acquireTokenByClientCredential({
|
|
453
562
|
scopes: [`${scope}/.default`],
|
|
454
|
-
correlationId:
|
|
563
|
+
correlationId: randomUUID(),
|
|
455
564
|
azureRegion: authConfig.azureRegion
|
|
456
565
|
})
|
|
457
566
|
if (!token?.accessToken) {
|
|
@@ -470,14 +579,14 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
470
579
|
const cca = new ConfidentialClientApplication({
|
|
471
580
|
auth: {
|
|
472
581
|
clientId: authConfig.clientId as string,
|
|
473
|
-
authority: `${authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
582
|
+
authority: `${authConfig.authorityEndpoint ?? authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
474
583
|
clientSecret: authConfig.clientSecret
|
|
475
584
|
},
|
|
476
585
|
system: this.sysOptions
|
|
477
586
|
})
|
|
478
587
|
const token = await cca.acquireTokenByClientCredential({
|
|
479
588
|
scopes: [`${scope}/.default`],
|
|
480
|
-
correlationId:
|
|
589
|
+
correlationId: randomUUID(),
|
|
481
590
|
azureRegion: authConfig.azureRegion
|
|
482
591
|
})
|
|
483
592
|
if (!token?.accessToken) {
|
|
@@ -494,11 +603,11 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
494
603
|
*/
|
|
495
604
|
private async acquireAccessTokenViaFIC (authConfig: AuthConfiguration, scope: string) : Promise<string> {
|
|
496
605
|
const scopes = [`${scope}/.default`]
|
|
497
|
-
const clientAssertion = await this.fetchExternalToken(authConfig.FICClientId as string)
|
|
606
|
+
const clientAssertion = await this.fetchExternalToken(authConfig.federatedClientId as string || authConfig.FICClientId as string)
|
|
498
607
|
const cca = new ConfidentialClientApplication({
|
|
499
608
|
auth: {
|
|
500
609
|
clientId: authConfig.clientId as string,
|
|
501
|
-
authority: `${authConfig.authority}/${authConfig.tenantId}`,
|
|
610
|
+
authority: `${authConfig.authorityEndpoint ?? authConfig.authority}/${authConfig.tenantId}`,
|
|
502
611
|
clientAssertion
|
|
503
612
|
},
|
|
504
613
|
system: this.sysOptions
|
|
@@ -519,7 +628,8 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
519
628
|
*/
|
|
520
629
|
private async acquireAccessTokenViaWID (authConfig: AuthConfiguration, scope: string) : Promise<string> {
|
|
521
630
|
const scopes = [`${scope}/.default`]
|
|
522
|
-
const
|
|
631
|
+
const tokenFilePath = authConfig.federatedTokenFile ?? authConfig.WIDAssertionFile
|
|
632
|
+
const clientAssertion = fs.readFileSync(tokenFilePath as string, 'utf8')
|
|
523
633
|
const cca = new ConfidentialClientApplication({
|
|
524
634
|
auth: {
|
|
525
635
|
clientId: authConfig.clientId as string,
|