@microsoft/agents-hosting 1.1.0-alpha.2 → 1.1.0-alpha.58
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 -6
- package/dist/src/activityWireCompat.js +8 -3
- package/dist/src/activityWireCompat.js.map +1 -1
- package/dist/src/agent-client/agentClient.js +7 -3
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.js +6 -2
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +26 -11
- package/dist/src/app/agentApplication.js +94 -86
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +2 -2
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +9 -2
- package/dist/src/app/appRoute.d.ts +7 -0
- package/dist/src/app/attachmentDownloader.d.ts +13 -3
- package/dist/src/app/attachmentDownloader.js +16 -3
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/{authorization.d.ts → auth/authorization.d.ts} +33 -139
- package/dist/src/app/auth/authorization.js +188 -0
- package/dist/src/app/auth/authorization.js.map +1 -0
- package/dist/src/app/auth/authorizationManager.d.ts +71 -0
- package/dist/src/app/auth/authorizationManager.js +170 -0
- package/dist/src/app/auth/authorizationManager.js.map +1 -0
- package/dist/src/app/auth/handlerStorage.d.ts +36 -0
- package/dist/src/app/auth/handlerStorage.js +62 -0
- package/dist/src/app/auth/handlerStorage.js.map +1 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.d.ts +97 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.js +145 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +222 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +428 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -0
- package/dist/src/app/auth/handlers/index.d.ts +2 -0
- package/dist/src/app/auth/handlers/index.js +19 -0
- package/dist/src/app/auth/handlers/index.js.map +1 -0
- package/dist/src/app/auth/index.d.ts +2 -0
- package/dist/src/app/auth/index.js +19 -0
- package/dist/src/app/auth/index.js.map +1 -0
- package/dist/src/app/auth/types.d.ts +104 -0
- package/dist/src/app/auth/types.js +24 -0
- package/dist/src/app/auth/types.js.map +1 -0
- package/dist/src/app/index.d.ts +2 -3
- package/dist/src/app/index.js +2 -3
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/inputFileDownloader.d.ts +10 -3
- package/dist/src/app/routeList.d.ts +1 -1
- package/dist/src/app/routeList.js +22 -5
- package/dist/src/app/routeList.js.map +1 -1
- package/dist/src/app/streaming/streamingResponse.d.ts +11 -1
- package/dist/src/app/streaming/streamingResponse.js +17 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/turnState.d.ts +2 -38
- package/dist/src/app/turnState.js +1 -46
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/MemoryCache.d.ts +16 -0
- package/dist/src/auth/MemoryCache.js +58 -0
- package/dist/src/auth/MemoryCache.js.map +1 -0
- package/dist/src/auth/authConfiguration.d.ts +44 -2
- package/dist/src/auth/authConfiguration.js +218 -53
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/authConstants.d.ts +11 -0
- package/dist/src/auth/authConstants.js +15 -0
- package/dist/src/auth/authConstants.js.map +1 -0
- package/dist/src/auth/authProvider.d.ts +23 -0
- package/dist/src/auth/connections.d.ts +40 -0
- package/dist/src/auth/connections.js +7 -0
- package/dist/src/auth/connections.js.map +1 -0
- package/dist/src/auth/index.d.ts +2 -0
- package/dist/src/auth/index.js +2 -0
- package/dist/src/auth/index.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +31 -18
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.d.ts +63 -0
- package/dist/src/auth/msalConnectionManager.js +124 -0
- package/dist/src/auth/msalConnectionManager.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +31 -0
- package/dist/src/auth/msalTokenProvider.js +167 -16
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.d.ts +10 -25
- package/dist/src/baseAdapter.js +2 -15
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +40 -23
- package/dist/src/cloudAdapter.js +132 -56
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +9 -0
- package/dist/src/connector-client/connectorClient.js +39 -9
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/index.d.ts +0 -1
- package/dist/src/oauth/index.js +0 -1
- package/dist/src/oauth/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +30 -13
- package/dist/src/oauth/userTokenClient.js +64 -26
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/oauth/userTokenClient.types.d.ts +19 -6
- package/dist/src/turnContext.d.ts +7 -1
- package/dist/src/turnContext.js +11 -4
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +10 -6
- package/src/activityWireCompat.ts +8 -3
- package/src/agent-client/agentClient.ts +9 -3
- package/src/agent-client/agentResponseHandler.ts +5 -2
- package/src/app/agentApplication.ts +98 -79
- package/src/app/agentApplicationBuilder.ts +2 -2
- package/src/app/agentApplicationOptions.ts +10 -2
- package/src/app/appRoute.ts +8 -0
- package/src/app/attachmentDownloader.ts +18 -3
- package/src/app/auth/authorization.ts +252 -0
- package/src/app/auth/authorizationManager.ts +213 -0
- package/src/app/auth/handlerStorage.ts +61 -0
- package/src/app/auth/handlers/agenticAuthorization.ts +194 -0
- package/src/app/auth/handlers/azureBotAuthorization.ts +599 -0
- package/src/app/auth/handlers/index.ts +2 -0
- package/src/app/auth/index.ts +2 -0
- package/src/app/auth/types.ts +111 -0
- package/src/app/index.ts +2 -3
- package/src/app/inputFileDownloader.ts +11 -3
- package/src/app/routeList.ts +24 -5
- package/src/app/streaming/streamingResponse.ts +20 -3
- package/src/app/turnState.ts +2 -61
- package/src/auth/MemoryCache.ts +59 -0
- package/src/auth/authConfiguration.ts +258 -52
- package/src/auth/authConstants.ts +11 -0
- package/src/auth/authProvider.ts +31 -0
- package/src/auth/connections.ts +46 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/jwt-middleware.ts +38 -21
- package/src/auth/msalConnectionManager.ts +150 -0
- package/src/auth/msalTokenProvider.ts +209 -9
- package/src/baseAdapter.ts +10 -29
- package/src/cloudAdapter.ts +192 -67
- package/src/connector-client/connectorClient.ts +49 -10
- package/src/index.ts +0 -1
- package/src/oauth/index.ts +0 -1
- package/src/oauth/userTokenClient.ts +79 -23
- package/src/oauth/userTokenClient.types.ts +20 -8
- package/src/turnContext.ts +16 -5
- package/dist/src/app/authorization.js +0 -387
- package/dist/src/app/authorization.js.map +0 -1
- package/dist/src/claimsIdentity.d.ts +0 -35
- package/dist/src/claimsIdentity.js +0 -43
- package/dist/src/claimsIdentity.js.map +0 -1
- package/dist/src/oauth/oAuthFlow.d.ts +0 -119
- package/dist/src/oauth/oAuthFlow.js +0 -316
- package/dist/src/oauth/oAuthFlow.js.map +0 -1
- package/src/app/authorization.ts +0 -432
- package/src/claimsIdentity.ts +0 -47
- package/src/oauth/oAuthFlow.ts +0 -378
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.AuthorizationManager = void 0;
|
|
8
|
+
const agents_activity_1 = require("@microsoft/agents-activity");
|
|
9
|
+
const handlers_1 = require("./handlers");
|
|
10
|
+
const handlerStorage_1 = require("./handlerStorage");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const logger = (0, agents_activity_1.debug)('agents:authorization:manager');
|
|
13
|
+
/**
|
|
14
|
+
* Manages multiple authorization handlers and their interactions.
|
|
15
|
+
* Processes authorization requests and maintains handler states.
|
|
16
|
+
* @remarks
|
|
17
|
+
* This class is responsible for coordinating the authorization process
|
|
18
|
+
* across multiple handlers, ensuring that each handler is invoked in
|
|
19
|
+
* the correct order and with the appropriate context.
|
|
20
|
+
*/
|
|
21
|
+
class AuthorizationManager {
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of the AuthorizationManager.
|
|
24
|
+
* @param app The agent application instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor(app, connections) {
|
|
27
|
+
this.app = app;
|
|
28
|
+
this._handlers = {};
|
|
29
|
+
if (!app.options.storage) {
|
|
30
|
+
throw new Error('Storage is required for Authorization. Ensure that a storage provider is configured in the AgentApplication options.');
|
|
31
|
+
}
|
|
32
|
+
if (app.options.authorization === undefined || Object.keys(app.options.authorization).length === 0) {
|
|
33
|
+
throw new Error('The AgentApplication.authorization does not have any auth handlers');
|
|
34
|
+
}
|
|
35
|
+
const settings = { storage: app.options.storage, connections };
|
|
36
|
+
for (const [id, handler] of Object.entries(app.options.authorization)) {
|
|
37
|
+
const options = this.loadOptions(id, handler);
|
|
38
|
+
if (options.type === 'agentic') {
|
|
39
|
+
this._handlers[id] = new handlers_1.AgenticAuthorization(id, options, settings);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this._handlers[id] = new handlers_1.AzureBotAuthorization(id, options, settings);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Loads and validates the authorization handler options.
|
|
48
|
+
*/
|
|
49
|
+
loadOptions(id, options) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const result = {
|
|
52
|
+
...options,
|
|
53
|
+
type: (_b = ((_a = options.type) !== null && _a !== void 0 ? _a : process.env[`${id}_type`])) === null || _b === void 0 ? void 0 : _b.toLowerCase(),
|
|
54
|
+
};
|
|
55
|
+
// Validate supported types, agentic, and default (Azure Bot - undefined)
|
|
56
|
+
const supportedTypes = ['agentic', undefined];
|
|
57
|
+
if (!supportedTypes.includes(result.type)) {
|
|
58
|
+
throw new Error(`Unsupported authorization handler type: '${result.type}' for auth handler: '${id}'. Supported types are: '${supportedTypes.filter(Boolean).join('\', \'')}'.`);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the registered authorization handlers.
|
|
64
|
+
* @returns A record of authorization handlers by their IDs.
|
|
65
|
+
*/
|
|
66
|
+
get handlers() {
|
|
67
|
+
return this._handlers;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Processes an authorization request.
|
|
71
|
+
* @param context The turn context.
|
|
72
|
+
* @param getHandlerIds A function to retrieve the handler IDs for the current activity.
|
|
73
|
+
* @returns The result of the authorization process.
|
|
74
|
+
*/
|
|
75
|
+
async process(context, getHandlerIds) {
|
|
76
|
+
var _a, _b, _c;
|
|
77
|
+
const storage = new handlerStorage_1.HandlerStorage(this.app.options.storage, context);
|
|
78
|
+
let active = await this.active(storage, getHandlerIds);
|
|
79
|
+
const handlers = (_c = (_a = active === null || active === void 0 ? void 0 : active.handlers) !== null && _a !== void 0 ? _a : this.mapHandlers((_b = await getHandlerIds(context.activity)) !== null && _b !== void 0 ? _b : [])) !== null && _c !== void 0 ? _c : [];
|
|
80
|
+
for (const handler of handlers) {
|
|
81
|
+
const status = await this.signin(storage, handler, context, active === null || active === void 0 ? void 0 : active.data);
|
|
82
|
+
logger.debug(this.prefix(handler.id, `Sign-in status: ${status}`));
|
|
83
|
+
if (status === types_1.AuthorizationHandlerStatus.IGNORED) {
|
|
84
|
+
await storage.delete();
|
|
85
|
+
return { authorized: true };
|
|
86
|
+
}
|
|
87
|
+
if (status === types_1.AuthorizationHandlerStatus.PENDING) {
|
|
88
|
+
return { authorized: false };
|
|
89
|
+
}
|
|
90
|
+
if (status === types_1.AuthorizationHandlerStatus.REJECTED) {
|
|
91
|
+
await storage.delete();
|
|
92
|
+
return { authorized: false };
|
|
93
|
+
}
|
|
94
|
+
if (status === types_1.AuthorizationHandlerStatus.REVALIDATE) {
|
|
95
|
+
await storage.delete();
|
|
96
|
+
return this.process(context, getHandlerIds);
|
|
97
|
+
}
|
|
98
|
+
if (status !== types_1.AuthorizationHandlerStatus.APPROVED) {
|
|
99
|
+
throw new Error(this.prefix(handler.id, `Unexpected registration status: ${status}`));
|
|
100
|
+
}
|
|
101
|
+
await storage.delete();
|
|
102
|
+
if (active) {
|
|
103
|
+
// Restore the original activity in the turn context for the next handler to process.
|
|
104
|
+
// This is done like this to avoid losing data that may be set in the turn context.
|
|
105
|
+
context._activity = agents_activity_1.Activity.fromObject(active.data.activity);
|
|
106
|
+
active = undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { authorized: true };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the active handler session from storage.
|
|
113
|
+
*/
|
|
114
|
+
async active(storage, getHandlerIds) {
|
|
115
|
+
var _a;
|
|
116
|
+
const data = await storage.read();
|
|
117
|
+
if (!data) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const handlerIds = await getHandlerIds(agents_activity_1.Activity.fromObject(data.activity));
|
|
121
|
+
let handlers = this.mapHandlers(handlerIds !== null && handlerIds !== void 0 ? handlerIds : []);
|
|
122
|
+
// Sort handlers to ensure the active handler is processed first, to ensure continuity.
|
|
123
|
+
handlers = (_a = handlers.sort((a, b) => {
|
|
124
|
+
if (a.id === data.id) {
|
|
125
|
+
return -1;
|
|
126
|
+
}
|
|
127
|
+
if (b.id === data.id) {
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
return 0;
|
|
131
|
+
})) !== null && _a !== void 0 ? _a : [];
|
|
132
|
+
return { data, handlers };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Attempts to sign in using the specified handler and options.
|
|
136
|
+
*/
|
|
137
|
+
async signin(storage, handler, context, active) {
|
|
138
|
+
try {
|
|
139
|
+
return await handler.signin(context, active);
|
|
140
|
+
}
|
|
141
|
+
catch (cause) {
|
|
142
|
+
await storage.delete();
|
|
143
|
+
throw new Error(this.prefix(handler.id, 'Failed to sign in'), { cause });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Maps an array of handler IDs to their corresponding handler instances.
|
|
148
|
+
*/
|
|
149
|
+
mapHandlers(ids) {
|
|
150
|
+
let unknownHandlers = '';
|
|
151
|
+
const handlers = ids.map(id => {
|
|
152
|
+
if (!this._handlers[id]) {
|
|
153
|
+
unknownHandlers += ` ${id}`;
|
|
154
|
+
}
|
|
155
|
+
return this._handlers[id];
|
|
156
|
+
});
|
|
157
|
+
if (unknownHandlers) {
|
|
158
|
+
throw new Error(`Cannot find auth handlers with ID(s): ${unknownHandlers}`);
|
|
159
|
+
}
|
|
160
|
+
return handlers;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Prefixes a message with the handler ID.
|
|
164
|
+
*/
|
|
165
|
+
prefix(id, message) {
|
|
166
|
+
return `[handler:${id}] ${message}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.AuthorizationManager = AuthorizationManager;
|
|
170
|
+
//# sourceMappingURL=authorizationManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorizationManager.js","sourceRoot":"","sources":["../../../../src/app/auth/authorizationManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,gEAA4D;AAE5D,yCAAwE;AAExE,qDAAiD;AACjD,mCAA0J;AAG1J,MAAM,MAAM,GAAG,IAAA,uBAAK,EAAC,8BAA8B,CAAC,CAAA;AAyBpD;;;;;;;GAOG;AACH,MAAa,oBAAo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;OAEG;IACK,WAAW,CAAE,GAAa;QAChC,IAAI,eAAe,GAAG,EAAE,CAAA;QACxB,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACxB,eAAe,IAAI,IAAI,EAAE,EAAE,CAAA;YAC7B,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;QACF,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yCAAyC,eAAe,EAAE,CAAC,CAAA;QAC7E,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;OAEG;IACK,MAAM,CAAE,EAAU,EAAE,OAAe;QACzC,OAAO,YAAY,EAAE,KAAK,OAAO,EAAE,CAAA;IACrC,CAAC;CACF;AAtKD,oDAsKC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ActiveAuthorizationHandler } from './types';
|
|
6
|
+
import { TurnContext } from '../../turnContext';
|
|
7
|
+
import { Storage } from '../../storage';
|
|
8
|
+
/**
|
|
9
|
+
* Storage manager for handler state.
|
|
10
|
+
*/
|
|
11
|
+
export declare class HandlerStorage<TActiveHandler extends ActiveAuthorizationHandler = ActiveAuthorizationHandler> {
|
|
12
|
+
private storage;
|
|
13
|
+
private context;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of the HandlerStorage.
|
|
16
|
+
* @param storage The storage provider.
|
|
17
|
+
* @param context The turn context.
|
|
18
|
+
*/
|
|
19
|
+
constructor(storage: Storage, context: TurnContext);
|
|
20
|
+
/**
|
|
21
|
+
* Gets the unique key for a handler session.
|
|
22
|
+
*/
|
|
23
|
+
get key(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the active handler state from storage.
|
|
26
|
+
*/
|
|
27
|
+
read(): Promise<TActiveHandler | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Writes handler state to storage.
|
|
30
|
+
*/
|
|
31
|
+
write(data: TActiveHandler): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Deletes handler state from storage.
|
|
34
|
+
*/
|
|
35
|
+
delete(): Promise<void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HandlerStorage = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Storage manager for handler state.
|
|
10
|
+
*/
|
|
11
|
+
class HandlerStorage {
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the HandlerStorage.
|
|
14
|
+
* @param storage The storage provider.
|
|
15
|
+
* @param context The turn context.
|
|
16
|
+
*/
|
|
17
|
+
constructor(storage, context) {
|
|
18
|
+
this.storage = storage;
|
|
19
|
+
this.context = context;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the unique key for a handler session.
|
|
23
|
+
*/
|
|
24
|
+
get key() {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const channelId = (_a = this.context.activity.channelId) === null || _a === void 0 ? void 0 : _a.trim();
|
|
27
|
+
const userId = (_c = (_b = this.context.activity.from) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.trim();
|
|
28
|
+
if (!channelId || !userId) {
|
|
29
|
+
throw new Error(`Both 'activity.channelId' and 'activity.from.id' are required to generate the ${HandlerStorage.name} key.`);
|
|
30
|
+
}
|
|
31
|
+
return `auth/${channelId}/${userId}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reads the active handler state from storage.
|
|
35
|
+
*/
|
|
36
|
+
async read() {
|
|
37
|
+
const ongoing = await this.storage.read([this.key]);
|
|
38
|
+
return ongoing === null || ongoing === void 0 ? void 0 : ongoing[this.key];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Writes handler state to storage.
|
|
42
|
+
*/
|
|
43
|
+
write(data) {
|
|
44
|
+
return this.storage.write({ [this.key]: data });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Deletes handler state from storage.
|
|
48
|
+
*/
|
|
49
|
+
async delete() {
|
|
50
|
+
try {
|
|
51
|
+
await this.storage.delete([this.key]);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error instanceof Error && 'code' in error && error.code === 404) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.HandlerStorage = HandlerStorage;
|
|
62
|
+
//# sourceMappingURL=handlerStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlerStorage.js","sourceRoot":"","sources":["../../../../src/app/auth/handlerStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH;;GAEG;AACH,MAAa,cAAc;IACzB;;;;OAIG;IACH,YAAqB,OAAgB,EAAU,OAAoB;QAA9C,YAAO,GAAP,OAAO,CAAS;QAAU,YAAO,GAAP,OAAO,CAAa;IAAI,CAAC;IAExE;;OAEG;IACH,IAAW,GAAG;;QACZ,MAAM,SAAS,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,0CAAE,IAAI,EAAE,CAAA;QACzD,MAAM,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,0CAAE,EAAE,0CAAE,IAAI,EAAE,CAAA;QACrD,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,iFAAiF,cAAc,CAAC,IAAI,OAAO,CAAC,CAAA;QAC9H,CAAC;QACD,OAAO,QAAQ,SAAS,IAAI,MAAM,EAAE,CAAA;IACtC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI;QACf,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACnD,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,IAAI,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;IAED;;OAEG;IACI,KAAK,CAAE,IAAoB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACjD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM;QACjB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;gBACpE,OAAM;YACR,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF;AAhDD,wCAgDC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { TurnContext } from '../../../turnContext';
|
|
6
|
+
import { AuthorizationHandler, AuthorizationHandlerSettings, AuthorizationHandlerStatus, AuthorizationHandlerTokenOptions } from '../types';
|
|
7
|
+
import { TokenResponse } from '../../../oauth';
|
|
8
|
+
/**
|
|
9
|
+
* Options for configuring the Agentic authorization handler.
|
|
10
|
+
*/
|
|
11
|
+
export interface AgenticAuthorizationOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The type of authorization handler.
|
|
14
|
+
* @remarks
|
|
15
|
+
* When using environment variables, this can be set using the `${authHandlerId}_type` variable.
|
|
16
|
+
*/
|
|
17
|
+
type: 'agentic';
|
|
18
|
+
/**
|
|
19
|
+
* The scopes required for the authorization.
|
|
20
|
+
* @remarks
|
|
21
|
+
* When using environment variables, this can be set using the `${authHandlerId}_scopes` variable (comma-separated values, e.g. `scope1,scope2`).
|
|
22
|
+
*/
|
|
23
|
+
scopes?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* (Optional) An alternative connection name to use for the authorization process.
|
|
26
|
+
* @remarks
|
|
27
|
+
* When using environment variables, this can be set using the `${authHandlerId}_altBlueprintConnectionName` variable.
|
|
28
|
+
*/
|
|
29
|
+
altBlueprintConnectionName?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Settings for configuring the Agentic authorization handler.
|
|
33
|
+
*/
|
|
34
|
+
export interface AgenticAuthorizationSettings extends AuthorizationHandlerSettings {
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Authorization handler for Agentic authentication.
|
|
38
|
+
*/
|
|
39
|
+
export declare class AgenticAuthorization implements AuthorizationHandler {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
private settings;
|
|
42
|
+
private _options;
|
|
43
|
+
private _onSuccess?;
|
|
44
|
+
private _onFailure?;
|
|
45
|
+
/**
|
|
46
|
+
* Creates an instance of the AgenticAuthorization class.
|
|
47
|
+
* @param id The unique identifier for the authorization handler.
|
|
48
|
+
* @param options The options for configuring the authorization handler.
|
|
49
|
+
* @param settings The settings for the authorization handler.
|
|
50
|
+
*/
|
|
51
|
+
constructor(id: string, options: AgenticAuthorizationOptions, settings: AgenticAuthorizationSettings);
|
|
52
|
+
/**
|
|
53
|
+
* Loads and validates the authorization handler options.
|
|
54
|
+
*/
|
|
55
|
+
private loadOptions;
|
|
56
|
+
/**
|
|
57
|
+
* @inheritdoc
|
|
58
|
+
*/
|
|
59
|
+
signin(): Promise<AuthorizationHandlerStatus>;
|
|
60
|
+
/**
|
|
61
|
+
* @inheritdoc
|
|
62
|
+
*/
|
|
63
|
+
signout(): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* @inheritdoc
|
|
66
|
+
*/
|
|
67
|
+
token(context: TurnContext, options?: AuthorizationHandlerTokenOptions): Promise<TokenResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* @inheritdoc
|
|
70
|
+
*/
|
|
71
|
+
onSuccess(callback: (context: TurnContext) => void): void;
|
|
72
|
+
/**
|
|
73
|
+
* @inheritdoc
|
|
74
|
+
*/
|
|
75
|
+
onFailure(callback: (context: TurnContext, reason?: string) => void): void;
|
|
76
|
+
/**
|
|
77
|
+
* Prefixes a message with the handler ID.
|
|
78
|
+
*/
|
|
79
|
+
private prefix;
|
|
80
|
+
private _key;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the authorization context in the turn state.
|
|
83
|
+
*/
|
|
84
|
+
private setContext;
|
|
85
|
+
/**
|
|
86
|
+
* Gets the authorization context from the turn state.
|
|
87
|
+
*/
|
|
88
|
+
private getContext;
|
|
89
|
+
/**
|
|
90
|
+
* Gets the audience from the turn context.
|
|
91
|
+
*/
|
|
92
|
+
private getAudience;
|
|
93
|
+
/**
|
|
94
|
+
* Loads the OAuth scopes from the environment variables.
|
|
95
|
+
*/
|
|
96
|
+
private loadScopes;
|
|
97
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.AgenticAuthorization = void 0;
|
|
8
|
+
const agents_activity_1 = require("@microsoft/agents-activity");
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const logger = (0, agents_activity_1.debug)('agents:authorization:agentic');
|
|
11
|
+
/**
|
|
12
|
+
* Authorization handler for Agentic authentication.
|
|
13
|
+
*/
|
|
14
|
+
class AgenticAuthorization {
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of the AgenticAuthorization class.
|
|
17
|
+
* @param id The unique identifier for the authorization handler.
|
|
18
|
+
* @param options The options for configuring the authorization handler.
|
|
19
|
+
* @param settings The settings for the authorization handler.
|
|
20
|
+
*/
|
|
21
|
+
constructor(id, options, settings) {
|
|
22
|
+
this.id = id;
|
|
23
|
+
this.settings = settings;
|
|
24
|
+
this._key = `${AgenticAuthorization.name}/${this.id}`;
|
|
25
|
+
if (!this.settings.connections) {
|
|
26
|
+
throw new Error(this.prefix('The \'connections\' option is not available in the app options. Ensure that the app is properly configured.'));
|
|
27
|
+
}
|
|
28
|
+
this._options = this.loadOptions(options);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Loads and validates the authorization handler options.
|
|
32
|
+
*/
|
|
33
|
+
loadOptions(settings) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const result = {
|
|
36
|
+
type: 'agentic',
|
|
37
|
+
altBlueprintConnectionName: (_a = settings.altBlueprintConnectionName) !== null && _a !== void 0 ? _a : (process.env[`${this.id}_altBlueprintConnectionName`]),
|
|
38
|
+
scopes: (_b = settings.scopes) !== null && _b !== void 0 ? _b : this.loadScopes(process.env[`${this.id}_scopes`]),
|
|
39
|
+
};
|
|
40
|
+
if (!result.scopes || result.scopes.length === 0) {
|
|
41
|
+
throw new Error(this.prefix('At least one scope must be specified for the Agentic authorization handler.'));
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @inheritdoc
|
|
47
|
+
*/
|
|
48
|
+
signin() {
|
|
49
|
+
return Promise.resolve(types_1.AuthorizationHandlerStatus.IGNORED);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @inheritdoc
|
|
53
|
+
*/
|
|
54
|
+
signout() {
|
|
55
|
+
return Promise.resolve(false);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @inheritdoc
|
|
59
|
+
*/
|
|
60
|
+
async token(context, options) {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f;
|
|
62
|
+
try {
|
|
63
|
+
const tokenResponse = this.getContext(context);
|
|
64
|
+
if (tokenResponse.token) {
|
|
65
|
+
logger.debug(this.prefix('Using cached Agentic user token'));
|
|
66
|
+
return tokenResponse;
|
|
67
|
+
}
|
|
68
|
+
let connection;
|
|
69
|
+
if ((_a = this._options.altBlueprintConnectionName) === null || _a === void 0 ? void 0 : _a.trim()) {
|
|
70
|
+
connection = this.settings.connections.getConnection(this._options.altBlueprintConnectionName);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const audience = this.getAudience(context);
|
|
74
|
+
connection = this.settings.connections.getTokenProvider(audience, (_b = context.activity.serviceUrl) !== null && _b !== void 0 ? _b : '');
|
|
75
|
+
}
|
|
76
|
+
const token = await connection.getAgenticUserToken((_c = context.activity.getAgenticInstanceId()) !== null && _c !== void 0 ? _c : '', (_d = context.activity.getAgenticUser()) !== null && _d !== void 0 ? _d : '', (options === null || options === void 0 ? void 0 : options.scopes) || this._options.scopes);
|
|
77
|
+
this.setContext(context, { token });
|
|
78
|
+
(_e = this._onSuccess) === null || _e === void 0 ? void 0 : _e.call(this, context);
|
|
79
|
+
return { token };
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const reason = 'Error retrieving Agentic user token';
|
|
83
|
+
logger.error(this.prefix(reason), error);
|
|
84
|
+
(_f = this._onFailure) === null || _f === void 0 ? void 0 : _f.call(this, context, `${reason}: ${error.message}`);
|
|
85
|
+
return { token: undefined };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @inheritdoc
|
|
90
|
+
*/
|
|
91
|
+
onSuccess(callback) {
|
|
92
|
+
this._onSuccess = callback;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @inheritdoc
|
|
96
|
+
*/
|
|
97
|
+
onFailure(callback) {
|
|
98
|
+
this._onFailure = callback;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Prefixes a message with the handler ID.
|
|
102
|
+
*/
|
|
103
|
+
prefix(message) {
|
|
104
|
+
return `[handler:${this.id}] ${message}`;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Sets the authorization context in the turn state.
|
|
108
|
+
*/
|
|
109
|
+
setContext(context, data) {
|
|
110
|
+
return context.turnState.set(this._key, () => data);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the authorization context from the turn state.
|
|
114
|
+
*/
|
|
115
|
+
getContext(context) {
|
|
116
|
+
var _a;
|
|
117
|
+
const result = context.turnState.get(this._key);
|
|
118
|
+
return (_a = result === null || result === void 0 ? void 0 : result()) !== null && _a !== void 0 ? _a : { token: undefined };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Gets the audience from the turn context.
|
|
122
|
+
*/
|
|
123
|
+
getAudience(context) {
|
|
124
|
+
const { aud } = context.identity;
|
|
125
|
+
if (!aud) {
|
|
126
|
+
throw new Error('No audience (aud) claim found in Activity.identity.');
|
|
127
|
+
}
|
|
128
|
+
return Array.isArray(aud) ? aud[0] : aud;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Loads the OAuth scopes from the environment variables.
|
|
132
|
+
*/
|
|
133
|
+
loadScopes(value) {
|
|
134
|
+
var _a;
|
|
135
|
+
return (_a = value === null || value === void 0 ? void 0 : value.split(',').reduce((acc, scope) => {
|
|
136
|
+
const trimmed = scope.trim();
|
|
137
|
+
if (trimmed) {
|
|
138
|
+
acc.push(trimmed);
|
|
139
|
+
}
|
|
140
|
+
return acc;
|
|
141
|
+
}, [])) !== null && _a !== void 0 ? _a : [];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.AgenticAuthorization = AgenticAuthorization;
|
|
145
|
+
//# sourceMappingURL=agenticAuthorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agenticAuthorization.js","sourceRoot":"","sources":["../../../../../src/app/auth/handlers/agenticAuthorization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,gEAAkD;AAElD,oCAA2I;AAI3I,MAAM,MAAM,GAAG,IAAA,uBAAK,EAAC,8BAA8B,CAAC,CAAA;AA+BpD;;GAEG;AACH,MAAa,oBAAoB;IAK/B;;;;;OAKG;IACH,YAA6B,EAAU,EAAE,OAAoC,EAAU,QAAsC;QAAhG,OAAE,GAAF,EAAE,CAAQ;QAAgD,aAAQ,GAAR,QAAQ,CAA8B;QAiGrH,SAAI,GAAG,GAAG,oBAAoB,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAA;QAhGtD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,6GAA6G,CAAC,CAAC,CAAA;QAC7I,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED;;OAEG;IACK,WAAW,CAAE,QAAqC;;QACxD,MAAM,MAAM,GAAgC;YAC1C,IAAI,EAAE,SAAS;YACf,0BAA0B,EAAE,MAAA,QAAQ,CAAC,0BAA0B,mCAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,6BAA6B,CAAC,CAAC;YACzH,MAAM,EAAE,MAAA,QAAQ,CAAC,MAAM,mCAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;SAC7E,CAAA;QAED,IAA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