@microsoft/agents-hosting 1.1.0-alpha.9.g154c2c8a32 → 1.1.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 -6
- package/dist/src/activityWireCompat.d.ts +1 -1
- package/dist/src/activityWireCompat.js +11 -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 +90 -79
- 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/{authorization.d.ts → auth/authorization.d.ts} +41 -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 +93 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.js +134 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +226 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +429 -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 +3 -3
- package/dist/src/app/index.js +2 -3
- package/dist/src/app/index.js.map +1 -1
- 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.js +2 -1
- package/dist/src/app/streaming/streamingResponse.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 +209 -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 +26 -0
- package/dist/src/auth/connections.d.ts +41 -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 +64 -0
- package/dist/src/auth/msalConnectionManager.js +148 -0
- package/dist/src/auth/msalConnectionManager.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +38 -0
- package/dist/src/auth/msalTokenProvider.js +186 -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/cards/cardFactory.d.ts +2 -1
- package/dist/src/cards/cardFactory.js +3 -2
- package/dist/src/cards/cardFactory.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +40 -23
- package/dist/src/cloudAdapter.js +143 -63
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +15 -0
- package/dist/src/connector-client/connectorClient.js +49 -15
- 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/customUserTokenAPI.d.ts +1 -0
- package/dist/src/oauth/customUserTokenAPI.js +11 -0
- package/dist/src/oauth/customUserTokenAPI.js.map +1 -0
- 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 +62 -26
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/oauth/userTokenClient.types.d.ts +19 -6
- package/dist/src/transcript/fileTranscriptLogger.d.ts +109 -0
- package/dist/src/transcript/fileTranscriptLogger.js +398 -0
- package/dist/src/transcript/fileTranscriptLogger.js.map +1 -0
- 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 +12 -4
- package/src/agent-client/agentClient.ts +9 -3
- package/src/agent-client/agentResponseHandler.ts +5 -2
- package/src/app/agentApplication.ts +95 -74
- package/src/app/agentApplicationBuilder.ts +2 -2
- package/src/app/agentApplicationOptions.ts +10 -2
- package/src/app/appRoute.ts +8 -0
- package/src/app/auth/authorization.ts +261 -0
- package/src/app/auth/authorizationManager.ts +213 -0
- package/src/app/auth/handlerStorage.ts +61 -0
- package/src/app/auth/handlers/agenticAuthorization.ts +183 -0
- package/src/app/auth/handlers/azureBotAuthorization.ts +606 -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 +3 -3
- package/src/app/routeList.ts +24 -5
- package/src/app/streaming/streamingResponse.ts +2 -1
- package/src/auth/MemoryCache.ts +59 -0
- package/src/auth/authConfiguration.ts +245 -52
- package/src/auth/authConstants.ts +11 -0
- package/src/auth/authProvider.ts +34 -0
- package/src/auth/connections.ts +47 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/jwt-middleware.ts +38 -21
- package/src/auth/msalConnectionManager.ts +175 -0
- package/src/auth/msalTokenProvider.ts +228 -9
- package/src/baseAdapter.ts +10 -29
- package/src/cards/cardFactory.ts +3 -2
- package/src/cloudAdapter.ts +207 -72
- package/src/connector-client/connectorClient.ts +59 -15
- package/src/index.ts +0 -1
- package/src/oauth/customUserTokenAPI.ts +5 -0
- package/src/oauth/index.ts +0 -1
- package/src/oauth/userTokenClient.ts +76 -22
- package/src/oauth/userTokenClient.types.ts +20 -8
- package/src/transcript/fileTranscriptLogger.ts +409 -0
- 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
package/src/turnContext.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { TurnContextStateCollection } from './turnContextStateCollection'
|
|
|
7
7
|
import { AttachmentInfo } from './connector-client/attachmentInfo'
|
|
8
8
|
import { AttachmentData } from './connector-client/attachmentData'
|
|
9
9
|
import { StreamingResponse } from './app/streaming/streamingResponse'
|
|
10
|
+
import { JwtPayload } from 'jsonwebtoken'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Defines a handler for processing and sending activities.
|
|
@@ -71,20 +72,23 @@ export class TurnContext {
|
|
|
71
72
|
private readonly _turn = 'turn'
|
|
72
73
|
private readonly _locale = 'locale'
|
|
73
74
|
private readonly _streamingResponse: StreamingResponse
|
|
75
|
+
private readonly _identity?: JwtPayload
|
|
76
|
+
|
|
74
77
|
/**
|
|
75
78
|
* Initializes a new instance of the TurnContext class.
|
|
76
79
|
*
|
|
77
80
|
* @param adapterOrContext The adapter that created this context, or another TurnContext to clone
|
|
78
81
|
* @param request The activity for the turn (required when first parameter is an adapter)
|
|
79
82
|
*/
|
|
80
|
-
constructor (adapterOrContext: BaseAdapter, request: Activity)
|
|
83
|
+
constructor (adapterOrContext: BaseAdapter, request: Activity, identity?: JwtPayload)
|
|
81
84
|
constructor (adapterOrContext: TurnContext)
|
|
82
|
-
constructor (adapterOrContext: BaseAdapter | TurnContext, request?: Activity) {
|
|
85
|
+
constructor (adapterOrContext: BaseAdapter | TurnContext, request?: Activity, identity?: JwtPayload) {
|
|
83
86
|
if (adapterOrContext instanceof TurnContext) {
|
|
84
87
|
adapterOrContext.copyTo(this)
|
|
85
88
|
} else {
|
|
86
89
|
this._adapter = adapterOrContext
|
|
87
90
|
this._activity = request as Activity
|
|
91
|
+
this._identity = identity as JwtPayload
|
|
88
92
|
}
|
|
89
93
|
this._streamingResponse = new StreamingResponse(this)
|
|
90
94
|
}
|
|
@@ -246,6 +250,7 @@ export class TurnContext {
|
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
/**
|
|
253
|
+
* @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
|
|
249
254
|
* Uploads an attachment to the conversation.
|
|
250
255
|
*
|
|
251
256
|
* @param conversationId The ID of the conversation
|
|
@@ -253,20 +258,22 @@ export class TurnContext {
|
|
|
253
258
|
* @returns A promise that resolves to the resource response
|
|
254
259
|
*/
|
|
255
260
|
async uploadAttachment (conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse> {
|
|
256
|
-
return await this.adapter.uploadAttachment(conversationId, attachmentData)
|
|
261
|
+
return await this.adapter.uploadAttachment(this, conversationId, attachmentData)
|
|
257
262
|
}
|
|
258
263
|
|
|
259
264
|
/**
|
|
265
|
+
* @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
|
|
260
266
|
* Gets information about an attachment.
|
|
261
267
|
*
|
|
262
268
|
* @param attachmentId The ID of the attachment
|
|
263
269
|
* @returns A promise that resolves to the attachment information
|
|
264
270
|
*/
|
|
265
271
|
async getAttachmentInfo (attachmentId: string): Promise<AttachmentInfo> {
|
|
266
|
-
return await this.adapter.getAttachmentInfo(attachmentId)
|
|
272
|
+
return await this.adapter.getAttachmentInfo(this, attachmentId)
|
|
267
273
|
}
|
|
268
274
|
|
|
269
275
|
/**
|
|
276
|
+
* @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
|
|
270
277
|
* Gets the content of an attachment.
|
|
271
278
|
*
|
|
272
279
|
* @param attachmentId The ID of the attachment
|
|
@@ -274,7 +281,7 @@ export class TurnContext {
|
|
|
274
281
|
* @returns A promise that resolves to a readable stream of the attachment content
|
|
275
282
|
*/
|
|
276
283
|
async getAttachment (attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream> {
|
|
277
|
-
return await this.adapter.getAttachment(attachmentId, viewId)
|
|
284
|
+
return await this.adapter.getAttachment(this, attachmentId, viewId)
|
|
278
285
|
}
|
|
279
286
|
|
|
280
287
|
/**
|
|
@@ -348,6 +355,10 @@ export class TurnContext {
|
|
|
348
355
|
return this._activity as Activity
|
|
349
356
|
}
|
|
350
357
|
|
|
358
|
+
get identity (): JwtPayload {
|
|
359
|
+
return this._identity as JwtPayload
|
|
360
|
+
}
|
|
361
|
+
|
|
351
362
|
/**
|
|
352
363
|
* Gets or sets whether the turn has sent a response to the user.
|
|
353
364
|
*
|
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Authorization = void 0;
|
|
11
|
-
const logger_1 = require("@microsoft/agents-activity/logger");
|
|
12
|
-
const oauth_1 = require("../oauth");
|
|
13
|
-
const auth_1 = require("../auth");
|
|
14
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
15
|
-
const logger = (0, logger_1.debug)('agents:authorization');
|
|
16
|
-
/**
|
|
17
|
-
* Class responsible for managing authorization and OAuth flows.
|
|
18
|
-
* Handles multiple OAuth providers and manages the complete authentication lifecycle.
|
|
19
|
-
*
|
|
20
|
-
* @remarks
|
|
21
|
-
* The Authorization class provides a centralized way to handle OAuth authentication
|
|
22
|
-
* flows within the agent application. It supports multiple authentication handlers,
|
|
23
|
-
* token exchange, on-behalf-of flows, and provides event handlers for success/failure scenarios.
|
|
24
|
-
*
|
|
25
|
-
* Key features:
|
|
26
|
-
* - Multiple OAuth provider support
|
|
27
|
-
* - Token caching and exchange
|
|
28
|
-
* - On-behalf-of (OBO) token flows
|
|
29
|
-
* - Sign-in success/failure event handling
|
|
30
|
-
* - Automatic configuration from environment variables
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const auth = new Authorization(storage, {
|
|
35
|
-
* 'microsoft': {
|
|
36
|
-
* name: 'Microsoft',
|
|
37
|
-
* title: 'Sign in with Microsoft',
|
|
38
|
-
* text: 'Please sign in'
|
|
39
|
-
* }
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* auth.onSignInSuccess(async (context, state) => {
|
|
43
|
-
* await context.sendActivity('Welcome! You are now signed in.');
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
class Authorization {
|
|
49
|
-
/**
|
|
50
|
-
* Creates a new instance of Authorization.
|
|
51
|
-
*
|
|
52
|
-
* @remarks
|
|
53
|
-
* The constructor initializes all configured auth handlers and sets up OAuth flows.
|
|
54
|
-
* It automatically configures handler properties from environment variables if not provided:
|
|
55
|
-
* - Connection name: {handlerId}_connectionName
|
|
56
|
-
* - Connection title: {handlerId}_connectionTitle
|
|
57
|
-
* - Connection text: {handlerId}_connectionText
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const auth = new Authorization(storage, {
|
|
62
|
-
* 'microsoft': {
|
|
63
|
-
* name: 'Microsoft',
|
|
64
|
-
* title: 'Sign in with Microsoft'
|
|
65
|
-
* },
|
|
66
|
-
* 'google': {
|
|
67
|
-
* // Will use GOOGLE_connectionName from env vars
|
|
68
|
-
* }
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* @param storage - The storage system to use for state management.
|
|
73
|
-
* @param authHandlers - Configuration for OAuth providers.
|
|
74
|
-
* @throws {Error} If storage is null/undefined or no auth handlers are provided.
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
constructor(storage, authHandlers, userTokenClient) {
|
|
78
|
-
var _a, _b, _c, _d;
|
|
79
|
-
this.storage = storage;
|
|
80
|
-
/**
|
|
81
|
-
* Private handler for successful sign-in events.
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
this._signInSuccessHandler = null;
|
|
85
|
-
/**
|
|
86
|
-
* Private handler for failed sign-in events.
|
|
87
|
-
* @private
|
|
88
|
-
*/
|
|
89
|
-
this._signInFailureHandler = null;
|
|
90
|
-
if (storage === undefined || storage === null) {
|
|
91
|
-
throw new Error('Storage is required for UserAuthorization');
|
|
92
|
-
}
|
|
93
|
-
if (authHandlers === undefined || Object.keys(authHandlers).length === 0) {
|
|
94
|
-
throw new Error('The authorization does not have any auth handlers');
|
|
95
|
-
}
|
|
96
|
-
this.authHandlers = authHandlers;
|
|
97
|
-
for (const ah in this.authHandlers) {
|
|
98
|
-
if (this.authHandlers[ah].name === undefined && process.env[ah + '_connectionName'] === undefined) {
|
|
99
|
-
throw new Error(`AuthHandler name ${ah}_connectionName not set in autorization and not found in env vars.`);
|
|
100
|
-
}
|
|
101
|
-
const currentAuthHandler = this.authHandlers[ah];
|
|
102
|
-
currentAuthHandler.name = (_a = currentAuthHandler.name) !== null && _a !== void 0 ? _a : process.env[ah + '_connectionName'];
|
|
103
|
-
currentAuthHandler.title = (_b = currentAuthHandler.title) !== null && _b !== void 0 ? _b : process.env[ah + '_connectionTitle'];
|
|
104
|
-
currentAuthHandler.text = (_c = currentAuthHandler.text) !== null && _c !== void 0 ? _c : process.env[ah + '_connectionText'];
|
|
105
|
-
currentAuthHandler.cnxPrefix = (_d = currentAuthHandler.cnxPrefix) !== null && _d !== void 0 ? _d : process.env[ah + '_cnxPrefix'];
|
|
106
|
-
currentAuthHandler.flow = new oauth_1.OAuthFlow(this.storage, currentAuthHandler.name, userTokenClient, currentAuthHandler.title, currentAuthHandler.text);
|
|
107
|
-
}
|
|
108
|
-
logger.info('Authorization handlers configured with', Object.keys(this.authHandlers).length, 'handlers');
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Gets the token for a specific auth handler.
|
|
112
|
-
*
|
|
113
|
-
* @param context - The context object for the current turn.
|
|
114
|
-
* @param authHandlerId - ID of the auth handler to use.
|
|
115
|
-
* @returns A promise that resolves to the token response from the OAuth provider.
|
|
116
|
-
* @throws {Error} If the auth handler is not configured.
|
|
117
|
-
*
|
|
118
|
-
* @remarks
|
|
119
|
-
* This method retrieves an existing token for the specified auth handler.
|
|
120
|
-
* The token may be cached and will be retrieved from the OAuth provider if needed.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* const tokenResponse = await auth.getToken(context, 'microsoft');
|
|
125
|
-
* if (tokenResponse.token) {
|
|
126
|
-
* console.log('User is authenticated');
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* @public
|
|
131
|
-
*/
|
|
132
|
-
async getToken(context, authHandlerId) {
|
|
133
|
-
var _a;
|
|
134
|
-
logger.info('getToken from user token service for authHandlerId:', authHandlerId);
|
|
135
|
-
const authHandler = this.getAuthHandlerOrThrow(authHandlerId);
|
|
136
|
-
return await ((_a = authHandler.flow) === null || _a === void 0 ? void 0 : _a.getUserToken(context));
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Gets the auth handler by ID or throws an error if not found.
|
|
140
|
-
*
|
|
141
|
-
* @param authHandlerId - ID of the auth handler to retrieve.
|
|
142
|
-
* @returns The auth handler instance.
|
|
143
|
-
* @throws {Error} If the auth handler with the specified ID is not configured.
|
|
144
|
-
* @private
|
|
145
|
-
*/
|
|
146
|
-
getAuthHandlerOrThrow(authHandlerId) {
|
|
147
|
-
if (!Object.prototype.hasOwnProperty.call(this.authHandlers, authHandlerId)) {
|
|
148
|
-
throw new Error(`AuthHandler with ID ${authHandlerId} not configured`);
|
|
149
|
-
}
|
|
150
|
-
return this.authHandlers[authHandlerId];
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Exchanges a token for a new token with different scopes.
|
|
154
|
-
*
|
|
155
|
-
* @param context - The context object for the current turn.
|
|
156
|
-
* @param scopes - Array of scopes to request for the new token.
|
|
157
|
-
* @param authHandlerId - ID of the auth handler to use.
|
|
158
|
-
* @returns A promise that resolves to the exchanged token response.
|
|
159
|
-
* @throws {Error} If the auth handler is not configured.
|
|
160
|
-
*
|
|
161
|
-
* @remarks
|
|
162
|
-
* This method handles token exchange scenarios, particularly for on-behalf-of (OBO) flows.
|
|
163
|
-
* It checks if the current token is exchangeable (e.g., has audience starting with 'api://')
|
|
164
|
-
* and performs the appropriate token exchange using MSAL.
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* const exchangedToken = await auth.exchangeToken(
|
|
169
|
-
* context,
|
|
170
|
-
* ['https://graph.microsoft.com/.default'],
|
|
171
|
-
* 'microsoft'
|
|
172
|
-
* );
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* @public
|
|
176
|
-
*/
|
|
177
|
-
async exchangeToken(context, scopes, authHandlerId) {
|
|
178
|
-
var _a;
|
|
179
|
-
logger.info('exchangeToken from user token service for authHandlerId:', authHandlerId);
|
|
180
|
-
const authHandler = this.getAuthHandlerOrThrow(authHandlerId);
|
|
181
|
-
const tokenResponse = await ((_a = authHandler.flow) === null || _a === void 0 ? void 0 : _a.getUserToken(context));
|
|
182
|
-
if (this.isExchangeable(tokenResponse.token)) {
|
|
183
|
-
return await this.handleObo(context, tokenResponse.token, scopes, authHandler.cnxPrefix);
|
|
184
|
-
}
|
|
185
|
-
return tokenResponse;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Checks if a token is exchangeable for an on-behalf-of flow.
|
|
189
|
-
*
|
|
190
|
-
* @param token - The token to check.
|
|
191
|
-
* @returns True if the token is exchangeable, false otherwise.
|
|
192
|
-
* @private
|
|
193
|
-
*/
|
|
194
|
-
isExchangeable(token) {
|
|
195
|
-
var _a;
|
|
196
|
-
if (!token || typeof token !== 'string') {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
const payload = jsonwebtoken_1.default.decode(token);
|
|
200
|
-
return ((_a = payload === null || payload === void 0 ? void 0 : payload.aud) === null || _a === void 0 ? void 0 : _a.indexOf('api://')) === 0;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Handles on-behalf-of token exchange using MSAL.
|
|
204
|
-
*
|
|
205
|
-
* @param context - The context object for the current turn.
|
|
206
|
-
* @param token - The token to exchange.
|
|
207
|
-
* @param scopes - Array of scopes to request for the new token.
|
|
208
|
-
* @returns A promise that resolves to the exchanged token response.
|
|
209
|
-
* @private
|
|
210
|
-
*/
|
|
211
|
-
async handleObo(context, token, scopes, cnxPrefix) {
|
|
212
|
-
const msalTokenProvider = new auth_1.MsalTokenProvider();
|
|
213
|
-
let authConfig = context.adapter.authConfig;
|
|
214
|
-
if (cnxPrefix) {
|
|
215
|
-
authConfig = (0, auth_1.loadAuthConfigFromEnv)(cnxPrefix);
|
|
216
|
-
}
|
|
217
|
-
const newToken = await msalTokenProvider.acquireTokenOnBehalfOf(authConfig, scopes, token);
|
|
218
|
-
return { token: newToken };
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Begins or continues an OAuth flow.
|
|
222
|
-
*
|
|
223
|
-
* @param context - The context object for the current turn.
|
|
224
|
-
* @param state - The state object for the current turn.
|
|
225
|
-
* @param authHandlerId - ID of the auth handler to use.
|
|
226
|
-
* @returns A promise that resolves to the token response from the OAuth provider.
|
|
227
|
-
* @throws {Error} If the auth handler is not configured.
|
|
228
|
-
*
|
|
229
|
-
* @remarks
|
|
230
|
-
* This method manages the complete OAuth authentication flow:
|
|
231
|
-
* - If no flow is active, it begins a new OAuth flow and shows the sign-in card
|
|
232
|
-
* - If a flow is active, it continues the flow and processes the authentication response
|
|
233
|
-
* - Handles success/failure callbacks and updates the sign-in state accordingly
|
|
234
|
-
*
|
|
235
|
-
* The method automatically manages the sign-in state and continuation activities,
|
|
236
|
-
* allowing the conversation to resume after successful authentication.
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```typescript
|
|
240
|
-
* const tokenResponse = await auth.beginOrContinueFlow(context, state, 'microsoft');
|
|
241
|
-
* if (tokenResponse && tokenResponse.token) {
|
|
242
|
-
* // User is now authenticated
|
|
243
|
-
* await context.sendActivity('Authentication successful!');
|
|
244
|
-
* }
|
|
245
|
-
* ```
|
|
246
|
-
*
|
|
247
|
-
* @public
|
|
248
|
-
*/
|
|
249
|
-
async beginOrContinueFlow(context, state, authHandlerId, secRoute = true) {
|
|
250
|
-
var _a, _b, _c, _d, _e;
|
|
251
|
-
const authHandler = this.getAuthHandlerOrThrow(authHandlerId);
|
|
252
|
-
logger.info('beginOrContinueFlow for authHandlerId:', authHandlerId);
|
|
253
|
-
const signInState = state.getValue('user.__SIGNIN_STATE_') || { continuationActivity: undefined, handlerId: undefined, completed: false };
|
|
254
|
-
const flow = authHandler.flow;
|
|
255
|
-
let tokenResponse;
|
|
256
|
-
tokenResponse = await ((_a = authHandler.flow) === null || _a === void 0 ? void 0 : _a.getUserToken(context));
|
|
257
|
-
if ((tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.token) && tokenResponse.token.length > 0) {
|
|
258
|
-
(_b = authHandler.flow) === null || _b === void 0 ? true : delete _b.state.eTag;
|
|
259
|
-
authHandler.flow.state.flowStarted = false;
|
|
260
|
-
await ((_c = authHandler.flow) === null || _c === void 0 ? void 0 : _c.setFlowState(context, authHandler.flow.state));
|
|
261
|
-
if (secRoute) {
|
|
262
|
-
return tokenResponse;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (flow.state === null || ((_d = flow.state) === null || _d === void 0 ? void 0 : _d.flowStarted) === false || ((_e = flow.state) === null || _e === void 0 ? void 0 : _e.flowStarted) === undefined) {
|
|
266
|
-
tokenResponse = await flow.beginFlow(context);
|
|
267
|
-
if (secRoute && (tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.token) === undefined) {
|
|
268
|
-
signInState.continuationActivity = context.activity;
|
|
269
|
-
signInState.handlerId = authHandlerId;
|
|
270
|
-
state.setValue('user.__SIGNIN_STATE_', signInState);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
tokenResponse = await flow.continueFlow(context);
|
|
275
|
-
if (tokenResponse && tokenResponse.token) {
|
|
276
|
-
if (this._signInSuccessHandler) {
|
|
277
|
-
await this._signInSuccessHandler(context, state, authHandlerId);
|
|
278
|
-
}
|
|
279
|
-
if (secRoute) {
|
|
280
|
-
state.deleteValue('user.__SIGNIN_STATE_');
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
logger.warn('Failed to complete OAuth flow, no token received');
|
|
285
|
-
if (this._signInFailureHandler) {
|
|
286
|
-
await this._signInFailureHandler(context, state, authHandlerId, 'Failed to complete the OAuth flow');
|
|
287
|
-
}
|
|
288
|
-
// signInState!.completed = false
|
|
289
|
-
// state.setValue('user.__SIGNIN_STATE_', signInState)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return tokenResponse;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Signs out the current user.
|
|
296
|
-
*
|
|
297
|
-
* @param context - The context object for the current turn.
|
|
298
|
-
* @param state - The state object for the current turn.
|
|
299
|
-
* @param authHandlerId - Optional ID of the auth handler to use for sign out. If not provided, signs out from all handlers.
|
|
300
|
-
* @returns A promise that resolves when sign out is complete.
|
|
301
|
-
* @throws {Error} If the specified auth handler is not configured.
|
|
302
|
-
*
|
|
303
|
-
* @remarks
|
|
304
|
-
* This method clears the user's token and resets the authentication state.
|
|
305
|
-
* If no specific authHandlerId is provided, it signs out from all configured handlers.
|
|
306
|
-
* This ensures complete cleanup of authentication state across all providers.
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```typescript
|
|
310
|
-
* // Sign out from specific handler
|
|
311
|
-
* await auth.signOut(context, state, 'microsoft');
|
|
312
|
-
*
|
|
313
|
-
* // Sign out from all handlers
|
|
314
|
-
* await auth.signOut(context, state);
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
317
|
-
* @public
|
|
318
|
-
*/
|
|
319
|
-
async signOut(context, state, authHandlerId) {
|
|
320
|
-
var _a;
|
|
321
|
-
logger.info('signOut for authHandlerId:', authHandlerId);
|
|
322
|
-
if (authHandlerId === undefined) { // aw
|
|
323
|
-
for (const ah in this.authHandlers) {
|
|
324
|
-
const flow = this.authHandlers[ah].flow;
|
|
325
|
-
await (flow === null || flow === void 0 ? void 0 : flow.signOut(context));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
const authHandler = this.getAuthHandlerOrThrow(authHandlerId);
|
|
330
|
-
await ((_a = authHandler.flow) === null || _a === void 0 ? void 0 : _a.signOut(context));
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Sets a handler to be called when sign-in is successfully completed.
|
|
335
|
-
*
|
|
336
|
-
* @param handler - The handler function to call on successful sign-in.
|
|
337
|
-
*
|
|
338
|
-
* @remarks
|
|
339
|
-
* This method allows you to register a callback that will be invoked whenever
|
|
340
|
-
* a user successfully completes the authentication process. The handler receives
|
|
341
|
-
* the turn context, state, and the ID of the auth handler that was used.
|
|
342
|
-
*
|
|
343
|
-
* @example
|
|
344
|
-
* ```typescript
|
|
345
|
-
* auth.onSignInSuccess(async (context, state, authHandlerId) => {
|
|
346
|
-
* await context.sendActivity(`Welcome! You signed in using ${authHandlerId}.`);
|
|
347
|
-
* // Perform any post-authentication setup
|
|
348
|
-
* });
|
|
349
|
-
* ```
|
|
350
|
-
*
|
|
351
|
-
* @public
|
|
352
|
-
*/
|
|
353
|
-
onSignInSuccess(handler) {
|
|
354
|
-
this._signInSuccessHandler = handler;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Sets a handler to be called when sign-in fails.
|
|
358
|
-
*
|
|
359
|
-
* @param handler - The handler function to call on sign-in failure.
|
|
360
|
-
*
|
|
361
|
-
* @remarks
|
|
362
|
-
* This method allows you to register a callback that will be invoked whenever
|
|
363
|
-
* a user's authentication attempt fails. The handler receives the turn context,
|
|
364
|
-
* state, auth handler ID, and an optional error message describing the failure.
|
|
365
|
-
*
|
|
366
|
-
* Common failure scenarios include:
|
|
367
|
-
* - User cancels the authentication process
|
|
368
|
-
* - Invalid credentials or expired tokens
|
|
369
|
-
* - Network connectivity issues
|
|
370
|
-
* - OAuth provider errors
|
|
371
|
-
*
|
|
372
|
-
* @example
|
|
373
|
-
* ```typescript
|
|
374
|
-
* auth.onSignInFailure(async (context, state, authHandlerId, errorMessage) => {
|
|
375
|
-
* await context.sendActivity(`Sign-in failed: ${errorMessage || 'Unknown error'}`);
|
|
376
|
-
* await context.sendActivity('Please try signing in again.');
|
|
377
|
-
* });
|
|
378
|
-
* ```
|
|
379
|
-
*
|
|
380
|
-
* @public
|
|
381
|
-
*/
|
|
382
|
-
onSignInFailure(handler) {
|
|
383
|
-
this._signInFailureHandler = handler;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
exports.Authorization = Authorization;
|
|
387
|
-
//# sourceMappingURL=authorization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/app/authorization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,8DAAyD;AAGzD,oCAAoE;AACpE,kCAAqF;AACrF,gEAA8C;AAG9C,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,sBAAsB,CAAC,CAAA;AAuC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,aAAa;IAOxB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YAAqB,OAAgB,EAAE,YAAmC,EAAE,eAAgC;;QAAvF,YAAO,GAAP,OAAO,CAAS;QAsPrC;;;WAGG;QACH,0BAAqB,GAA+F,IAAI,CAAA;QA0BxH;;;WAGG;QACH,0BAAqB,GAAsH,IAAI,CAAA;QAvR7I,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;QAC9D,CAAC;QACD,IAAI,YAAY,KAAK,SAAS,IAAI,MAAM,C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qBAAqB,CAAC,aAAa,CAAC,CAAA;YAC7D,MAAM,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,OAAO,CAAC,OAAO,CAAC,CAAA,CAAA;QAC1C,CAAC;IACH,CAAC;IAQD;;;;;;;;;;;;;;;;;;;OAmBG;IACI,eAAe,CAAE,OAA0F;QAChH,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAA;IACtC,CAAC;IAQD;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,eAAe,CAAE,OAAiH;QACvI,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAA;IACtC,CAAC;CACF;AA1VD,sCA0VC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Represents a claim with a type and value.
|
|
7
|
-
*/
|
|
8
|
-
export interface Claim {
|
|
9
|
-
readonly type: string;
|
|
10
|
-
readonly value: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Represents an identity with a collection of claims.
|
|
14
|
-
*/
|
|
15
|
-
export declare class ClaimsIdentity {
|
|
16
|
-
readonly claims: Claim[];
|
|
17
|
-
private readonly authenticationType?;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new instance of the ClaimsIdentity class.
|
|
20
|
-
* @param claims The collection of claims associated with the identity.
|
|
21
|
-
* @param authenticationType The type of authentication used, or a boolean indicating if the identity is authenticated.
|
|
22
|
-
*/
|
|
23
|
-
constructor(claims: Claim[], authenticationType?: string | boolean | undefined);
|
|
24
|
-
/**
|
|
25
|
-
* Indicates whether the identity is authenticated.
|
|
26
|
-
* @returns True if the identity is authenticated; otherwise, false.
|
|
27
|
-
*/
|
|
28
|
-
get isAuthenticated(): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Gets the value of a claim by its type.
|
|
31
|
-
* @param claimType The type of the claim to retrieve.
|
|
32
|
-
* @returns The value of the claim, or null if the claim is not found.
|
|
33
|
-
*/
|
|
34
|
-
getClaimValue(claimType: string): string | null;
|
|
35
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
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.ClaimsIdentity = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* Represents an identity with a collection of claims.
|
|
10
|
-
*/
|
|
11
|
-
class ClaimsIdentity {
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new instance of the ClaimsIdentity class.
|
|
14
|
-
* @param claims The collection of claims associated with the identity.
|
|
15
|
-
* @param authenticationType The type of authentication used, or a boolean indicating if the identity is authenticated.
|
|
16
|
-
*/
|
|
17
|
-
constructor(claims, authenticationType) {
|
|
18
|
-
this.claims = claims;
|
|
19
|
-
this.authenticationType = authenticationType;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Indicates whether the identity is authenticated.
|
|
23
|
-
* @returns True if the identity is authenticated; otherwise, false.
|
|
24
|
-
*/
|
|
25
|
-
get isAuthenticated() {
|
|
26
|
-
if (typeof this.authenticationType === 'boolean') {
|
|
27
|
-
return this.authenticationType;
|
|
28
|
-
}
|
|
29
|
-
return this.authenticationType != null;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Gets the value of a claim by its type.
|
|
33
|
-
* @param claimType The type of the claim to retrieve.
|
|
34
|
-
* @returns The value of the claim, or null if the claim is not found.
|
|
35
|
-
*/
|
|
36
|
-
getClaimValue(claimType) {
|
|
37
|
-
var _a;
|
|
38
|
-
const claim = this.claims.find((c) => c.type === claimType);
|
|
39
|
-
return (_a = claim === null || claim === void 0 ? void 0 : claim.value) !== null && _a !== void 0 ? _a : null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.ClaimsIdentity = ClaimsIdentity;
|
|
43
|
-
//# sourceMappingURL=claimsIdentity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claimsIdentity.js","sourceRoot":"","sources":["../../src/claimsIdentity.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH;;GAEG;AACH,MAAa,cAAc;IACzB;;;;OAIG;IACH,YAA6B,MAAe,EAAmB,kBAAqC;QAAvE,WAAM,GAAN,MAAM,CAAS;QAAmB,uBAAkB,GAAlB,kBAAkB,CAAmB;IAAG,CAAC;IAExG;;;OAGG;IACH,IAAI,eAAe;QACjB,IAAI,OAAO,IAAI,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;YACjD,OAAO,IAAI,CAAC,kBAAkB,CAAA;QAChC,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAE,SAAiB;;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;QAE3D,OAAO,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,mCAAI,IAAI,CAAA;IAC7B,CAAC;CACF;AA9BD,wCA8BC"}
|