@microsoft/agents-hosting 1.5.0-beta.6.ga236d9a19c → 1.5.1
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 +10 -9
- package/dist/src/activityHandler.js +2 -2
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentClient.js +49 -40
- 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.d.ts +36 -10
- package/dist/src/app/agentApplication.js +169 -99
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +15 -0
- package/dist/src/app/agentApplicationBuilder.js +22 -4
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +38 -0
- package/dist/src/app/attachmentDownloader.js +2 -2
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/auth/authorization.js +12 -9
- package/dist/src/app/auth/authorization.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +18 -5
- package/dist/src/app/auth/authorizationManager.js +258 -45
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlerStorage.js +3 -1
- package/dist/src/app/auth/handlerStorage.js.map +1 -1
- package/dist/src/app/auth/handlers/agenticAuthorization.d.ts +19 -16
- package/dist/src/app/auth/handlers/agenticAuthorization.js +46 -52
- package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -1
- package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +51 -75
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +217 -192
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
- package/dist/src/app/auth/types.d.ts +100 -1
- package/dist/src/app/auth/utils.d.ts +10 -0
- package/dist/src/app/auth/utils.js +21 -0
- package/dist/src/app/auth/utils.js.map +1 -0
- package/dist/src/app/index.d.ts +1 -0
- package/dist/src/app/index.js +1 -0
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/proactive/conversation.d.ts +43 -0
- package/dist/src/app/proactive/conversation.js +67 -0
- package/dist/src/app/proactive/conversation.js.map +1 -0
- package/dist/src/app/proactive/conversationBuilder.d.ts +54 -0
- package/dist/src/app/proactive/conversationBuilder.js +110 -0
- package/dist/src/app/proactive/conversationBuilder.js.map +1 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.d.ts +68 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.js +125 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.js.map +1 -0
- package/dist/src/app/proactive/createConversationOptions.d.ts +30 -0
- package/dist/src/app/proactive/createConversationOptions.js +10 -0
- package/dist/src/app/proactive/createConversationOptions.js.map +1 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.d.ts +69 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +141 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -0
- package/dist/src/app/proactive/index.d.ts +7 -0
- package/dist/src/app/proactive/index.js +26 -0
- package/dist/src/app/proactive/index.js.map +1 -0
- package/dist/src/app/proactive/proactive.d.ts +248 -0
- package/dist/src/app/proactive/proactive.js +310 -0
- package/dist/src/app/proactive/proactive.js.map +1 -0
- package/dist/src/app/proactive/proactiveOptions.d.ts +19 -0
- package/dist/src/app/proactive/proactiveOptions.js +5 -0
- package/dist/src/app/proactive/proactiveOptions.js.map +1 -0
- package/dist/src/app/streaming/streamingResponse.js +2 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +2 -2
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/app/turnState.js +2 -2
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +61 -0
- package/dist/src/auth/authConfiguration.js +52 -3
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -2
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.js +20 -0
- package/dist/src/auth/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msalTokenCredential.js +3 -0
- package/dist/src/auth/msalTokenCredential.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.js +136 -110
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.js +2 -2
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cloudAdapter.js +201 -154
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.js +176 -127
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +108 -0
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/middlewareSet.js +2 -2
- package/dist/src/middlewareSet.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +78 -48
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/index.d.ts +2 -0
- package/dist/src/observability/index.js +21 -0
- package/dist/src/observability/index.js.map +1 -0
- package/dist/src/observability/metrics.d.ts +21 -0
- package/dist/src/observability/metrics.js +87 -0
- package/dist/src/observability/metrics.js.map +1 -0
- package/dist/src/observability/traces.d.ts +234 -0
- package/dist/src/observability/traces.js +962 -0
- package/dist/src/observability/traces.js.map +1 -0
- package/dist/src/state/agentState.js +2 -2
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/storage/fileStorage.js +38 -28
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.js +41 -30
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/transcript/fileTranscriptLogger.js +2 -2
- package/dist/src/transcript/fileTranscriptLogger.js.map +1 -1
- package/dist/src/transcript/transcriptLoggerMiddleware.js +2 -2
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -1
- package/dist/src/turnContext.js +48 -42
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +10 -9
- package/src/activityHandler.ts +1 -1
- package/src/agent-client/agentClient.ts +53 -42
- package/src/agent-client/agentResponseHandler.ts +1 -1
- package/src/app/agentApplication.ts +212 -86
- package/src/app/agentApplicationBuilder.ts +26 -4
- package/src/app/agentApplicationOptions.ts +43 -0
- package/src/app/attachmentDownloader.ts +1 -1
- package/src/app/auth/authorization.ts +11 -8
- package/src/app/auth/authorizationManager.ts +297 -45
- package/src/app/auth/handlerStorage.ts +3 -1
- package/src/app/auth/handlers/agenticAuthorization.ts +68 -72
- package/src/app/auth/handlers/azureBotAuthorization.ts +260 -264
- package/src/app/auth/types.ts +102 -1
- package/src/app/auth/utils.ts +22 -0
- package/src/app/index.ts +1 -0
- package/src/app/proactive/conversation.ts +87 -0
- package/src/app/proactive/conversationBuilder.ts +139 -0
- package/src/app/proactive/conversationReferenceBuilder.ts +161 -0
- package/src/app/proactive/createConversationOptions.ts +35 -0
- package/src/app/proactive/createConversationOptionsBuilder.ts +181 -0
- package/src/app/proactive/index.ts +10 -0
- package/src/app/proactive/proactive.ts +524 -0
- package/src/app/proactive/proactiveOptions.ts +24 -0
- package/src/app/streaming/streamingResponse.ts +1 -1
- package/src/app/teamsAttachmentDownloader.ts +1 -1
- package/src/app/turnState.ts +1 -1
- package/src/auth/authConfiguration.ts +58 -1
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalConnectionManager.ts +22 -0
- package/src/auth/msalTokenCredential.ts +4 -0
- package/src/auth/msalTokenProvider.ts +138 -107
- package/src/baseAdapter.ts +1 -1
- package/src/cloudAdapter.ts +239 -184
- package/src/connector-client/connectorClient.ts +169 -126
- package/src/errorHelper.ts +124 -0
- package/src/middlewareSet.ts +1 -1
- package/src/oauth/userTokenClient.ts +70 -46
- package/src/observability/index.ts +5 -0
- package/src/observability/metrics.ts +103 -0
- package/src/observability/traces.ts +988 -0
- package/src/state/agentState.ts +1 -1
- package/src/storage/fileStorage.ts +36 -26
- package/src/storage/memoryStorage.ts +40 -29
- package/src/transcript/fileTranscriptLogger.ts +1 -1
- package/src/transcript/transcriptLoggerMiddleware.ts +1 -1
- package/src/turnContext.ts +47 -41
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Activity, RoleTypes } from '@microsoft/agents-activity'
|
|
7
|
+
import { debug } from '@microsoft/agents-telemetry'
|
|
7
8
|
import { AuthConfiguration, resolveAuthority } from './authConfiguration'
|
|
8
9
|
import { Connections } from './connections'
|
|
9
10
|
import { MsalTokenProvider } from './msalTokenProvider'
|
|
10
11
|
import { JwtPayload } from 'jsonwebtoken'
|
|
11
12
|
|
|
13
|
+
const logger = debug('agents:authorization:connections')
|
|
14
|
+
|
|
12
15
|
export interface ConnectionMapItem {
|
|
13
16
|
audience?: string
|
|
14
17
|
serviceUrl: string
|
|
@@ -38,6 +41,22 @@ export class MsalConnectionManager implements Connections {
|
|
|
38
41
|
this._serviceConnectionConfiguration = config
|
|
39
42
|
}
|
|
40
43
|
}
|
|
44
|
+
|
|
45
|
+
for (const [name, provider] of this._connections.entries()) {
|
|
46
|
+
const cfg = provider.connectionSettings
|
|
47
|
+
const authType = cfg?.certPemFile
|
|
48
|
+
? 'certificate'
|
|
49
|
+
: cfg?.clientSecret
|
|
50
|
+
? 'clientSecret'
|
|
51
|
+
: cfg?.WIDAssertionFile || cfg?.FICClientId
|
|
52
|
+
? 'workloadIdentity'
|
|
53
|
+
: 'none'
|
|
54
|
+
logger.debug('connection "%s" clientId=%s tenantId=%s authType=%s', name, cfg?.clientId ?? '<none>', cfg?.tenantId ?? '<none>', authType)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const item of this._connectionsMap) {
|
|
58
|
+
logger.debug('connectionsMap: %s -> %s audience=%s', item.serviceUrl, item.connection, item.audience ?? '')
|
|
59
|
+
}
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
/**
|
|
@@ -107,6 +126,7 @@ export class MsalConnectionManager implements Connections {
|
|
|
107
126
|
if (!audience || !serviceUrl) throw new Error('Audience and Service URL are required to get the token provider.')
|
|
108
127
|
|
|
109
128
|
if (this._connectionsMap.length === 0) {
|
|
129
|
+
logger.debug('no connectionsMap, using default connection for serviceUrl=%s', serviceUrl)
|
|
110
130
|
return this.getDefaultConnection()
|
|
111
131
|
}
|
|
112
132
|
|
|
@@ -120,11 +140,13 @@ export class MsalConnectionManager implements Connections {
|
|
|
120
140
|
|
|
121
141
|
if (audienceMatch) {
|
|
122
142
|
if (item.serviceUrl === '*' || !item.serviceUrl) {
|
|
143
|
+
logger.debug('connection "%s" matched (wildcard/no serviceUrl) for audience=%s', item.connection, audience)
|
|
123
144
|
return this.getConnection(item.connection)
|
|
124
145
|
}
|
|
125
146
|
|
|
126
147
|
const regex = new RegExp(item.serviceUrl, 'i')
|
|
127
148
|
if (regex.test(serviceUrl)) {
|
|
149
|
+
logger.debug('connection "%s" matched serviceUrl=%s for audience=%s', item.connection, serviceUrl, audience)
|
|
128
150
|
return this.getConnection(item.connection)
|
|
129
151
|
}
|
|
130
152
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { GetTokenOptions, TokenCredential } from '@azure/core-auth'
|
|
2
2
|
import { AuthConfiguration, MsalTokenProvider } from './'
|
|
3
|
+
import { debug } from '@microsoft/agents-telemetry'
|
|
4
|
+
|
|
5
|
+
const logger = debug('agents:msal')
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Token credential implementation that uses MSAL (Microsoft Authentication Library) to acquire access tokens.
|
|
@@ -19,6 +22,7 @@ export class MsalTokenCredential implements TokenCredential {
|
|
|
19
22
|
* @returns Promise that resolves to an access token with expiration timestamp.
|
|
20
23
|
*/
|
|
21
24
|
public async getToken (scopes: string[], options?: GetTokenOptions) {
|
|
25
|
+
logger.debug('getToken scopes=%o', scopes)
|
|
22
26
|
const scope = scopes[0].substring(0, scopes[0].lastIndexOf('/'))
|
|
23
27
|
const token = await new MsalTokenProvider().getAccessToken(this.authConfig, scope)
|
|
24
28
|
return {
|
|
@@ -7,13 +7,14 @@ import { ConfidentialClientApplication, LogLevel, ManagedIdentityApplication, No
|
|
|
7
7
|
import axios from 'axios'
|
|
8
8
|
import { AuthConfiguration, resolveAuthority as resolveAuthorityUtil } from './authConfiguration'
|
|
9
9
|
import { AuthProvider } from './authProvider'
|
|
10
|
-
import { debug } from '@microsoft/agents-
|
|
10
|
+
import { debug, trace } from '@microsoft/agents-telemetry'
|
|
11
11
|
import { v4 } from 'uuid'
|
|
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
|
+
import { AuthenticationTraceDefinitions } from '../observability'
|
|
17
18
|
|
|
18
19
|
const audience = 'api://AzureADTokenExchange'
|
|
19
20
|
const logger = debug('agents:msal')
|
|
@@ -43,121 +44,146 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
43
44
|
* @returns A promise that resolves to the access token.
|
|
44
45
|
*/
|
|
45
46
|
public async getAccessToken (authConfig: AuthConfiguration, scope: string): Promise<string>
|
|
46
|
-
|
|
47
47
|
public async getAccessToken (authConfigOrScope: AuthConfiguration | string, scope?: string): Promise<string> {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
return trace(AuthenticationTraceDefinitions.getAccessToken, async ({ record }) => {
|
|
49
|
+
let authConfig: AuthConfiguration
|
|
50
|
+
let actualScope: string
|
|
51
|
+
|
|
52
|
+
if (typeof authConfigOrScope === 'string') {
|
|
53
|
+
// Called as getAccessToken(scope)
|
|
54
|
+
if (!this.connectionSettings) {
|
|
55
|
+
throw new Error('Connection settings must be provided to constructor when calling getAccessToken(scope)')
|
|
56
|
+
}
|
|
57
|
+
authConfig = this.connectionSettings
|
|
58
|
+
actualScope = authConfigOrScope
|
|
59
|
+
} else {
|
|
60
|
+
// Called as getAccessToken(authConfig, scope)
|
|
61
|
+
authConfig = authConfigOrScope
|
|
62
|
+
actualScope = scope as string
|
|
63
|
+
}
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!
|
|
54
|
-
|
|
65
|
+
record({ scope: actualScope })
|
|
66
|
+
|
|
67
|
+
if (!authConfig.clientId && process.env.NODE_ENV !== 'production') {
|
|
68
|
+
record({ method: 'unknown' })
|
|
69
|
+
return ''
|
|
55
70
|
}
|
|
56
|
-
authConfig = this.connectionSettings
|
|
57
|
-
actualScope = authConfigOrScope
|
|
58
|
-
} else {
|
|
59
|
-
// Called as getAccessToken(authConfig, scope)
|
|
60
|
-
authConfig = authConfigOrScope
|
|
61
|
-
actualScope = scope as string
|
|
62
|
-
}
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
let token
|
|
73
|
+
if (authConfig.WIDAssertionFile !== undefined) {
|
|
74
|
+
record({ method: 'wid' })
|
|
75
|
+
logger.debug('getAccessToken via WID clientId=%s scope=%s', authConfig.clientId, actualScope)
|
|
76
|
+
token = await this.acquireAccessTokenViaWID(authConfig, actualScope)
|
|
77
|
+
} else if (authConfig.FICClientId !== undefined) {
|
|
78
|
+
record({ method: 'fic' })
|
|
79
|
+
logger.debug('getAccessToken via FIC clientId=%s scope=%s', authConfig.clientId, actualScope)
|
|
80
|
+
token = await this.acquireAccessTokenViaFIC(authConfig, actualScope)
|
|
81
|
+
} else if (authConfig.clientSecret !== undefined) {
|
|
82
|
+
record({ method: 'secret' })
|
|
83
|
+
logger.debug('getAccessToken via secret clientId=%s scope=%s', authConfig.clientId, actualScope)
|
|
84
|
+
token = await this.acquireAccessTokenViaSecret(authConfig, actualScope)
|
|
85
|
+
} else if (authConfig.certPemFile !== undefined &&
|
|
86
|
+
authConfig.certKeyFile !== undefined) {
|
|
87
|
+
record({ method: 'certificate' })
|
|
88
|
+
logger.debug('getAccessToken via certificate clientId=%s scope=%s', authConfig.clientId, actualScope)
|
|
89
|
+
token = await this.acquireTokenWithCertificate(authConfig, actualScope)
|
|
90
|
+
} else if (authConfig.clientSecret === undefined &&
|
|
91
|
+
authConfig.certPemFile === undefined &&
|
|
92
|
+
authConfig.certKeyFile === undefined) {
|
|
93
|
+
record({ method: 'managed_identity' })
|
|
94
|
+
logger.debug('getAccessToken via managed identity clientId=%s scope=%s', authConfig.clientId, actualScope)
|
|
95
|
+
token = await this.acquireTokenWithUserAssignedIdentity(authConfig, actualScope)
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error('Invalid authConfig. ')
|
|
98
|
+
}
|
|
99
|
+
if (token === undefined) {
|
|
100
|
+
throw new Error('Failed to acquire token')
|
|
101
|
+
}
|
|
87
102
|
|
|
88
|
-
|
|
103
|
+
return token
|
|
104
|
+
})
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
public async acquireTokenOnBehalfOf (scopes: string[], oboAssertion: string): Promise<string>
|
|
92
108
|
public async acquireTokenOnBehalfOf (authConfig: AuthConfiguration, scopes: string[], oboAssertion: string): Promise<string>
|
|
93
|
-
|
|
94
109
|
public async acquireTokenOnBehalfOf (
|
|
95
110
|
authConfigOrScopes: AuthConfiguration | string[],
|
|
96
111
|
scopesOrOboAssertion?: string[] | string,
|
|
97
112
|
oboAssertion?: string
|
|
98
113
|
): Promise<string> {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
114
|
+
return trace(AuthenticationTraceDefinitions.acquireTokenOnBehalfOf, async ({ record }) => {
|
|
115
|
+
let authConfig: AuthConfiguration
|
|
116
|
+
let actualScopes: string[]
|
|
117
|
+
let actualOboAssertion: string
|
|
118
|
+
|
|
119
|
+
if (Array.isArray(authConfigOrScopes)) {
|
|
120
|
+
// Called as acquireTokenOnBehalfOf(scopes, oboAssertion)
|
|
121
|
+
if (!this.connectionSettings) {
|
|
122
|
+
throw new Error('Connection settings must be provided to constructor when calling acquireTokenOnBehalfOf(scopes, oboAssertion)')
|
|
123
|
+
}
|
|
124
|
+
authConfig = this.connectionSettings
|
|
125
|
+
actualScopes = authConfigOrScopes
|
|
126
|
+
actualOboAssertion = scopesOrOboAssertion as string
|
|
127
|
+
} else {
|
|
128
|
+
// Called as acquireTokenOnBehalfOf(authConfig, scopes, oboAssertion)
|
|
129
|
+
authConfig = authConfigOrScopes
|
|
130
|
+
actualScopes = scopesOrOboAssertion as string[]
|
|
131
|
+
actualOboAssertion = oboAssertion!
|
|
132
|
+
}
|
|
102
133
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
record({ scopes: actualScopes })
|
|
135
|
+
logger.debug('acquireTokenOnBehalfOf clientId=%s scopes=%o', authConfig.clientId, actualScopes)
|
|
136
|
+
|
|
137
|
+
const cca = new ConfidentialClientApplication({
|
|
138
|
+
auth: {
|
|
139
|
+
clientId: authConfig.clientId as string,
|
|
140
|
+
authority: `${authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
141
|
+
clientSecret: authConfig.clientSecret
|
|
142
|
+
},
|
|
143
|
+
system: this.sysOptions
|
|
144
|
+
})
|
|
145
|
+
const token = await cca.acquireTokenOnBehalfOf({
|
|
146
|
+
oboAssertion: actualOboAssertion,
|
|
147
|
+
scopes: actualScopes
|
|
148
|
+
})
|
|
149
|
+
if (!token?.accessToken) {
|
|
150
|
+
throw new Error('Failed to acquire token on behalf of user')
|
|
107
151
|
}
|
|
108
|
-
authConfig = this.connectionSettings
|
|
109
|
-
actualScopes = authConfigOrScopes
|
|
110
|
-
actualOboAssertion = scopesOrOboAssertion as string
|
|
111
|
-
} else {
|
|
112
|
-
// Called as acquireTokenOnBehalfOf(authConfig, scopes, oboAssertion)
|
|
113
|
-
authConfig = authConfigOrScopes
|
|
114
|
-
actualScopes = scopesOrOboAssertion as string[]
|
|
115
|
-
actualOboAssertion = oboAssertion!
|
|
116
|
-
}
|
|
117
152
|
|
|
118
|
-
|
|
119
|
-
auth: {
|
|
120
|
-
clientId: authConfig.clientId as string,
|
|
121
|
-
authority: `${authConfig.authority}/${authConfig.tenantId || 'botframework.com'}`,
|
|
122
|
-
clientSecret: authConfig.clientSecret
|
|
123
|
-
},
|
|
124
|
-
system: this.sysOptions
|
|
125
|
-
})
|
|
126
|
-
const token = await cca.acquireTokenOnBehalfOf({
|
|
127
|
-
oboAssertion: actualOboAssertion,
|
|
128
|
-
scopes: actualScopes
|
|
153
|
+
return token.accessToken
|
|
129
154
|
})
|
|
130
|
-
if (!token?.accessToken) {
|
|
131
|
-
throw new Error('Failed to acquire token on behalf of user')
|
|
132
|
-
}
|
|
133
|
-
return token.accessToken
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
public async getAgenticInstanceToken (tenantId: string, agentAppInstanceId: string): Promise<string> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
const appToken = await this.getAgenticApplicationToken(tenantId, agentAppInstanceId)
|
|
142
|
-
const cca = new ConfidentialClientApplication({
|
|
143
|
-
auth: {
|
|
144
|
-
clientId: agentAppInstanceId,
|
|
145
|
-
clientAssertion: appToken,
|
|
146
|
-
authority: this.resolveAuthority(tenantId),
|
|
147
|
-
},
|
|
148
|
-
system: this.sysOptions
|
|
149
|
-
})
|
|
158
|
+
return trace(AuthenticationTraceDefinitions.getAgenticInstanceToken, async ({ record }) => {
|
|
159
|
+
logger.debug('getAgenticInstanceToken tenantId=%s agentAppInstanceId=%s', tenantId, agentAppInstanceId)
|
|
160
|
+
record({ agenticInstanceId: agentAppInstanceId })
|
|
150
161
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})
|
|
162
|
+
if (!this.connectionSettings) {
|
|
163
|
+
throw new Error('Connection settings must be provided when calling getAgenticInstanceToken')
|
|
164
|
+
}
|
|
155
165
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
166
|
+
const appToken = await this.getAgenticApplicationToken(tenantId, agentAppInstanceId)
|
|
167
|
+
const cca = new ConfidentialClientApplication({
|
|
168
|
+
auth: {
|
|
169
|
+
clientId: agentAppInstanceId,
|
|
170
|
+
clientAssertion: appToken,
|
|
171
|
+
authority: this.resolveAuthority(tenantId),
|
|
172
|
+
},
|
|
173
|
+
system: this.sysOptions
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
const token = await cca.acquireTokenByClientCredential({
|
|
177
|
+
scopes: ['api://AzureAdTokenExchange/.default'],
|
|
178
|
+
correlationId: v4()
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
if (!token?.accessToken) {
|
|
182
|
+
throw new Error(`Failed to acquire instance token for agent instance: ${agentAppInstanceId}`)
|
|
183
|
+
}
|
|
159
184
|
|
|
160
|
-
|
|
185
|
+
return token.accessToken
|
|
186
|
+
})
|
|
161
187
|
}
|
|
162
188
|
|
|
163
189
|
/**
|
|
@@ -205,6 +231,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
205
231
|
throw new Error('Connection settings must be provided when calling getAgenticInstanceToken')
|
|
206
232
|
}
|
|
207
233
|
|
|
234
|
+
logger.debug('acquireTokenForAgenticScenarios clientId=%s tenantId=%s scopes=%o grant_type=%s', clientId, tenantId, scopes, tokenBodyParameters.grant_type)
|
|
208
235
|
// Check cache first
|
|
209
236
|
const cacheKey = `${clientId}/${Object.keys(tokenBodyParameters).map(key => key !== 'user_federated_identity_credential' ? `${key}=${tokenBodyParameters[key]}` : '').join('&')}/${scopes.join(';')}`
|
|
210
237
|
if (this._agenticTokenCache.get(cacheKey)) {
|
|
@@ -249,28 +276,32 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
249
276
|
}
|
|
250
277
|
|
|
251
278
|
public async getAgenticUserToken (tenantId: string, agentAppInstanceId: string, agenticUserId: string, scopes: string[]): Promise<string> {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const token = await this.acquireTokenForAgenticScenarios(tenantId, agentAppInstanceId, agentToken, scopes, {
|
|
257
|
-
user_id: agenticUserId,
|
|
258
|
-
user_federated_identity_credential: instanceToken,
|
|
259
|
-
grant_type: 'user_fic',
|
|
260
|
-
})
|
|
279
|
+
return trace(AuthenticationTraceDefinitions.getAgenticUserToken, async ({ record }) => {
|
|
280
|
+
logger.debug('getAgenticUserToken tenantId=%s agentAppInstanceId=%s scopes=%o', tenantId, agentAppInstanceId, scopes)
|
|
281
|
+
record({ agenticInstanceId: agentAppInstanceId, agenticUserId, scopes })
|
|
261
282
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
283
|
+
const agentToken = await this.getAgenticApplicationToken(tenantId, agentAppInstanceId)
|
|
284
|
+
const instanceToken = await this.getAgenticInstanceToken(tenantId, agentAppInstanceId)
|
|
265
285
|
|
|
266
|
-
|
|
286
|
+
const token = await this.acquireTokenForAgenticScenarios(tenantId, agentAppInstanceId, agentToken, scopes, {
|
|
287
|
+
user_id: agenticUserId,
|
|
288
|
+
user_federated_identity_credential: instanceToken,
|
|
289
|
+
grant_type: 'user_fic',
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
if (!token) {
|
|
293
|
+
throw new Error(`Failed to acquire instance token for user token: ${agentAppInstanceId}`)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return token
|
|
297
|
+
})
|
|
267
298
|
}
|
|
268
299
|
|
|
269
300
|
public async getAgenticApplicationToken (tenantId: string, agentAppInstanceId: string): Promise<string> {
|
|
270
301
|
if (!this.connectionSettings?.clientId) {
|
|
271
302
|
throw new Error('Connection settings must be provided when calling getAgenticApplicationToken')
|
|
272
303
|
}
|
|
273
|
-
logger.debug('
|
|
304
|
+
logger.debug('getAgenticApplicationToken clientId=%s tenantId=%s agentAppInstanceId=%s', this.connectionSettings.clientId, tenantId, agentAppInstanceId)
|
|
274
305
|
|
|
275
306
|
let clientAssertion
|
|
276
307
|
|
|
@@ -496,7 +527,7 @@ export class MsalTokenProvider implements AuthProvider {
|
|
|
496
527
|
system: this.sysOptions
|
|
497
528
|
})
|
|
498
529
|
const token = await cca.acquireTokenByClientCredential({ scopes })
|
|
499
|
-
logger.
|
|
530
|
+
logger.debug('got token using WID client assertion')
|
|
500
531
|
if (!token?.accessToken) {
|
|
501
532
|
throw new Error('Failed to acquire token using WID client assertion')
|
|
502
533
|
}
|
package/src/baseAdapter.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { Middleware, MiddlewareHandler, MiddlewareSet } from './middlewareSet'
|
|
7
7
|
import { TurnContext } from './turnContext'
|
|
8
|
-
import { debug } from '@microsoft/agents-
|
|
8
|
+
import { debug } from '@microsoft/agents-telemetry'
|
|
9
9
|
import { Activity, ConversationReference } from '@microsoft/agents-activity'
|
|
10
10
|
import { ResourceResponse } from './connector-client/resourceResponse'
|
|
11
11
|
import { AttachmentData } from './connector-client/attachmentData'
|