@microsoft/agents-hosting 0.5.12-g2d752e9b13 → 0.5.19-gc1e2ea1096
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/src/app/agentApplication.d.ts +186 -20
- package/dist/src/app/agentApplication.js +234 -32
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +1 -1
- package/dist/src/app/appRoute.d.ts +5 -0
- package/dist/src/app/authorization.d.ts +294 -0
- package/dist/src/app/authorization.js +379 -0
- package/dist/src/app/authorization.js.map +1 -0
- package/dist/src/app/index.d.ts +1 -1
- package/dist/src/app/index.js +1 -1
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/streaming/streamingResponse.js +1 -1
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +2 -2
- package/dist/src/auth/authConfiguration.js +36 -17
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/index.d.ts +1 -0
- package/dist/src/auth/index.js +1 -0
- package/dist/src/auth/index.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalTokenCredential.d.ts +10 -0
- package/dist/src/auth/msalTokenCredential.js +19 -0
- package/dist/src/auth/msalTokenCredential.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +1 -0
- package/dist/src/auth/msalTokenProvider.js +15 -0
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.d.ts +1 -1
- package/dist/src/baseAdapter.js +0 -4
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +1 -0
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/oauth/oAuthFlow.d.ts +53 -9
- package/dist/src/oauth/oAuthFlow.js +164 -35
- package/dist/src/oauth/oAuthFlow.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +4 -0
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/package.json +4 -3
- package/src/app/agentApplication.ts +247 -32
- package/src/app/agentApplicationBuilder.ts +1 -1
- package/src/app/agentApplicationOptions.ts +1 -1
- package/src/app/appRoute.ts +6 -0
- package/src/app/authorization.ts +424 -0
- package/src/app/index.ts +1 -1
- package/src/app/streaming/streamingResponse.ts +1 -1
- package/src/auth/authConfiguration.ts +36 -19
- package/src/auth/index.ts +1 -0
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalTokenCredential.ts +14 -0
- package/src/auth/msalTokenProvider.ts +17 -1
- package/src/baseAdapter.ts +1 -1
- package/src/cloudAdapter.ts +2 -2
- package/src/oauth/oAuthFlow.ts +197 -35
- package/src/oauth/userTokenClient.ts +3 -0
- package/dist/src/app/oauth/authorization.d.ts +0 -88
- package/dist/src/app/oauth/authorization.js +0 -134
- package/dist/src/app/oauth/authorization.js.map +0 -1
- package/src/app/oauth/authorization.ts +0 -160
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { TurnContext } from '../../turnContext'
|
|
7
|
-
import { debug } from '../../logger'
|
|
8
|
-
import { TurnState } from '../turnState'
|
|
9
|
-
import { Storage } from '../../storage'
|
|
10
|
-
import { OAuthFlow, TokenResponse } from '../../oauth'
|
|
11
|
-
|
|
12
|
-
const logger = debug('agents:authorization')
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Interface defining an authorization handler for OAuth flows
|
|
16
|
-
* @interface AuthHandler
|
|
17
|
-
*/
|
|
18
|
-
export interface AuthHandler {
|
|
19
|
-
/** Connection name for the auth provider */
|
|
20
|
-
name?: string,
|
|
21
|
-
/** Whether authorization should be triggered automatically */
|
|
22
|
-
auto?: boolean,
|
|
23
|
-
/** The OAuth flow implementation */
|
|
24
|
-
flow?: OAuthFlow,
|
|
25
|
-
/** Title to display on auth cards/UI */
|
|
26
|
-
title?: string,
|
|
27
|
-
/** Text to display on auth cards/UI */
|
|
28
|
-
text?: string,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Options for configuring user authorization.
|
|
33
|
-
* Contains settings to configure OAuth connections.
|
|
34
|
-
*/
|
|
35
|
-
export interface AuthorizationHandlers extends Record<string, AuthHandler> {}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Class responsible for managing authorization and OAuth flows
|
|
39
|
-
* @class Authorization
|
|
40
|
-
*/
|
|
41
|
-
export class Authorization {
|
|
42
|
-
_authHandlers: AuthorizationHandlers
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Creates a new instance of UserAuthorization.
|
|
46
|
-
* @param {Storage} storage - The storage system to use for state management.
|
|
47
|
-
* @param {AuthorizationHandlers} authHandlers - Configuration for OAuth providers
|
|
48
|
-
* @throws {Error} If storage is null/undefined or no auth handlers are provided
|
|
49
|
-
*/
|
|
50
|
-
constructor (private storage: Storage, authHandlers: AuthorizationHandlers) {
|
|
51
|
-
if (storage === undefined || storage === null) {
|
|
52
|
-
throw new Error('Storage is required for UserAuthorization')
|
|
53
|
-
}
|
|
54
|
-
if (authHandlers === undefined || Object.keys(authHandlers).length === 0) {
|
|
55
|
-
throw new Error('The authorization does not have any auth handlers')
|
|
56
|
-
}
|
|
57
|
-
this._authHandlers = authHandlers
|
|
58
|
-
for (const ah in this._authHandlers) {
|
|
59
|
-
if (this._authHandlers![ah].name === undefined && process.env[ah + '_connectionName'] === undefined) {
|
|
60
|
-
throw new Error(`AuthHandler name ${ah}_connectionName not set in autorization and not found in env vars.`)
|
|
61
|
-
}
|
|
62
|
-
const currentAuthHandler = this._authHandlers![ah]
|
|
63
|
-
currentAuthHandler.name = currentAuthHandler.name ?? process.env[ah + '_connectionName'] as string
|
|
64
|
-
currentAuthHandler.title = currentAuthHandler.title ?? process.env[ah + '_connectionTitle'] as string
|
|
65
|
-
currentAuthHandler.text = currentAuthHandler.text ?? process.env[ah + '_connectionText'] as string
|
|
66
|
-
currentAuthHandler.auto = currentAuthHandler.auto ?? process.env[ah + '_connectionAuto'] === 'true'
|
|
67
|
-
currentAuthHandler.flow = new OAuthFlow(this.storage, currentAuthHandler.name, null!, currentAuthHandler.title, currentAuthHandler.text)
|
|
68
|
-
}
|
|
69
|
-
logger.info('Authorization handlers configured with', this._authHandlers.length, 'handlers')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Gets the token for a specific auth handler
|
|
74
|
-
* @param {TurnContext} context - The context object for the current turn
|
|
75
|
-
* @param {string} [authHandlerId] - Optional ID of the auth handler to use, defaults to first handler
|
|
76
|
-
* @returns {Promise<TokenResponse>} The token response from the OAuth provider
|
|
77
|
-
*/
|
|
78
|
-
public async getToken (context: TurnContext, authHandlerId?: string): Promise<TokenResponse> {
|
|
79
|
-
logger.info('getToken from user token service for authHandlerId:', authHandlerId)
|
|
80
|
-
const authHandler = this.resolverHandler(authHandlerId)
|
|
81
|
-
return await authHandler.flow?.getUserToken(context)!
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Begins or continues an OAuth flow
|
|
86
|
-
* @param {TurnContext} context - The context object for the current turn
|
|
87
|
-
* @param {TurnState} state - The state object for the current turn
|
|
88
|
-
* @param {string} [authHandlerId] - Optional ID of the auth handler to use, defaults to first handler
|
|
89
|
-
* @returns {Promise<TokenResponse>} The token response from the OAuth provider
|
|
90
|
-
*/
|
|
91
|
-
public async beginOrContinueFlow (context: TurnContext, state: TurnState, authHandlerId?: string) : Promise<TokenResponse> {
|
|
92
|
-
logger.info('beginOrContinueFlow for authHandlerId:', authHandlerId)
|
|
93
|
-
const flow = this.resolverHandler(authHandlerId).flow!
|
|
94
|
-
let tokenResponse: TokenResponse | undefined
|
|
95
|
-
if (flow.state!.flowStarted === false) {
|
|
96
|
-
tokenResponse = await flow.beginFlow(context)
|
|
97
|
-
} else {
|
|
98
|
-
tokenResponse = await flow.continueFlow(context)
|
|
99
|
-
if (tokenResponse && tokenResponse.token) {
|
|
100
|
-
if (this._signInHandler) {
|
|
101
|
-
await this._signInHandler(context, state, authHandlerId)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return tokenResponse!
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Gets the current state of the OAuth flow
|
|
110
|
-
* @param {string} [authHandlerId] - Optional ID of the auth handler to check, defaults to first handler
|
|
111
|
-
* @returns {boolean} Whether the flow has started
|
|
112
|
-
*/
|
|
113
|
-
public getFlowState (authHandlerId?: string) : boolean {
|
|
114
|
-
const flow = this.resolverHandler(authHandlerId).flow!
|
|
115
|
-
return flow.state?.flowStarted!
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Resolves the auth handler to use based on the provided ID
|
|
120
|
-
* @param {string} [authHandlerId] - Optional ID of the auth handler to resolve, defaults to first handler
|
|
121
|
-
* @returns {AuthHandler} The resolved auth handler
|
|
122
|
-
*/
|
|
123
|
-
resolverHandler = (authHandlerId?: string) : AuthHandler => {
|
|
124
|
-
if (authHandlerId) {
|
|
125
|
-
return this._authHandlers![authHandlerId]
|
|
126
|
-
}
|
|
127
|
-
return this._authHandlers![Object.keys(this._authHandlers)[0]]
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Signs out the current user.
|
|
132
|
-
* This method clears the user's token and resets the SSO state.
|
|
133
|
-
*
|
|
134
|
-
* @param {TurnContext} context - The context object for the current turn.
|
|
135
|
-
* @param {TurnState} state - The state object for the current turn.
|
|
136
|
-
* @param {string} [authHandlerId] - Optional ID of the auth handler to use for sign out
|
|
137
|
-
* @returns {Promise<void>}
|
|
138
|
-
*/
|
|
139
|
-
async signOut (context: TurnContext, state: TurnState, authHandlerId?: string) : Promise<void> {
|
|
140
|
-
logger.info('signOut for authHandlerId:', authHandlerId)
|
|
141
|
-
if (authHandlerId === undefined) { // aw
|
|
142
|
-
for (const ah in this._authHandlers) {
|
|
143
|
-
const flow = this._authHandlers[ah].flow
|
|
144
|
-
await flow?.signOut(context)
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
await this.resolverHandler(authHandlerId).flow?.signOut(context)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
_signInHandler: ((context: TurnContext, state: TurnState, authHandlerId?: string) => void) | null = null
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Sets a handler to be called when sign-in is successfully completed
|
|
155
|
-
* @param {Function} handler - The handler function to call on successful sign-in
|
|
156
|
-
*/
|
|
157
|
-
public onSignInSuccess (handler: (context: TurnContext, state: TurnState, authHandlerId?: string) => void) {
|
|
158
|
-
this._signInHandler = handler
|
|
159
|
-
}
|
|
160
|
-
}
|