@microsoft/agents-hosting 0.6.16-gc874f0c9d8 → 0.6.18
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 +47 -0
- package/dist/src/app/agentApplication.js +7 -3
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/authorization.d.ts +2 -2
- package/dist/src/app/authorization.js +2 -2
- package/dist/src/app/authorization.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +3 -3
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.js +3 -3
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.d.ts +5 -0
- package/dist/src/baseAdapter.js +4 -0
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +2 -1
- package/dist/src/cloudAdapter.js +6 -8
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/oauth/oAuthFlow.d.ts +2 -2
- package/dist/src/oauth/oAuthFlow.js +20 -12
- package/dist/src/oauth/oAuthFlow.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +3 -2
- package/dist/src/oauth/userTokenClient.js +54 -48
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/storage/memoryStorage.js +3 -3
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/package.json +5 -3
- package/src/app/agentApplication.ts +5 -2
- package/src/app/authorization.ts +3 -3
- package/src/auth/jwt-middleware.ts +3 -3
- package/src/auth/msalTokenProvider.ts +3 -3
- package/src/baseAdapter.ts +6 -0
- package/src/cloudAdapter.ts +6 -10
- package/src/oauth/oAuthFlow.ts +18 -12
- package/src/oauth/userTokenClient.ts +55 -43
- package/src/storage/memoryStorage.ts +3 -3
|
@@ -15,14 +15,12 @@ const logger = debug('agents:user-token-client')
|
|
|
15
15
|
*/
|
|
16
16
|
export class UserTokenClient {
|
|
17
17
|
client: AxiosInstance
|
|
18
|
-
msAppId: string
|
|
19
18
|
/**
|
|
20
19
|
* Creates a new instance of UserTokenClient.
|
|
21
20
|
* @param token The token to use for authentication.
|
|
22
21
|
* @param msAppId The Microsoft application ID.
|
|
23
22
|
*/
|
|
24
|
-
constructor (
|
|
25
|
-
this.msAppId = appId
|
|
23
|
+
constructor (private msAppId: string) {
|
|
26
24
|
const baseURL = 'https://api.botframework.com'
|
|
27
25
|
const axiosInstance = axios.create({
|
|
28
26
|
baseURL,
|
|
@@ -31,7 +29,35 @@ export class UserTokenClient {
|
|
|
31
29
|
'User-Agent': getProductInfo(),
|
|
32
30
|
}
|
|
33
31
|
})
|
|
34
|
-
axiosInstance.defaults.headers.common.Authorization = `Bearer ${token}`
|
|
32
|
+
// axiosInstance.defaults.headers.common.Authorization = `Bearer ${token}`
|
|
33
|
+
axiosInstance.interceptors.response.use(
|
|
34
|
+
(config) => {
|
|
35
|
+
const { status, statusText, config: requestConfig } = config
|
|
36
|
+
logger.debug('Response: ', {
|
|
37
|
+
status,
|
|
38
|
+
statusText,
|
|
39
|
+
host: axiosInstance.getUri(),
|
|
40
|
+
url: requestConfig?.url,
|
|
41
|
+
data: config.config.data,
|
|
42
|
+
method: requestConfig?.method,
|
|
43
|
+
})
|
|
44
|
+
return config
|
|
45
|
+
},
|
|
46
|
+
(error) => {
|
|
47
|
+
const { code, status, message, stack, response } = error
|
|
48
|
+
if (status !== 404) {
|
|
49
|
+
const errorDetails = {
|
|
50
|
+
code,
|
|
51
|
+
host: axiosInstance.getUri(),
|
|
52
|
+
url: error.config.url,
|
|
53
|
+
method: error.config.method,
|
|
54
|
+
data: error.config.data,
|
|
55
|
+
message: message + JSON.stringify(response?.data),
|
|
56
|
+
stack,
|
|
57
|
+
}
|
|
58
|
+
return Promise.reject(errorDetails)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
35
61
|
this.client = axiosInstance
|
|
36
62
|
}
|
|
37
63
|
|
|
@@ -44,16 +70,12 @@ export class UserTokenClient {
|
|
|
44
70
|
* @returns A promise that resolves to the user token.
|
|
45
71
|
*/
|
|
46
72
|
async getUserToken (connectionName: string, channelId: string, userId: string, code?: string) : Promise<TokenResponse> {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
const params = { connectionName, channelId, userId, code }
|
|
74
|
+
const response = await this.client.get('/api/usertoken/GetToken', { params })
|
|
75
|
+
if (response?.data) {
|
|
50
76
|
return response.data as TokenResponse
|
|
51
|
-
} catch (error: any) {
|
|
52
|
-
if (error.response?.status !== 404) {
|
|
53
|
-
logger.error(error)
|
|
54
|
-
}
|
|
55
|
-
return { token: undefined }
|
|
56
77
|
}
|
|
78
|
+
return { token: undefined }
|
|
57
79
|
}
|
|
58
80
|
|
|
59
81
|
/**
|
|
@@ -64,14 +86,9 @@ export class UserTokenClient {
|
|
|
64
86
|
* @returns A promise that resolves when the sign-out operation is complete.
|
|
65
87
|
*/
|
|
66
88
|
async signOut (userId: string, connectionName: string, channelId: string) : Promise<void> {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (response.status !== 200) {
|
|
71
|
-
throw new Error('Failed to sign out')
|
|
72
|
-
}
|
|
73
|
-
} catch (error: any) {
|
|
74
|
-
logger.error(error)
|
|
89
|
+
const params = { userId, connectionName, channelId }
|
|
90
|
+
const response = await this.client.delete('/api/usertoken/SignOut', { params })
|
|
91
|
+
if (response.status !== 200) {
|
|
75
92
|
throw new Error('Failed to sign out')
|
|
76
93
|
}
|
|
77
94
|
}
|
|
@@ -84,22 +101,17 @@ export class UserTokenClient {
|
|
|
84
101
|
* @returns A promise that resolves to the signing resource.
|
|
85
102
|
*/
|
|
86
103
|
async getSignInResource (msAppId: string, connectionName: string, conversation: ConversationReference, relatesTo?: ConversationReference) : Promise<SignInResource> {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
msAppId
|
|
93
|
-
}
|
|
94
|
-
const tokenExchangeStateNormalized = normalizeTokenExchangeState(tokenExchangeState)
|
|
95
|
-
const state = Buffer.from(JSON.stringify(tokenExchangeStateNormalized)).toString('base64')
|
|
96
|
-
const params = { state }
|
|
97
|
-
const response = await this.client.get('/api/botsignin/GetSignInResource', { params })
|
|
98
|
-
return response.data as SignInResource
|
|
99
|
-
} catch (error: any) {
|
|
100
|
-
logger.error(error)
|
|
101
|
-
throw error
|
|
104
|
+
const tokenExchangeState = {
|
|
105
|
+
connectionName,
|
|
106
|
+
conversation,
|
|
107
|
+
relatesTo,
|
|
108
|
+
msAppId
|
|
102
109
|
}
|
|
110
|
+
const tokenExchangeStateNormalized = normalizeTokenExchangeState(tokenExchangeState)
|
|
111
|
+
const state = Buffer.from(JSON.stringify(tokenExchangeStateNormalized)).toString('base64')
|
|
112
|
+
const params = { state }
|
|
113
|
+
const response = await this.client.get('/api/botsignin/GetSignInResource', { params })
|
|
114
|
+
return response.data as SignInResource
|
|
103
115
|
}
|
|
104
116
|
|
|
105
117
|
/**
|
|
@@ -111,15 +123,11 @@ export class UserTokenClient {
|
|
|
111
123
|
* @returns A promise that resolves to the exchanged token.
|
|
112
124
|
*/
|
|
113
125
|
async exchangeTokenAsync (userId: string, connectionName: string, channelId: string, tokenExchangeRequest: TokenExchangeRequest) : Promise<TokenResponse> {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
const params = { userId, connectionName, channelId }
|
|
127
|
+
const response = await this.client.post('/api/usertoken/exchange', tokenExchangeRequest, { params })
|
|
128
|
+
if (response?.data) {
|
|
117
129
|
return response.data as TokenResponse
|
|
118
|
-
}
|
|
119
|
-
logger.error(error)
|
|
120
|
-
if (error.response?.data) {
|
|
121
|
-
logger.error(error.response.data)
|
|
122
|
-
}
|
|
130
|
+
} else {
|
|
123
131
|
return { token: undefined }
|
|
124
132
|
}
|
|
125
133
|
}
|
|
@@ -169,4 +177,8 @@ export class UserTokenClient {
|
|
|
169
177
|
const response = await this.client.post('/api/usertoken/GetAadTokens', resourceUrls, { params })
|
|
170
178
|
return response.data as Record<string, TokenResponse>
|
|
171
179
|
}
|
|
180
|
+
|
|
181
|
+
public updateAuthToken (token: string): void {
|
|
182
|
+
this.client.defaults.headers.common.Authorization = `Bearer ${token}`
|
|
183
|
+
}
|
|
172
184
|
}
|
|
@@ -65,7 +65,7 @@ export class MemoryStorage implements Storage {
|
|
|
65
65
|
|
|
66
66
|
const data: StoreItem = {}
|
|
67
67
|
for (const key of keys) {
|
|
68
|
-
logger.
|
|
68
|
+
logger.debug(`Reading key: ${key}`)
|
|
69
69
|
const item = this.memory[key]
|
|
70
70
|
if (item) {
|
|
71
71
|
data[key] = JSON.parse(item)
|
|
@@ -93,7 +93,7 @@ export class MemoryStorage implements Storage {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
for (const [key, newItem] of Object.entries(changes)) {
|
|
96
|
-
logger.
|
|
96
|
+
logger.debug(`Writing key: ${key}`)
|
|
97
97
|
const oldItemStr = this.memory[key]
|
|
98
98
|
if (!oldItemStr || newItem.eTag === '*' || !newItem.eTag) {
|
|
99
99
|
this.saveItem(key, newItem)
|
|
@@ -115,7 +115,7 @@ export class MemoryStorage implements Storage {
|
|
|
115
115
|
* @returns A promise that resolves when the delete operation is complete
|
|
116
116
|
*/
|
|
117
117
|
async delete (keys: string[]): Promise<void> {
|
|
118
|
-
logger.
|
|
118
|
+
logger.debug(`Deleting keys: ${keys.join(', ')}`)
|
|
119
119
|
for (const key of keys) {
|
|
120
120
|
delete this.memory[key]
|
|
121
121
|
}
|