@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,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { AuthorizationHandlerStatus, AuthorizationHandler, ActiveAuthorizationHandler, AuthorizationHandlerSettings, AuthorizationHandlerTokenOptions } from '../types';
|
|
6
|
+
import { TurnContext } from '../../../turnContext';
|
|
7
|
+
import { TokenResponse } from '../../../oauth';
|
|
8
|
+
declare enum Category {
|
|
9
|
+
SIGNIN = "signin",
|
|
10
|
+
UNKNOWN = "unknown"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Active handler manager information.
|
|
14
|
+
*/
|
|
15
|
+
export interface AzureBotActiveHandler extends ActiveAuthorizationHandler {
|
|
16
|
+
/**
|
|
17
|
+
* The number of attempts left for the handler to process in case of failure.
|
|
18
|
+
*/
|
|
19
|
+
attemptsLeft: number;
|
|
20
|
+
/**
|
|
21
|
+
* The current category of the handler.
|
|
22
|
+
*/
|
|
23
|
+
category?: Category;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Messages configuration for the AzureBotAuthorization handler.
|
|
27
|
+
*/
|
|
28
|
+
export interface AzureBotAuthorizationOptionsMessages {
|
|
29
|
+
/**
|
|
30
|
+
* Message displayed when an invalid code is entered.
|
|
31
|
+
* Use `{code}` as a placeholder for the entered code.
|
|
32
|
+
* Defaults to: 'The code entered is invalid. Please sign-in again to continue.'
|
|
33
|
+
*/
|
|
34
|
+
invalidCode?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Message displayed when the entered code format is invalid.
|
|
37
|
+
* Use `{attemptsLeft}` as a placeholder for the number of attempts left.
|
|
38
|
+
* Defaults to: 'Please enter a valid **6-digit** code format (_e.g. 123456_).\r\n**{attemptsLeft} attempt(s) left...**'
|
|
39
|
+
*/
|
|
40
|
+
invalidCodeFormat?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Message displayed when the maximum number of attempts is exceeded.
|
|
43
|
+
* Use `{maxAttempts}` as a placeholder for the maximum number of attempts.
|
|
44
|
+
* Defaults to: 'You have exceeded the maximum number of sign-in attempts ({maxAttempts}).'
|
|
45
|
+
*/
|
|
46
|
+
maxAttemptsExceeded?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Settings for on-behalf-of token acquisition.
|
|
50
|
+
*/
|
|
51
|
+
export interface AzureBotAuthorizationOptionsOBO {
|
|
52
|
+
/**
|
|
53
|
+
* Connection name to use for on-behalf-of token acquisition.
|
|
54
|
+
*/
|
|
55
|
+
connection?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Scopes to request for on-behalf-of token acquisition.
|
|
58
|
+
*/
|
|
59
|
+
scopes?: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Interface defining an authorization handler configuration.
|
|
63
|
+
*/
|
|
64
|
+
export interface AzureBotAuthorizationOptions {
|
|
65
|
+
/**
|
|
66
|
+
* The type of authorization handler.
|
|
67
|
+
* This property is optional and should not be set when configuring this handler.
|
|
68
|
+
* It is included here for completeness and type safety.
|
|
69
|
+
*/
|
|
70
|
+
type?: undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Connection name for the auth provider.
|
|
73
|
+
* @remarks
|
|
74
|
+
* When using environment variables, this can be set using the `${authHandlerId}_connectionName` variable.
|
|
75
|
+
*/
|
|
76
|
+
name?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Title to display on auth cards/UI.
|
|
79
|
+
* @remarks
|
|
80
|
+
* When using environment variables, this can be set using the `${authHandlerId}_connectionTitle` variable.
|
|
81
|
+
*/
|
|
82
|
+
title?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Text to display on auth cards/UI.
|
|
85
|
+
* @remarks
|
|
86
|
+
* When using environment variables, this can be set using the `${authHandlerId}_connectionText` variable.
|
|
87
|
+
*/
|
|
88
|
+
text?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Maximum number of attempts for entering the magic code. Defaults to 2.
|
|
91
|
+
* @remarks
|
|
92
|
+
* When using environment variables, this can be set using the `${authHandlerId}_maxAttempts` variable.
|
|
93
|
+
*/
|
|
94
|
+
maxAttempts?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Messages to display for various authentication scenarios.
|
|
97
|
+
* @remarks
|
|
98
|
+
* When using environment variables, these can be set using the following variables:
|
|
99
|
+
* - `${authHandlerId}_messages_invalidCode`
|
|
100
|
+
* - `${authHandlerId}_messages_invalidCodeFormat`
|
|
101
|
+
* - `${authHandlerId}_messages_maxAttemptsExceeded`
|
|
102
|
+
*/
|
|
103
|
+
messages?: AzureBotAuthorizationOptionsMessages;
|
|
104
|
+
/**
|
|
105
|
+
* Settings for on-behalf-of token acquisition.
|
|
106
|
+
* @remarks
|
|
107
|
+
* When using environment variables, these can be set using the following variables:
|
|
108
|
+
* - `${authHandlerId}_obo_connection`
|
|
109
|
+
* - `${authHandlerId}_obo_scopes` (comma-separated values, e.g. `scope1,scope2`)
|
|
110
|
+
*/
|
|
111
|
+
obo?: AzureBotAuthorizationOptionsOBO;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Settings for configuring the AzureBot authorization handler.
|
|
115
|
+
*/
|
|
116
|
+
export interface AzureBotAuthorizationSettings extends AuthorizationHandlerSettings {
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Default implementation of an authorization handler using Azure Bot Service.
|
|
120
|
+
*/
|
|
121
|
+
export declare class AzureBotAuthorization implements AuthorizationHandler {
|
|
122
|
+
readonly id: string;
|
|
123
|
+
private settings;
|
|
124
|
+
private _options;
|
|
125
|
+
private _onSuccess?;
|
|
126
|
+
private _onFailure?;
|
|
127
|
+
/**
|
|
128
|
+
* Creates an instance of the AzureBotAuthorization.
|
|
129
|
+
* @param id The unique identifier for the handler.
|
|
130
|
+
* @param options The settings for the handler.
|
|
131
|
+
* @param app The agent application instance.
|
|
132
|
+
*/
|
|
133
|
+
constructor(id: string, options: AzureBotAuthorizationOptions, settings: AzureBotAuthorizationSettings);
|
|
134
|
+
/**
|
|
135
|
+
* Loads and validates the authorization handler options.
|
|
136
|
+
*/
|
|
137
|
+
private loadOptions;
|
|
138
|
+
/**
|
|
139
|
+
* Maximum number of attempts for magic code entry.
|
|
140
|
+
*/
|
|
141
|
+
private get maxAttempts();
|
|
142
|
+
/**
|
|
143
|
+
* Sets a handler to be called when a user successfully signs in.
|
|
144
|
+
* @param callback The callback function to be invoked on successful sign-in.
|
|
145
|
+
*/
|
|
146
|
+
onSuccess(callback: (context: TurnContext) => Promise<void> | void): void;
|
|
147
|
+
/**
|
|
148
|
+
* Sets a handler to be called when a user fails to sign in.
|
|
149
|
+
* @param callback The callback function to be invoked on sign-in failure.
|
|
150
|
+
*/
|
|
151
|
+
onFailure(callback: (context: TurnContext, reason?: string) => Promise<void> | void): void;
|
|
152
|
+
/**
|
|
153
|
+
* Retrieves the token for the user, optionally using on-behalf-of flow for specified scopes.
|
|
154
|
+
* @param context The turn context.
|
|
155
|
+
* @param options Optional options for token acquisition, including connection and scopes for on-behalf-of flow.
|
|
156
|
+
* @returns The token response containing the token or undefined if not available.
|
|
157
|
+
*/
|
|
158
|
+
token(context: TurnContext, options?: AuthorizationHandlerTokenOptions): Promise<TokenResponse>;
|
|
159
|
+
/**
|
|
160
|
+
* Signs out the user from the service.
|
|
161
|
+
* @param context The turn context.
|
|
162
|
+
* @returns True if the signout was successful, false otherwise.
|
|
163
|
+
*/
|
|
164
|
+
signout(context: TurnContext): Promise<boolean>;
|
|
165
|
+
/**
|
|
166
|
+
* Initiates the sign-in process for the handler.
|
|
167
|
+
* @param context The turn context.
|
|
168
|
+
* @param active Optional active handler data.
|
|
169
|
+
* @returns The status of the sign-in attempt.
|
|
170
|
+
*/
|
|
171
|
+
signin(context: TurnContext, active?: AzureBotActiveHandler): Promise<AuthorizationHandlerStatus>;
|
|
172
|
+
/**
|
|
173
|
+
* Handles on-behalf-of token acquisition.
|
|
174
|
+
*/
|
|
175
|
+
private handleOBO;
|
|
176
|
+
/**
|
|
177
|
+
* Checks if a token is exchangeable for an on-behalf-of flow.
|
|
178
|
+
*/
|
|
179
|
+
private isExchangeable;
|
|
180
|
+
/**
|
|
181
|
+
* Sets the token from the token response or initiates the sign-in flow.
|
|
182
|
+
*/
|
|
183
|
+
private setToken;
|
|
184
|
+
/**
|
|
185
|
+
* Handles sign-in related activities.
|
|
186
|
+
*/
|
|
187
|
+
private handleSignInActivities;
|
|
188
|
+
/**
|
|
189
|
+
* Verifies the magic code provided by the user.
|
|
190
|
+
*/
|
|
191
|
+
private codeVerification;
|
|
192
|
+
private _key;
|
|
193
|
+
/**
|
|
194
|
+
* Sets the authorization context in the turn state.
|
|
195
|
+
*/
|
|
196
|
+
private setContext;
|
|
197
|
+
/**
|
|
198
|
+
* Gets the authorization context from the turn state.
|
|
199
|
+
*/
|
|
200
|
+
private getContext;
|
|
201
|
+
/**
|
|
202
|
+
* Gets the user token client from the turn context.
|
|
203
|
+
*/
|
|
204
|
+
private getUserTokenClient;
|
|
205
|
+
/**
|
|
206
|
+
* Sends an InvokeResponse activity if the channel is Microsoft Teams.
|
|
207
|
+
*/
|
|
208
|
+
private sendInvokeResponse;
|
|
209
|
+
/**
|
|
210
|
+
* Prefixes a message with the handler ID.
|
|
211
|
+
*/
|
|
212
|
+
private prefix;
|
|
213
|
+
/**
|
|
214
|
+
* Predefined messages with dynamic placeholders.
|
|
215
|
+
*/
|
|
216
|
+
private messages;
|
|
217
|
+
/**
|
|
218
|
+
* Loads the OAuth scopes from the environment variables.
|
|
219
|
+
*/
|
|
220
|
+
private loadScopes;
|
|
221
|
+
}
|
|
222
|
+
export {};
|
|
@@ -0,0 +1,428 @@
|
|
|
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.AzureBotAuthorization = void 0;
|
|
11
|
+
const logger_1 = require("@microsoft/agents-activity/logger");
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
const messageFactory_1 = require("../../../messageFactory");
|
|
14
|
+
const cards_1 = require("../../../cards");
|
|
15
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
16
|
+
const handlerStorage_1 = require("../handlerStorage");
|
|
17
|
+
const agents_activity_1 = require("@microsoft/agents-activity");
|
|
18
|
+
const logger = (0, logger_1.debug)('agents:authorization:azurebot');
|
|
19
|
+
const DEFAULT_SIGN_IN_ATTEMPTS = 2;
|
|
20
|
+
var Category;
|
|
21
|
+
(function (Category) {
|
|
22
|
+
Category["SIGNIN"] = "signin";
|
|
23
|
+
Category["UNKNOWN"] = "unknown";
|
|
24
|
+
})(Category || (Category = {}));
|
|
25
|
+
/**
|
|
26
|
+
* Default implementation of an authorization handler using Azure Bot Service.
|
|
27
|
+
*/
|
|
28
|
+
class AzureBotAuthorization {
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of the AzureBotAuthorization.
|
|
31
|
+
* @param id The unique identifier for the handler.
|
|
32
|
+
* @param options The settings for the handler.
|
|
33
|
+
* @param app The agent application instance.
|
|
34
|
+
*/
|
|
35
|
+
constructor(id, options, settings) {
|
|
36
|
+
this.id = id;
|
|
37
|
+
this.settings = settings;
|
|
38
|
+
this._key = `${AzureBotAuthorization.name}/${this.id}`;
|
|
39
|
+
/**
|
|
40
|
+
* Predefined messages with dynamic placeholders.
|
|
41
|
+
*/
|
|
42
|
+
this.messages = {
|
|
43
|
+
invalidCode: (code) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const message = (_b = (_a = this._options.messages) === null || _a === void 0 ? void 0 : _a.invalidCode) !== null && _b !== void 0 ? _b : 'Invalid **{code}** code entered. Please try again with a new sign-in request.';
|
|
46
|
+
return message.replaceAll('{code}', code);
|
|
47
|
+
},
|
|
48
|
+
invalidCodeFormat: (attemptsLeft) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const message = (_b = (_a = this._options.messages) === null || _a === void 0 ? void 0 : _a.invalidCodeFormat) !== null && _b !== void 0 ? _b : 'Please enter a valid **6-digit** code format (_e.g. 123456_).\r\n**{attemptsLeft} attempt(s) left...**';
|
|
51
|
+
return message.replaceAll('{attemptsLeft}', attemptsLeft.toString());
|
|
52
|
+
},
|
|
53
|
+
maxAttemptsExceeded: (maxAttempts) => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const message = (_b = (_a = this._options.messages) === null || _a === void 0 ? void 0 : _a.maxAttemptsExceeded) !== null && _b !== void 0 ? _b : 'You have exceeded the maximum number of sign-in attempts ({maxAttempts}). Please try again with a new sign-in request.';
|
|
56
|
+
return message.replaceAll('{maxAttempts}', maxAttempts.toString());
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
if (!this.settings.storage) {
|
|
60
|
+
throw new Error(this.prefix('The \'storage\' option is not available in the app options. Ensure that the app is properly configured.'));
|
|
61
|
+
}
|
|
62
|
+
if (!this.settings.connections) {
|
|
63
|
+
throw new Error(this.prefix('The \'connections\' option is not available in the app options. Ensure that the app is properly configured.'));
|
|
64
|
+
}
|
|
65
|
+
this._options = this.loadOptions(options);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Loads and validates the authorization handler options.
|
|
69
|
+
*/
|
|
70
|
+
loadOptions(settings) {
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
72
|
+
const result = {
|
|
73
|
+
name: (_a = settings.name) !== null && _a !== void 0 ? _a : (process.env[`${this.id}_connectionName`]),
|
|
74
|
+
title: (_c = (_b = settings.title) !== null && _b !== void 0 ? _b : (process.env[`${this.id}_connectionTitle`])) !== null && _c !== void 0 ? _c : 'Sign-in',
|
|
75
|
+
text: (_e = (_d = settings.text) !== null && _d !== void 0 ? _d : (process.env[`${this.id}_connectionText`])) !== null && _e !== void 0 ? _e : 'Please sign-in to continue',
|
|
76
|
+
maxAttempts: (_f = settings.maxAttempts) !== null && _f !== void 0 ? _f : parseInt(process.env[`${this.id}_maxAttempts`]),
|
|
77
|
+
messages: {
|
|
78
|
+
invalidCode: (_h = (_g = settings.messages) === null || _g === void 0 ? void 0 : _g.invalidCode) !== null && _h !== void 0 ? _h : process.env[`${this.id}_messages_invalidCode`],
|
|
79
|
+
invalidCodeFormat: (_k = (_j = settings.messages) === null || _j === void 0 ? void 0 : _j.invalidCodeFormat) !== null && _k !== void 0 ? _k : process.env[`${this.id}_messages_invalidCodeFormat`],
|
|
80
|
+
maxAttemptsExceeded: (_m = (_l = settings.messages) === null || _l === void 0 ? void 0 : _l.maxAttemptsExceeded) !== null && _m !== void 0 ? _m : process.env[`${this.id}_messages_maxAttemptsExceeded`],
|
|
81
|
+
},
|
|
82
|
+
obo: {
|
|
83
|
+
connection: (_p = (_o = settings.obo) === null || _o === void 0 ? void 0 : _o.connection) !== null && _p !== void 0 ? _p : process.env[`${this.id}_obo_connection`],
|
|
84
|
+
scopes: (_r = (_q = settings.obo) === null || _q === void 0 ? void 0 : _q.scopes) !== null && _r !== void 0 ? _r : this.loadScopes(process.env[`${this.id}_obo_scopes`]),
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
if (!result.name) {
|
|
88
|
+
throw new Error(this.prefix(`The 'name' property or '${this.id}_connectionName' env variable is required to initialize the handler.`));
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Maximum number of attempts for magic code entry.
|
|
94
|
+
*/
|
|
95
|
+
get maxAttempts() {
|
|
96
|
+
const attempts = this._options.maxAttempts;
|
|
97
|
+
const result = typeof attempts === 'number' && Number.isFinite(attempts) ? Math.round(attempts) : NaN;
|
|
98
|
+
return result > 0 ? result : DEFAULT_SIGN_IN_ATTEMPTS;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sets a handler to be called when a user successfully signs in.
|
|
102
|
+
* @param callback The callback function to be invoked on successful sign-in.
|
|
103
|
+
*/
|
|
104
|
+
onSuccess(callback) {
|
|
105
|
+
this._onSuccess = callback;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Sets a handler to be called when a user fails to sign in.
|
|
109
|
+
* @param callback The callback function to be invoked on sign-in failure.
|
|
110
|
+
*/
|
|
111
|
+
onFailure(callback) {
|
|
112
|
+
this._onFailure = callback;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Retrieves the token for the user, optionally using on-behalf-of flow for specified scopes.
|
|
116
|
+
* @param context The turn context.
|
|
117
|
+
* @param options Optional options for token acquisition, including connection and scopes for on-behalf-of flow.
|
|
118
|
+
* @returns The token response containing the token or undefined if not available.
|
|
119
|
+
*/
|
|
120
|
+
async token(context, options) {
|
|
121
|
+
var _a;
|
|
122
|
+
let { token } = this.getContext(context);
|
|
123
|
+
if (!(token === null || token === void 0 ? void 0 : token.trim())) {
|
|
124
|
+
const { activity } = context;
|
|
125
|
+
const userTokenClient = await this.getUserTokenClient(context);
|
|
126
|
+
// Using getTokenOrSignInResource instead of getUserToken to avoid HTTP 404 errors.
|
|
127
|
+
const { tokenResponse } = await userTokenClient.getTokenOrSignInResource((_a = activity.from) === null || _a === void 0 ? void 0 : _a.id, this._options.name, activity.channelId, activity.getConversationReference(), activity.relatesTo, '');
|
|
128
|
+
token = tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.token;
|
|
129
|
+
}
|
|
130
|
+
if (!(token === null || token === void 0 ? void 0 : token.trim())) {
|
|
131
|
+
return { token: undefined };
|
|
132
|
+
}
|
|
133
|
+
return await this.handleOBO(token, options);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Signs out the user from the service.
|
|
137
|
+
* @param context The turn context.
|
|
138
|
+
* @returns True if the signout was successful, false otherwise.
|
|
139
|
+
*/
|
|
140
|
+
async signout(context) {
|
|
141
|
+
var _a;
|
|
142
|
+
const user = (_a = context.activity.from) === null || _a === void 0 ? void 0 : _a.id;
|
|
143
|
+
const channel = context.activity.channelId;
|
|
144
|
+
const connection = this._options.name;
|
|
145
|
+
if (!channel || !user) {
|
|
146
|
+
throw new Error(this.prefix('Both \'activity.channelId\' and \'activity.from.id\' are required to perform signout.'));
|
|
147
|
+
}
|
|
148
|
+
logger.debug(this.prefix(`Signing out User '${user}' from => Channel: '${channel}', Connection: '${connection}'`), context.activity);
|
|
149
|
+
const userTokenClient = await this.getUserTokenClient(context);
|
|
150
|
+
await userTokenClient.signOut(user, connection, channel);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Initiates the sign-in process for the handler.
|
|
155
|
+
* @param context The turn context.
|
|
156
|
+
* @param active Optional active handler data.
|
|
157
|
+
* @returns The status of the sign-in attempt.
|
|
158
|
+
*/
|
|
159
|
+
async signin(context, active) {
|
|
160
|
+
var _a, _b, _c, _d, _e;
|
|
161
|
+
const { activity } = context;
|
|
162
|
+
const [category] = (_b = (_a = activity.name) === null || _a === void 0 ? void 0 : _a.split('/')) !== null && _b !== void 0 ? _b : [Category.UNKNOWN];
|
|
163
|
+
const storage = new handlerStorage_1.HandlerStorage(this.settings.storage, context);
|
|
164
|
+
if (!active) {
|
|
165
|
+
return this.setToken(storage, context);
|
|
166
|
+
}
|
|
167
|
+
logger.debug(this.prefix('Sign-in active session detected'), active.activity);
|
|
168
|
+
if (((_c = active.activity.conversation) === null || _c === void 0 ? void 0 : _c.id) !== ((_d = activity.conversation) === null || _d === void 0 ? void 0 : _d.id)) {
|
|
169
|
+
await this.sendInvokeResponse(context, { status: 400 });
|
|
170
|
+
logger.warn(this.prefix('Discarding the active session due to the conversation has changed during an active sign-in process'), activity);
|
|
171
|
+
return types_1.AuthorizationHandlerStatus.IGNORED;
|
|
172
|
+
}
|
|
173
|
+
if (active.attemptsLeft <= 0) {
|
|
174
|
+
logger.warn(this.prefix('Maximum sign-in attempts exceeded'), activity);
|
|
175
|
+
await context.sendActivity(messageFactory_1.MessageFactory.text(this.messages.maxAttemptsExceeded(this.maxAttempts)));
|
|
176
|
+
return types_1.AuthorizationHandlerStatus.REJECTED;
|
|
177
|
+
}
|
|
178
|
+
if (category === Category.SIGNIN) {
|
|
179
|
+
await storage.write({ ...active, category });
|
|
180
|
+
const status = await this.handleSignInActivities(context);
|
|
181
|
+
if (status !== types_1.AuthorizationHandlerStatus.IGNORED) {
|
|
182
|
+
return status;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (active.category === Category.SIGNIN) {
|
|
186
|
+
// This is only for safety in case of unexpected behaviors during the MS Teams sign-in process,
|
|
187
|
+
// e.g., user interrupts the flow by clicking the Consent Cancel button.
|
|
188
|
+
logger.warn(this.prefix('The incoming activity will be revalidated due to a change in the sign-in flow'), activity);
|
|
189
|
+
return types_1.AuthorizationHandlerStatus.REVALIDATE;
|
|
190
|
+
}
|
|
191
|
+
const { status, code } = await this.codeVerification(storage, context, active);
|
|
192
|
+
if (status !== types_1.AuthorizationHandlerStatus.APPROVED) {
|
|
193
|
+
return status;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const result = await this.setToken(storage, context, active, code);
|
|
197
|
+
if (result !== types_1.AuthorizationHandlerStatus.APPROVED) {
|
|
198
|
+
await this.sendInvokeResponse(context, { status: 404 });
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
await this.sendInvokeResponse(context, { status: 200 });
|
|
202
|
+
await ((_e = this._onSuccess) === null || _e === void 0 ? void 0 : _e.call(this, context));
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
await this.sendInvokeResponse(context, { status: 500 });
|
|
207
|
+
if (error instanceof Error) {
|
|
208
|
+
error.message = this.prefix(error.message);
|
|
209
|
+
}
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Handles on-behalf-of token acquisition.
|
|
215
|
+
*/
|
|
216
|
+
async handleOBO(token, options) {
|
|
217
|
+
var _a, _b, _c;
|
|
218
|
+
const oboConnection = (_a = options === null || options === void 0 ? void 0 : options.connection) !== null && _a !== void 0 ? _a : (_b = this._options.obo) === null || _b === void 0 ? void 0 : _b.connection;
|
|
219
|
+
const oboScopes = (options === null || options === void 0 ? void 0 : options.scopes) && options.scopes.length > 0 ? options.scopes : (_c = this._options.obo) === null || _c === void 0 ? void 0 : _c.scopes;
|
|
220
|
+
if (!oboScopes || oboScopes.length === 0) {
|
|
221
|
+
return { token };
|
|
222
|
+
}
|
|
223
|
+
if (!this.isExchangeable(token)) {
|
|
224
|
+
throw new Error(this.prefix('The current token is not exchangeable for an on-behalf-of flow. Ensure the token audience starts with \'api://\'.'));
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
const provider = oboConnection ? this.settings.connections.getConnection(oboConnection) : this.settings.connections.getDefaultConnection();
|
|
228
|
+
const newToken = await provider.acquireTokenOnBehalfOf(oboScopes, token);
|
|
229
|
+
logger.debug(this.prefix('Successfully acquired on-behalf-of token'), { connection: oboConnection, scopes: oboScopes });
|
|
230
|
+
return { token: newToken };
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
logger.error(this.prefix('Failed to exchange on-behalf-of token'), { connection: oboConnection, scopes: oboScopes }, error);
|
|
234
|
+
return { token: undefined };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Checks if a token is exchangeable for an on-behalf-of flow.
|
|
239
|
+
*/
|
|
240
|
+
isExchangeable(token) {
|
|
241
|
+
if (!token || typeof token !== 'string') {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
const payload = jsonwebtoken_1.default.decode(token);
|
|
245
|
+
const audiences = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
|
246
|
+
return audiences.some(aud => typeof aud === 'string' && aud.startsWith('api://'));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Sets the token from the token response or initiates the sign-in flow.
|
|
250
|
+
*/
|
|
251
|
+
async setToken(storage, context, active, code) {
|
|
252
|
+
var _a;
|
|
253
|
+
const { activity } = context;
|
|
254
|
+
const userTokenClient = await this.getUserTokenClient(context);
|
|
255
|
+
const { tokenResponse, signInResource } = await userTokenClient.getTokenOrSignInResource((_a = activity.from) === null || _a === void 0 ? void 0 : _a.id, this._options.name, activity.channelId, activity.getConversationReference(), activity.relatesTo, code !== null && code !== void 0 ? code : '');
|
|
256
|
+
if (!tokenResponse && active) {
|
|
257
|
+
logger.warn(this.prefix('Invalid code entered. Restarting sign-in flow'), activity);
|
|
258
|
+
await context.sendActivity(messageFactory_1.MessageFactory.text(this.messages.invalidCode(code !== null && code !== void 0 ? code : '')));
|
|
259
|
+
return types_1.AuthorizationHandlerStatus.REJECTED;
|
|
260
|
+
}
|
|
261
|
+
if (!tokenResponse) {
|
|
262
|
+
logger.debug(this.prefix('Cannot find token. Sending sign-in card'), activity);
|
|
263
|
+
const oCard = cards_1.CardFactory.oauthCard(this._options.name, this._options.title, this._options.text, signInResource);
|
|
264
|
+
await context.sendActivity(messageFactory_1.MessageFactory.attachment(oCard));
|
|
265
|
+
await storage.write({ activity, id: this.id, ...(active !== null && active !== void 0 ? active : {}), attemptsLeft: this.maxAttempts });
|
|
266
|
+
return types_1.AuthorizationHandlerStatus.PENDING;
|
|
267
|
+
}
|
|
268
|
+
logger.debug(this.prefix('Successfully acquired token'), activity);
|
|
269
|
+
this.setContext(context, { token: tokenResponse.token });
|
|
270
|
+
return types_1.AuthorizationHandlerStatus.APPROVED;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Handles sign-in related activities.
|
|
274
|
+
*/
|
|
275
|
+
async handleSignInActivities(context) {
|
|
276
|
+
var _a, _b, _c, _d;
|
|
277
|
+
const { activity } = context;
|
|
278
|
+
// Ignore signin/verifyState here (handled in codeVerification).
|
|
279
|
+
if (activity.name === 'signin/verifyState') {
|
|
280
|
+
return types_1.AuthorizationHandlerStatus.IGNORED;
|
|
281
|
+
}
|
|
282
|
+
const userTokenClient = await this.getUserTokenClient(context);
|
|
283
|
+
if (activity.name === 'signin/tokenExchange') {
|
|
284
|
+
const tokenExchangeInvokeRequest = activity.value;
|
|
285
|
+
const tokenExchangeRequest = { token: tokenExchangeInvokeRequest.token };
|
|
286
|
+
if (!(tokenExchangeRequest === null || tokenExchangeRequest === void 0 ? void 0 : tokenExchangeRequest.token)) {
|
|
287
|
+
const reason = 'The Agent received an InvokeActivity that is missing a TokenExchangeInvokeRequest value. This is required to be sent with the InvokeActivity.';
|
|
288
|
+
await this.sendInvokeResponse(context, {
|
|
289
|
+
status: 400,
|
|
290
|
+
body: { connectionName: this._options.name, failureDetail: reason }
|
|
291
|
+
});
|
|
292
|
+
logger.error(this.prefix(reason));
|
|
293
|
+
await ((_a = this._onFailure) === null || _a === void 0 ? void 0 : _a.call(this, context, reason));
|
|
294
|
+
return types_1.AuthorizationHandlerStatus.REJECTED;
|
|
295
|
+
}
|
|
296
|
+
if (tokenExchangeInvokeRequest.connectionName !== this._options.name) {
|
|
297
|
+
const reason = `The Agent received an InvokeActivity with a TokenExchangeInvokeRequest for a different connection name ('${tokenExchangeInvokeRequest.connectionName}') than expected ('${this._options.name}').`;
|
|
298
|
+
await this.sendInvokeResponse(context, {
|
|
299
|
+
status: 400,
|
|
300
|
+
body: { id: tokenExchangeInvokeRequest.id, connectionName: this._options.name, failureDetail: reason }
|
|
301
|
+
});
|
|
302
|
+
logger.error(this.prefix(reason));
|
|
303
|
+
await ((_b = this._onFailure) === null || _b === void 0 ? void 0 : _b.call(this, context, reason));
|
|
304
|
+
return types_1.AuthorizationHandlerStatus.REJECTED;
|
|
305
|
+
}
|
|
306
|
+
const { token } = await userTokenClient.exchangeTokenAsync((_c = activity.from) === null || _c === void 0 ? void 0 : _c.id, this._options.name, activity.channelId, tokenExchangeRequest);
|
|
307
|
+
if (!token) {
|
|
308
|
+
const reason = 'The MS Teams token service didn\'t send back the exchanged token. Waiting for MS Teams to send another signin/tokenExchange request. After multiple failed attempts, the user will be asked to enter the magic code.';
|
|
309
|
+
await this.sendInvokeResponse(context, {
|
|
310
|
+
status: 412,
|
|
311
|
+
body: { id: tokenExchangeInvokeRequest.id, connectionName: this._options.name, failureDetail: reason }
|
|
312
|
+
});
|
|
313
|
+
logger.debug(this.prefix(reason));
|
|
314
|
+
return types_1.AuthorizationHandlerStatus.PENDING;
|
|
315
|
+
}
|
|
316
|
+
await this.sendInvokeResponse(context, {
|
|
317
|
+
status: 200,
|
|
318
|
+
body: { id: tokenExchangeInvokeRequest.id, connectionName: this._options.name }
|
|
319
|
+
});
|
|
320
|
+
logger.debug(this.prefix('Successfully exchanged token'));
|
|
321
|
+
this.setContext(context, { token });
|
|
322
|
+
await ((_d = this._onSuccess) === null || _d === void 0 ? void 0 : _d.call(this, context));
|
|
323
|
+
return types_1.AuthorizationHandlerStatus.APPROVED;
|
|
324
|
+
}
|
|
325
|
+
if (activity.name === 'signin/failure') {
|
|
326
|
+
await this.sendInvokeResponse(context, { status: 200 });
|
|
327
|
+
const reason = 'Failed to sign-in';
|
|
328
|
+
const value = activity.value;
|
|
329
|
+
logger.error(this.prefix(reason), value, activity);
|
|
330
|
+
if (this._onFailure) {
|
|
331
|
+
await this._onFailure(context, value.message || reason);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
await context.sendActivity(messageFactory_1.MessageFactory.text(`${reason}. Please try again.`));
|
|
335
|
+
}
|
|
336
|
+
return types_1.AuthorizationHandlerStatus.REJECTED;
|
|
337
|
+
}
|
|
338
|
+
logger.error(this.prefix(`Unknown sign-in activity name: ${activity.name}`), activity);
|
|
339
|
+
return types_1.AuthorizationHandlerStatus.REJECTED;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Verifies the magic code provided by the user.
|
|
343
|
+
*/
|
|
344
|
+
async codeVerification(storage, context, active) {
|
|
345
|
+
if (!active) {
|
|
346
|
+
logger.debug(this.prefix('No active session found. Skipping code verification.'), context.activity);
|
|
347
|
+
return { status: types_1.AuthorizationHandlerStatus.IGNORED };
|
|
348
|
+
}
|
|
349
|
+
const { activity } = context;
|
|
350
|
+
let state = activity.text;
|
|
351
|
+
if (activity.name === 'signin/verifyState') {
|
|
352
|
+
logger.debug(this.prefix('Getting code from activity.value'), activity);
|
|
353
|
+
const { state: teamsState } = activity.value;
|
|
354
|
+
state = teamsState;
|
|
355
|
+
}
|
|
356
|
+
if (state === 'CancelledByUser') {
|
|
357
|
+
await this.sendInvokeResponse(context, { status: 200 });
|
|
358
|
+
logger.warn(this.prefix('Sign-in process was cancelled by the user'), activity);
|
|
359
|
+
return { status: types_1.AuthorizationHandlerStatus.REJECTED };
|
|
360
|
+
}
|
|
361
|
+
if (!(state === null || state === void 0 ? void 0 : state.match(/^\d{6}$/))) {
|
|
362
|
+
logger.warn(this.prefix(`Invalid magic code entered. Attempts left: ${active.attemptsLeft}`), activity);
|
|
363
|
+
await context.sendActivity(messageFactory_1.MessageFactory.text(this.messages.invalidCodeFormat(active.attemptsLeft)));
|
|
364
|
+
await storage.write({ ...active, attemptsLeft: active.attemptsLeft - 1 });
|
|
365
|
+
return { status: types_1.AuthorizationHandlerStatus.PENDING };
|
|
366
|
+
}
|
|
367
|
+
await this.sendInvokeResponse(context, { status: 200 });
|
|
368
|
+
logger.debug(this.prefix('Code verification successful'), activity);
|
|
369
|
+
return { status: types_1.AuthorizationHandlerStatus.APPROVED, code: state };
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Sets the authorization context in the turn state.
|
|
373
|
+
*/
|
|
374
|
+
setContext(context, data) {
|
|
375
|
+
return context.turnState.set(this._key, () => data);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Gets the authorization context from the turn state.
|
|
379
|
+
*/
|
|
380
|
+
getContext(context) {
|
|
381
|
+
var _a;
|
|
382
|
+
const result = context.turnState.get(this._key);
|
|
383
|
+
return (_a = result === null || result === void 0 ? void 0 : result()) !== null && _a !== void 0 ? _a : { token: undefined };
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Gets the user token client from the turn context.
|
|
387
|
+
*/
|
|
388
|
+
async getUserTokenClient(context) {
|
|
389
|
+
const userTokenClient = context.turnState.get(context.adapter.UserTokenClientKey);
|
|
390
|
+
if (!userTokenClient) {
|
|
391
|
+
throw new Error(this.prefix('The \'userTokenClient\' is not available in the adapter. Ensure that the adapter supports user token operations.'));
|
|
392
|
+
}
|
|
393
|
+
return userTokenClient;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Sends an InvokeResponse activity if the channel is Microsoft Teams.
|
|
397
|
+
*/
|
|
398
|
+
sendInvokeResponse(context, response) {
|
|
399
|
+
if (context.activity.channelId !== agents_activity_1.Channels.Msteams) {
|
|
400
|
+
return Promise.resolve();
|
|
401
|
+
}
|
|
402
|
+
return context.sendActivity(agents_activity_1.Activity.fromObject({
|
|
403
|
+
type: agents_activity_1.ActivityTypes.InvokeResponse,
|
|
404
|
+
value: response
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Prefixes a message with the handler ID.
|
|
409
|
+
*/
|
|
410
|
+
prefix(message) {
|
|
411
|
+
return `[handler:${this.id}] ${message}`;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Loads the OAuth scopes from the environment variables.
|
|
415
|
+
*/
|
|
416
|
+
loadScopes(value) {
|
|
417
|
+
var _a;
|
|
418
|
+
return (_a = value === null || value === void 0 ? void 0 : value.split(',').reduce((acc, scope) => {
|
|
419
|
+
const trimmed = scope.trim();
|
|
420
|
+
if (trimmed) {
|
|
421
|
+
acc.push(trimmed);
|
|
422
|
+
}
|
|
423
|
+
return acc;
|
|
424
|
+
}, [])) !== null && _a !== void 0 ? _a : [];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
exports.AzureBotAuthorization = AzureBotAuthorization;
|
|
428
|
+
//# sourceMappingURL=azureBotAuthorization.js.map
|