@microsoft/teamsfx 0.3.0-alpha.def66483.0 → 0.3.0-rc.0

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.
@@ -1,871 +1,900 @@
1
- import { AccessToken } from '@azure/identity';
2
- import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
3
- import { Client } from '@microsoft/microsoft-graph-client';
4
- import { ConnectionConfig } from 'tedious';
5
- import { Dialog } from 'botbuilder-dialogs';
6
- import { DialogContext } from 'botbuilder-dialogs';
7
- import { DialogTurnResult } from 'botbuilder-dialogs';
8
- import { GetTokenOptions } from '@azure/identity';
9
- import { TokenCredential } from '@azure/identity';
10
- import { TokenResponse } from 'botframework-schema';
11
-
12
- /**
13
- * Authentication related configuration.
14
- * @beta
15
- */
16
- export declare interface AuthenticationConfiguration {
17
- /**
18
- * Hostname of AAD authority. Default value comes from M365_AUTHORITY_HOST environment variable.
19
- *
20
- * @readonly
21
- */
22
- readonly authorityHost?: string;
23
- /**
24
- * AAD tenant id, default value comes from M365_TENANT_ID environment variable.
25
- *
26
- * @readonly
27
- */
28
- readonly tenantId?: string;
29
- /**
30
- * The client (application) ID of an App Registration in the tenant, default value comes from M365_CLIENT_ID environment variable
31
- *
32
- * @readonly
33
- */
34
- readonly clientId?: string;
35
- /**
36
- * Secret string that the application uses when requesting a token. Only used in confidential client applications. Can be created in the Azure app registration portal. Default value comes from M365_CLIENT_SECRET environment variable
37
- *
38
- * @readonly
39
- */
40
- readonly clientSecret?: string;
41
- /**
42
- * Endpoint of auth service provisioned by Teams Framework. Default value comes from SIMPLE_AUTH_ENDPOINT environment variable.
43
- *
44
- * @readonly
45
- */
46
- readonly simpleAuthEndpoint?: string;
47
- /**
48
- * Login page for Teams to redirect to. Default value comes from INITIATE_LOGIN_ENDPOINT environment variable.
49
- *
50
- * @readonly
51
- */
52
- readonly initiateLoginEndpoint?: string;
53
- /**
54
- * Application ID URI. Default value comes from M365_APPLICATION_ID_URI environment variable.
55
- */
56
- readonly applicationIdUri?: string;
57
- }
58
-
59
- /**
60
- * Configuration for current environment.
61
- * @beta
62
- */
63
- export declare interface Configuration {
64
- /**
65
- * Authentication related configuration.
66
- *
67
- * @readonly
68
- */
69
- readonly authentication?: AuthenticationConfiguration;
70
- /**
71
- * Configuration for resources.
72
- *
73
- * @readonly
74
- */
75
- readonly resources?: ResourceConfiguration[];
76
- }
77
-
78
- /**
79
- * Get Microsoft graph client.
80
- *
81
- * @example
82
- * Get Microsoft graph client by TokenCredential
83
- * ```typescript
84
- * // Sso token example (Azure Function)
85
- * const ssoToken = "YOUR_TOKEN_STRING";
86
- * const options = {"AAD_APP_ID", "AAD_APP_SECRET"};
87
- * const credential = new OnBehalfOfAADUserCredential(ssoToken, options);
88
- * const graphClient = await createMicrosoftGraphClient(credential);
89
- * const profile = await graphClient.api("/me").get();
90
- *
91
- * // TeamsBotSsoPrompt example (Bot Application)
92
- * const requiredScopes = ["User.Read"];
93
- * const config: Configuration = {
94
- * loginUrl: loginUrl,
95
- * clientId: clientId,
96
- * clientSecret: clientSecret,
97
- * tenantId: tenantId
98
- * };
99
- * const prompt = new TeamsBotSsoPrompt(dialogId, {
100
- * config: config
101
- * scopes: '["User.Read"],
102
- * });
103
- * this.addDialog(prompt);
104
- *
105
- * const oboCredential = new OnBehalfOfAADUserCredential(
106
- * getUserId(dialogContext),
107
- * {
108
- * clientId: "AAD_APP_ID",
109
- * clientSecret: "AAD_APP_SECRET"
110
- * });
111
- * try {
112
- * const graphClient = await createMicrosoftGraphClient(credential);
113
- * const profile = await graphClient.api("/me").get();
114
- * } catch (e) {
115
- * dialogContext.beginDialog(dialogId);
116
- * return Dialog.endOfTurn();
117
- * }
118
- * ```
119
- *
120
- * @param {TokenCredential} credential - token credential instance.
121
- * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
122
- *
123
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
124
- *
125
- * @returns Graph client with specified scopes.
126
- *
127
- * @beta
128
- */
129
- export declare function createMicrosoftGraphClient(credential: TokenCredential, scopes?: string | string[]): Client;
130
-
131
- /**
132
- * SQL connection configuration instance.
133
- * @remarks
134
- * Only works in in server side.
135
- *
136
- * @beta
137
- *
138
- */
139
- export declare class DefaultTediousConnectionConfiguration {
140
- /**
141
- * MSSQL default scope
142
- * https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi
143
- */
144
- private readonly defaultSQLScope;
145
- /**
146
- * Generate connection configuration consumed by tedious.
147
- *
148
- * @returns Connection configuration of tedious for the SQL.
149
- *
150
- * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
151
- * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
152
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
153
- *
154
- * @beta
155
- */
156
- getConfig(): Promise<ConnectionConfig>;
157
- /**
158
- * Check SQL use MSI identity or username and password.
159
- *
160
- * @returns false - login with SQL MSI identity, true - login with username and password.
161
- * @internal
162
- */
163
- private isMsiAuthentication;
164
- /**
165
- * check configuration is an available configurations.
166
- * @param { SqlConfiguration } sqlConfig
167
- *
168
- * @returns true - SQL configuration has a valid SQL endpoints, SQL username with password or identity ID.
169
- * false - configuration is not valid.
170
- * @internal
171
- */
172
- private isSQLConfigurationValid;
173
- /**
174
- * Generate tedious connection configuration with default authentication type.
175
- *
176
- * @param { SqlConfiguration } SQL configuration with username and password.
177
- *
178
- * @returns Tedious connection configuration with username and password.
179
- * @internal
180
- */
181
- private generateDefaultConfig;
182
- /**
183
- * Generate tedious connection configuration with azure-active-directory-access-token authentication type.
184
- *
185
- * @param { SqlConfiguration } SQL configuration with AAD access token.
186
- *
187
- * @returns Tedious connection configuration with access token.
188
- * @internal
189
- */
190
- private generateTokenConfig;
191
- }
192
-
193
- /**
194
- * Error code to trace the error types.
195
- * @beta
196
- */
197
- export declare enum ErrorCode {
198
- /**
199
- * Invalid parameter error.
200
- */
201
- InvalidParameter = "InvalidParameter",
202
- /**
203
- * Invalid configuration error.
204
- */
205
- InvalidConfiguration = "InvalidConfiguration",
206
- /**
207
- * Internal error.
208
- */
209
- InternalError = "InternalError",
210
- /**
211
- * Channel is not supported error.
212
- */
213
- ChannelNotSupported = "ChannelNotSupported",
214
- /**
215
- * Runtime is not supported error.
216
- */
217
- RuntimeNotSupported = "RuntimeNotSupported",
218
- /**
219
- * User failed to finish the AAD consent flow failed.
220
- */
221
- ConsentFailed = "ConsentFailed",
222
- /**
223
- * The user or administrator has not consented to use the application error.
224
- */
225
- UiRequiredError = "UiRequiredError",
226
- /**
227
- * Token is not within its valid time range error.
228
- */
229
- TokenExpiredError = "TokenExpiredError",
230
- /**
231
- * Call service (AAD or simple authentication server) failed.
232
- */
233
- ServiceError = "ServiceError",
234
- /**
235
- * Operation failed.
236
- */
237
- FailedOperation = "FailedOperation"
238
- }
239
-
240
- /**
241
- * Error class with code and message thrown by the SDK.
242
- *
243
- * @beta
244
- */
245
- export declare class ErrorWithCode extends Error {
246
- /**
247
- * Error code
248
- *
249
- * @readonly
250
- */
251
- code: string | undefined;
252
- /**
253
- * Constructor of ErrorWithCode.
254
- *
255
- * @param {string} message - error message.
256
- * @param {ErrorCode} code - error code.
257
- *
258
- * @beta
259
- */
260
- constructor(message?: string, code?: ErrorCode);
261
- }
262
-
263
- /**
264
- * Get configuration for authentication.
265
- *
266
- * @returns Authentication configuration from global configuration instance, the value may be undefined if no authentication config exists in current environment.
267
- *
268
- * @throws {@link ErrorCode|InvalidConfiguration} when global configuration does not exist
269
- *
270
- * @beta
271
- */
272
- export declare function getAuthenticationConfiguration(): AuthenticationConfiguration | undefined;
273
-
274
- /**
275
- * Get log level.
276
- *
277
- * @returns Log level
278
- *
279
- * @beta
280
- */
281
- export declare function getLogLevel(): LogLevel;
282
-
283
- /**
284
- * Get configuration for a specific resource.
285
- * @param {ResourceType} resourceType - The type of resource
286
- * @param {string} resourceName - The name of resource, default value is "default".
287
- *
288
- * @returns Resource configuration for target resource from global configuration instance.
289
- *
290
- * @throws {@link ErrorCode|InvalidConfiguration} when resource configuration with the specific type and name is not found
291
- *
292
- * @beta
293
- */
294
- export declare function getResourceConfiguration(resourceType: ResourceType, resourceName?: string): {
295
- [index: string]: any;
296
- };
297
- export { GetTokenOptions }
298
-
299
- /**
300
- * Initialize configuration from environment variables or configuration object and set the global instance
301
- *
302
- * @param {Configuration} configuration - Optional configuration that overrides the default configuration values. The override depth is 1.
303
- *
304
- * @throws {@link ErrorCode|InvalidParameter} when configuration is not passed in browser environment
305
- *
306
- * @beta
307
- */
308
- export declare function loadConfiguration(configuration?: Configuration): void;
309
-
310
- /**
311
- * Log function for customized logging.
312
- *
313
- * @beta
314
- */
315
- export declare type LogFunction = (level: LogLevel, message: string) => void;
316
-
317
- /**
318
- * Interface for customized logger.
319
- * @beta
320
- */
321
- export declare interface Logger {
322
- /**
323
- * Writes to error level logging or lower.
324
- */
325
- error(message: string): void;
326
- /**
327
- * Writes to warning level logging or lower.
328
- */
329
- warn(message: string): void;
330
- /**
331
- * Writes to info level logging or lower.
332
- */
333
- info(message: string): void;
334
- /**
335
- * Writes to verbose level logging.
336
- */
337
- verbose(message: string): void;
338
- }
339
-
340
- /**
341
- * Log level.
342
- *
343
- * @beta
344
- */
345
- export declare enum LogLevel {
346
- /**
347
- * Show verbose, information, warning and error message.
348
- */
349
- Verbose = 0,
350
- /**
351
- * Show information, warning and error message.
352
- */
353
- Info = 1,
354
- /**
355
- * Show warning and error message.
356
- */
357
- Warn = 2,
358
- /**
359
- * Show error message.
360
- */
361
- Error = 3
362
- }
363
-
364
- /**
365
- * Represent Microsoft 365 tenant identity, and it is usually used when user is not involved like time-triggered automation job.
366
- *
367
- * @example
368
- * ```typescript
369
- * loadConfiguration(); // load configuration from environment variables
370
- * const credential = new M365TenantCredential();
371
- * ```
372
- *
373
- * @remarks
374
- * Only works in in server side.
375
- *
376
- * @beta
377
- */
378
- export declare class M365TenantCredential implements TokenCredential {
379
- private readonly clientSecretCredential;
380
- /**
381
- * Constructor of M365TenantCredential.
382
- *
383
- * @remarks
384
- * Only works in in server side.
385
- *
386
- * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret or tenant id is not found in config.
387
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
388
- *
389
- * @beta
390
- */
391
- constructor();
392
- /**
393
- * Get access token for credential.
394
- *
395
- * @example
396
- * ```typescript
397
- * await credential.getToken(["User.Read.All"]) // Get Graph access token for single scope using string array
398
- * await credential.getToken("User.Read.All") // Get Graph access token for single scope using string
399
- * await credential.getToken(["User.Read.All", "Calendars.Read"]) // Get Graph access token for multiple scopes using string array
400
- * await credential.getToken("User.Read.All Calendars.Read") // Get Graph access token for multiple scopes using space-separated string
401
- * await credential.getToken("https://graph.microsoft.com/User.Read.All") // Get Graph access token with full resource URI
402
- * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
403
- * ```
404
- *
405
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
406
- * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
407
- *
408
- * @throws {@link ErrorCode|ServiceError} when get access token with authentication error.
409
- * @throws {@link ErrorCode|InternalError} when get access token with unknown error.
410
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
411
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
412
- *
413
- * @returns Access token with expected scopes.
414
- * Throw error if get access token failed.
415
- *
416
- * @beta
417
- */
418
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
419
- /**
420
- * Load and validate authentication configuration
421
- * @returns Authentication configuration
422
- */
423
- private loadAndValidateConfig;
424
- }
425
-
426
- /**
427
- * Microsoft Graph auth provider for Teams Framework
428
- *
429
- * @beta
430
- */
431
- export declare class MsGraphAuthProvider implements AuthenticationProvider {
432
- private credential;
433
- private scopes;
434
- /**
435
- * Constructor of MsGraphAuthProvider.
436
- *
437
- * @param {TokenCredential} credential - Credential used to invoke Microsoft Graph APIs.
438
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
439
- *
440
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
441
- *
442
- * @returns An instance of MsGraphAuthProvider.
443
- *
444
- * @beta
445
- */
446
- constructor(credential: TokenCredential, scopes?: string | string[]);
447
- /**
448
- * Get access token for Microsoft Graph API requests.
449
- *
450
- * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
451
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
452
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
453
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
454
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
455
- *
456
- * @returns Access token from the credential.
457
- *
458
- */
459
- getAccessToken(): Promise<string>;
460
- }
461
-
462
- /**
463
- * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
464
- *
465
- * @example
466
- * ```typescript
467
- * loadConfiguration(); // load configuration from environment variables
468
- * const credential = new OnBehalfOfUserCredential(ssoToken);
469
- * ```
470
- *
471
- * @remarks
472
- * Can only be used in server side.
473
- *
474
- * @beta
475
- */
476
- export declare class OnBehalfOfUserCredential implements TokenCredential {
477
- private msalClient;
478
- private ssoToken;
479
- /**
480
- * Constructor of OnBehalfOfUserCredential
481
- *
482
- * @remarks
483
- * Only works in in server side.
484
- *
485
- * @param {string} ssoToken - User token provided by Teams SSO feature.
486
- *
487
- * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, authority host or tenant id is not found in config.
488
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
489
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
490
- *
491
- * @beta
492
- */
493
- constructor(ssoToken: string);
494
- /**
495
- * Get access token from credential.
496
- *
497
- * @example
498
- * ```typescript
499
- * await credential.getToken([]) // Get SSO token using empty string array
500
- * await credential.getToken("") // Get SSO token using empty string
501
- * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
502
- * await credential.getToken(".default") // Get Graph access token with default scope using string
503
- * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
504
- * await credential.getToken("User.Read") // Get Graph access token for single scope using string
505
- * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
506
- * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
507
- * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
508
- * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
509
- * ```
510
- *
511
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
512
- * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
513
- *
514
- * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
515
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
516
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
517
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
518
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
519
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
520
- *
521
- * @returns Access token with expected scopes.
522
- *
523
- * @remarks
524
- * If scopes is empty string or array, it returns SSO token.
525
- * If scopes is non-empty, it returns access token for target scope.
526
- *
527
- * @beta
528
- */
529
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
530
- /**
531
- * Get basic user info from SSO token.
532
- *
533
- * @example
534
- * ```typescript
535
- * const currentUser = getUserInfo();
536
- * ```
537
- *
538
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
539
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
540
- *
541
- * @returns Basic user info with user displayName, objectId and preferredUserName.
542
- *
543
- * @beta
544
- */
545
- getUserInfo(): UserInfo;
546
- private generateAuthServerError;
547
- }
548
-
549
- /**
550
- * Configuration for resources.
551
- * @beta
552
- */
553
- export declare interface ResourceConfiguration {
554
- /**
555
- * Resource type.
556
- *
557
- * @readonly
558
- */
559
- readonly type: ResourceType;
560
- /**
561
- * Resource name.
562
- *
563
- * @readonly
564
- */
565
- readonly name: string;
566
- /**
567
- * Config for the resource.
568
- *
569
- * @readonly
570
- */
571
- readonly properties: {
572
- [index: string]: any;
573
- };
574
- }
575
-
576
- /**
577
- * Available resource type.
578
- * @beta
579
- */
580
- export declare enum ResourceType {
581
- /**
582
- * SQL database.
583
- *
584
- */
585
- SQL = 0,
586
- /**
587
- * Rest API.
588
- *
589
- */
590
- API = 1
591
- }
592
-
593
- /**
594
- * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
595
- *
596
- * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
597
- *
598
- * @beta
599
- */
600
- export declare function setLogFunction(logFunction?: LogFunction): void;
601
-
602
- /**
603
- * Set custom logger. Use the output function if it's set. Priority is higher than setLogFunction.
604
- *
605
- * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
606
- *
607
- * @beta
608
- */
609
- export declare function setLogger(logger?: Logger): void;
610
-
611
- /**
612
- * Update log level helper.
613
- *
614
- * @param { LogLevel } level - log level in configuration
615
- *
616
- * @beta
617
- */
618
- export declare function setLogLevel(level: LogLevel): void;
619
-
620
- /**
621
- * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
622
- * help receive oauth token, asks the user to consent if needed.
623
- *
624
- * @remarks
625
- * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
626
- * the token store.
627
- *
628
- * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
629
- * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
630
- *
631
- * @example
632
- * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
633
- * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
634
- * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
635
- * needed and their access token will be passed as an argument to the callers next waterfall step:
636
- *
637
- * ```JavaScript
638
- * const { ConversationState, MemoryStorage } = require('botbuilder');
639
- * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
640
- * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
641
- *
642
- * const convoState = new ConversationState(new MemoryStorage());
643
- * const dialogState = convoState.createProperty('dialogState');
644
- * const dialogs = new DialogSet(dialogState);
645
- *
646
- * loadConfiguration();
647
- * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
648
- * scopes: ["User.Read"],
649
- * }));
650
- *
651
- * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
652
- * async (step) => {
653
- * return await step.beginDialog('TeamsBotSsoPrompt');
654
- * },
655
- * async (step) => {
656
- * const token = step.result;
657
- * if (token) {
658
- *
659
- * // ... continue with task needing access token ...
660
- *
661
- * } else {
662
- * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
663
- * return await step.endDialog();
664
- * }
665
- * }
666
- * ]));
667
- * ```
668
- *
669
- * @beta
670
- */
671
- export declare class TeamsBotSsoPrompt extends Dialog {
672
- private settings;
673
- /**
674
- * Constructor of TeamsBotSsoPrompt.
675
- *
676
- * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
677
- * @param settings Settings used to configure the prompt.
678
- *
679
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
680
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
681
- *
682
- * @beta
683
- */
684
- constructor(dialogId: string, settings: TeamsBotSsoPromptSettings);
685
- /**
686
- * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
687
- * @remarks
688
- * If the task is successful, the result indicates whether the prompt is still
689
- * active after the turn has been processed by the prompt.
690
- *
691
- * @param dc The DialogContext for the current turn of the conversation.
692
- *
693
- * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
694
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
695
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
696
- *
697
- * @returns A `Promise` representing the asynchronous operation.
698
- *
699
- * @beta
700
- */
701
- beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
702
- /**
703
- * Called when a prompt dialog is the active dialog and the user replied with a new activity.
704
- *
705
- * @remarks
706
- * If the task is successful, the result indicates whether the dialog is still
707
- * active after the turn has been processed by the dialog.
708
- * The prompt generally continues to receive the user's replies until it accepts the
709
- * user's reply as valid input for the prompt.
710
- *
711
- * @param dc The DialogContext for the current turn of the conversation.
712
- *
713
- * @returns A `Promise` representing the asynchronous operation.
714
- *
715
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
716
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
717
- *
718
- * @beta
719
- */
720
- continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
721
- /**
722
- * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
723
- * @param dc dialog context
724
- * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
725
- * @internal
726
- */
727
- private ensureMsTeamsChannel;
728
- /**
729
- * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
730
- * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
731
- *
732
- * @internal
733
- */
734
- private sendOAuthCardAsync;
735
- /**
736
- * Get sign in resource.
737
- *
738
- * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
739
- *
740
- * @internal
741
- */
742
- private getSignInResource;
743
- /**
744
- * @internal
745
- */
746
- private recognizeToken;
747
- /**
748
- * @internal
749
- */
750
- private getTokenExchangeInvokeResponse;
751
- /**
752
- * @internal
753
- */
754
- private isTeamsVerificationInvoke;
755
- /**
756
- * @internal
757
- */
758
- private isTokenExchangeRequestInvoke;
759
- /**
760
- * @internal
761
- */
762
- private isTokenExchangeRequest;
763
- }
764
-
765
- /**
766
- * Settings used to configure an TeamsBotSsoPrompt instance.
767
- *
768
- * @beta
769
- */
770
- export declare interface TeamsBotSsoPromptSettings {
771
- /**
772
- * The array of strings that declare the desired permissions and the resources requested.
773
- */
774
- scopes: string[];
775
- /**
776
- * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
777
- * Defaults to a value `900,000` (15 minutes.)
778
- */
779
- timeout?: number;
780
- /**
781
- * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
782
- * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
783
- * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
784
- * Defaults to value `true`
785
- */
786
- endOnInvalidMessage?: boolean;
787
- }
788
-
789
- /**
790
- * Token response provided by Teams Bot SSO prompt
791
- *
792
- * @beta
793
- */
794
- export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
795
- /**
796
- * SSO token for user
797
- */
798
- ssoToken: string;
799
- /**
800
- * Expire time of SSO token
801
- */
802
- ssoTokenExpiration: string;
803
- }
804
-
805
- /**
806
- * Represent Teams current user's identity, and it is used within Teams client applications.
807
- *
808
- * @remarks
809
- * Can only be used within Teams.
810
- *
811
- * @beta
812
- */
813
- export declare class TeamsUserCredential implements TokenCredential {
814
- /**
815
- * Constructor of TeamsUserCredential.
816
- * @remarks
817
- * Can only be used within Teams.
818
- * @beta
819
- */
820
- constructor();
821
- /**
822
- * Popup login page to get user's access token with specific scopes.
823
- * @remarks
824
- * Can only be used within Teams.
825
- * @beta
826
- */
827
- login(scopes: string | string[]): Promise<void>;
828
- /**
829
- * Get access token from credential.
830
- * @remarks
831
- * Can only be used within Teams.
832
- * @beta
833
- */
834
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
835
- /**
836
- * Get basic user info from SSO token
837
- * @remarks
838
- * Can only be used within Teams.
839
- * @beta
840
- */
841
- getUserInfo(): Promise<UserInfo>;
842
- }
843
- export { TokenCredential }
844
-
845
- /**
846
- * UserInfo with user displayName, objectId and preferredUserName.
847
- *
848
- * @beta
849
- */
850
- export declare interface UserInfo {
851
- /**
852
- * User Display Name.
853
- *
854
- * @readonly
855
- */
856
- displayName: string;
857
- /**
858
- * User unique reference within the Azure Active Directory domain.
859
- *
860
- * @readonly
861
- */
862
- objectId: string;
863
- /**
864
- * Usually be the email address.
865
- *
866
- * @readonly
867
- */
868
- preferredUserName: string;
869
- }
870
-
871
- export { }
1
+ import { AccessToken } from '@azure/identity';
2
+ import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
3
+ import { Client } from '@microsoft/microsoft-graph-client';
4
+ import { ConnectionConfig } from 'tedious';
5
+ import { Dialog } from 'botbuilder-dialogs';
6
+ import { DialogContext } from 'botbuilder-dialogs';
7
+ import { DialogTurnResult } from 'botbuilder-dialogs';
8
+ import { GetTokenOptions } from '@azure/identity';
9
+ import { TokenCredential } from '@azure/identity';
10
+ import { TokenResponse } from 'botframework-schema';
11
+
12
+ /**
13
+ * Authentication related configuration.
14
+ * @beta
15
+ */
16
+ export declare interface AuthenticationConfiguration {
17
+ /**
18
+ * Hostname of AAD authority. Default value comes from M365_AUTHORITY_HOST environment variable.
19
+ *
20
+ * @readonly
21
+ */
22
+ readonly authorityHost?: string;
23
+ /**
24
+ * AAD tenant id, default value comes from M365_TENANT_ID environment variable.
25
+ *
26
+ * @readonly
27
+ */
28
+ readonly tenantId?: string;
29
+ /**
30
+ * The client (application) ID of an App Registration in the tenant, default value comes from M365_CLIENT_ID environment variable
31
+ *
32
+ * @readonly
33
+ */
34
+ readonly clientId?: string;
35
+ /**
36
+ * Secret string that the application uses when requesting a token. Only used in confidential client applications. Can be created in the Azure app registration portal. Default value comes from M365_CLIENT_SECRET environment variable
37
+ *
38
+ * @readonly
39
+ */
40
+ readonly clientSecret?: string;
41
+ /**
42
+ * The content of a PEM-encoded public/private key certificate.
43
+ *
44
+ * @readonly
45
+ */
46
+ readonly certificateContent?: string;
47
+ /**
48
+ * Endpoint of auth service provisioned by Teams Framework. Default value comes from SIMPLE_AUTH_ENDPOINT environment variable.
49
+ *
50
+ * @readonly
51
+ */
52
+ readonly simpleAuthEndpoint?: string;
53
+ /**
54
+ * Login page for Teams to redirect to. Default value comes from INITIATE_LOGIN_ENDPOINT environment variable.
55
+ *
56
+ * @readonly
57
+ */
58
+ readonly initiateLoginEndpoint?: string;
59
+ /**
60
+ * Application ID URI. Default value comes from M365_APPLICATION_ID_URI environment variable.
61
+ */
62
+ readonly applicationIdUri?: string;
63
+ }
64
+
65
+ /**
66
+ * Configuration for current environment.
67
+ * @beta
68
+ */
69
+ export declare interface Configuration {
70
+ /**
71
+ * Authentication related configuration.
72
+ *
73
+ * @readonly
74
+ */
75
+ readonly authentication?: AuthenticationConfiguration;
76
+ /**
77
+ * Configuration for resources.
78
+ *
79
+ * @readonly
80
+ */
81
+ readonly resources?: ResourceConfiguration[];
82
+ }
83
+
84
+ /**
85
+ * Get Microsoft graph client.
86
+ *
87
+ * @example
88
+ * Get Microsoft graph client by TokenCredential
89
+ * ```typescript
90
+ * // Sso token example (Azure Function)
91
+ * const ssoToken = "YOUR_TOKEN_STRING";
92
+ * const options = {"AAD_APP_ID", "AAD_APP_SECRET"};
93
+ * const credential = new OnBehalfOfAADUserCredential(ssoToken, options);
94
+ * const graphClient = await createMicrosoftGraphClient(credential);
95
+ * const profile = await graphClient.api("/me").get();
96
+ *
97
+ * // TeamsBotSsoPrompt example (Bot Application)
98
+ * const requiredScopes = ["User.Read"];
99
+ * const config: Configuration = {
100
+ * loginUrl: loginUrl,
101
+ * clientId: clientId,
102
+ * clientSecret: clientSecret,
103
+ * tenantId: tenantId
104
+ * };
105
+ * const prompt = new TeamsBotSsoPrompt(dialogId, {
106
+ * config: config
107
+ * scopes: '["User.Read"],
108
+ * });
109
+ * this.addDialog(prompt);
110
+ *
111
+ * const oboCredential = new OnBehalfOfAADUserCredential(
112
+ * getUserId(dialogContext),
113
+ * {
114
+ * clientId: "AAD_APP_ID",
115
+ * clientSecret: "AAD_APP_SECRET"
116
+ * });
117
+ * try {
118
+ * const graphClient = await createMicrosoftGraphClient(credential);
119
+ * const profile = await graphClient.api("/me").get();
120
+ * } catch (e) {
121
+ * dialogContext.beginDialog(dialogId);
122
+ * return Dialog.endOfTurn();
123
+ * }
124
+ * ```
125
+ *
126
+ * @param {TokenCredential} credential - token credential instance.
127
+ * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
128
+ *
129
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
130
+ *
131
+ * @returns Graph client with specified scopes.
132
+ *
133
+ * @beta
134
+ */
135
+ export declare function createMicrosoftGraphClient(credential: TokenCredential, scopes?: string | string[]): Client;
136
+
137
+ /**
138
+ * SQL connection configuration instance.
139
+ * @remarks
140
+ * Only works in in server side.
141
+ *
142
+ * @beta
143
+ *
144
+ */
145
+ export declare class DefaultTediousConnectionConfiguration {
146
+ /**
147
+ * MSSQL default scope
148
+ * https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi
149
+ */
150
+ private readonly defaultSQLScope;
151
+ /**
152
+ * Generate connection configuration consumed by tedious.
153
+ *
154
+ * @returns Connection configuration of tedious for the SQL.
155
+ *
156
+ * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
157
+ * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
158
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
159
+ *
160
+ * @beta
161
+ */
162
+ getConfig(): Promise<ConnectionConfig>;
163
+ /**
164
+ * Check SQL use MSI identity or username and password.
165
+ *
166
+ * @returns false - login with SQL MSI identity, true - login with username and password.
167
+ * @internal
168
+ */
169
+ private isMsiAuthentication;
170
+ /**
171
+ * check configuration is an available configurations.
172
+ * @param { SqlConfiguration } sqlConfig
173
+ *
174
+ * @returns true - SQL configuration has a valid SQL endpoints, SQL username with password or identity ID.
175
+ * false - configuration is not valid.
176
+ * @internal
177
+ */
178
+ private isSQLConfigurationValid;
179
+ /**
180
+ * Generate tedious connection configuration with default authentication type.
181
+ *
182
+ * @param { SqlConfiguration } SQL configuration with username and password.
183
+ *
184
+ * @returns Tedious connection configuration with username and password.
185
+ * @internal
186
+ */
187
+ private generateDefaultConfig;
188
+ /**
189
+ * Generate tedious connection configuration with azure-active-directory-access-token authentication type.
190
+ *
191
+ * @param { SqlConfiguration } SQL configuration with AAD access token.
192
+ *
193
+ * @returns Tedious connection configuration with access token.
194
+ * @internal
195
+ */
196
+ private generateTokenConfig;
197
+ }
198
+
199
+ /**
200
+ * Error code to trace the error types.
201
+ * @beta
202
+ */
203
+ export declare enum ErrorCode {
204
+ /**
205
+ * Invalid parameter error.
206
+ */
207
+ InvalidParameter = "InvalidParameter",
208
+ /**
209
+ * Invalid configuration error.
210
+ */
211
+ InvalidConfiguration = "InvalidConfiguration",
212
+ /**
213
+ * Invalid certificate error.
214
+ */
215
+ InvalidCertificate = "InvalidCertificate",
216
+ /**
217
+ * Internal error.
218
+ */
219
+ InternalError = "InternalError",
220
+ /**
221
+ * Channel is not supported error.
222
+ */
223
+ ChannelNotSupported = "ChannelNotSupported",
224
+ /**
225
+ * Runtime is not supported error.
226
+ */
227
+ RuntimeNotSupported = "RuntimeNotSupported",
228
+ /**
229
+ * User failed to finish the AAD consent flow failed.
230
+ */
231
+ ConsentFailed = "ConsentFailed",
232
+ /**
233
+ * The user or administrator has not consented to use the application error.
234
+ */
235
+ UiRequiredError = "UiRequiredError",
236
+ /**
237
+ * Token is not within its valid time range error.
238
+ */
239
+ TokenExpiredError = "TokenExpiredError",
240
+ /**
241
+ * Call service (AAD or simple authentication server) failed.
242
+ */
243
+ ServiceError = "ServiceError",
244
+ /**
245
+ * Operation failed.
246
+ */
247
+ FailedOperation = "FailedOperation"
248
+ }
249
+
250
+ /**
251
+ * Error class with code and message thrown by the SDK.
252
+ *
253
+ * @beta
254
+ */
255
+ export declare class ErrorWithCode extends Error {
256
+ /**
257
+ * Error code
258
+ *
259
+ * @readonly
260
+ */
261
+ code: string | undefined;
262
+ /**
263
+ * Constructor of ErrorWithCode.
264
+ *
265
+ * @param {string} message - error message.
266
+ * @param {ErrorCode} code - error code.
267
+ *
268
+ * @beta
269
+ */
270
+ constructor(message?: string, code?: ErrorCode);
271
+ }
272
+
273
+ /**
274
+ * Get configuration for authentication.
275
+ *
276
+ * @returns Authentication configuration from global configuration instance, the value may be undefined if no authentication config exists in current environment.
277
+ *
278
+ * @throws {@link ErrorCode|InvalidConfiguration} when global configuration does not exist
279
+ *
280
+ * @beta
281
+ */
282
+ export declare function getAuthenticationConfiguration(): AuthenticationConfiguration | undefined;
283
+
284
+ /**
285
+ * Get log level.
286
+ *
287
+ * @returns Log level
288
+ *
289
+ * @beta
290
+ */
291
+ export declare function getLogLevel(): LogLevel | undefined;
292
+
293
+ /**
294
+ * Get configuration for a specific resource.
295
+ * @param {ResourceType} resourceType - The type of resource
296
+ * @param {string} resourceName - The name of resource, default value is "default".
297
+ *
298
+ * @returns Resource configuration for target resource from global configuration instance.
299
+ *
300
+ * @throws {@link ErrorCode|InvalidConfiguration} when resource configuration with the specific type and name is not found
301
+ *
302
+ * @beta
303
+ */
304
+ export declare function getResourceConfiguration(resourceType: ResourceType, resourceName?: string): {
305
+ [index: string]: any;
306
+ };
307
+ export { GetTokenOptions }
308
+
309
+ /**
310
+ * Initialize configuration from environment variables or configuration object and set the global instance
311
+ *
312
+ * @param {Configuration} configuration - Optional configuration that overrides the default configuration values. The override depth is 1.
313
+ *
314
+ * @throws {@link ErrorCode|InvalidParameter} when configuration is not passed in browser environment
315
+ *
316
+ * @beta
317
+ */
318
+ export declare function loadConfiguration(configuration?: Configuration): void;
319
+
320
+ /**
321
+ * Log function for customized logging.
322
+ *
323
+ * @beta
324
+ */
325
+ export declare type LogFunction = (level: LogLevel, message: string) => void;
326
+
327
+ /**
328
+ * Interface for customized logger.
329
+ * @beta
330
+ */
331
+ export declare interface Logger {
332
+ /**
333
+ * Writes to error level logging or lower.
334
+ */
335
+ error(message: string): void;
336
+ /**
337
+ * Writes to warning level logging or lower.
338
+ */
339
+ warn(message: string): void;
340
+ /**
341
+ * Writes to info level logging or lower.
342
+ */
343
+ info(message: string): void;
344
+ /**
345
+ * Writes to verbose level logging.
346
+ */
347
+ verbose(message: string): void;
348
+ }
349
+
350
+ /**
351
+ * Log level.
352
+ *
353
+ * @beta
354
+ */
355
+ export declare enum LogLevel {
356
+ /**
357
+ * Show verbose, information, warning and error message.
358
+ */
359
+ Verbose = 0,
360
+ /**
361
+ * Show information, warning and error message.
362
+ */
363
+ Info = 1,
364
+ /**
365
+ * Show warning and error message.
366
+ */
367
+ Warn = 2,
368
+ /**
369
+ * Show error message.
370
+ */
371
+ Error = 3
372
+ }
373
+
374
+ /**
375
+ * Represent Microsoft 365 tenant identity, and it is usually used when user is not involved like time-triggered automation job.
376
+ *
377
+ * @example
378
+ * ```typescript
379
+ * loadConfiguration(); // load configuration from environment variables
380
+ * const credential = new M365TenantCredential();
381
+ * ```
382
+ *
383
+ * @remarks
384
+ * Only works in in server side.
385
+ *
386
+ * @beta
387
+ */
388
+ export declare class M365TenantCredential implements TokenCredential {
389
+ private readonly msalClient;
390
+ /**
391
+ * Constructor of M365TenantCredential.
392
+ *
393
+ * @remarks
394
+ * Only works in in server side.
395
+ *
396
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret or tenant id is not found in config.
397
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
398
+ *
399
+ * @beta
400
+ */
401
+ constructor();
402
+ /**
403
+ * Get access token for credential.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * await credential.getToken(["User.Read.All"]) // Get Graph access token for single scope using string array
408
+ * await credential.getToken("User.Read.All") // Get Graph access token for single scope using string
409
+ * await credential.getToken(["User.Read.All", "Calendars.Read"]) // Get Graph access token for multiple scopes using string array
410
+ * await credential.getToken("User.Read.All Calendars.Read") // Get Graph access token for multiple scopes using space-separated string
411
+ * await credential.getToken("https://graph.microsoft.com/User.Read.All") // Get Graph access token with full resource URI
412
+ * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
413
+ * ```
414
+ *
415
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
416
+ * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
417
+ *
418
+ * @throws {@link ErrorCode|ServiceError} when get access token with authentication error.
419
+ * @throws {@link ErrorCode|InternalError} when get access token with unknown error.
420
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
421
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
422
+ *
423
+ * @returns Access token with expected scopes.
424
+ * Throw error if get access token failed.
425
+ *
426
+ * @beta
427
+ */
428
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
429
+ /**
430
+ * Load and validate authentication configuration
431
+ * @returns Authentication configuration
432
+ */
433
+ private loadAndValidateConfig;
434
+ }
435
+
436
+ /**
437
+ * Microsoft Graph auth provider for Teams Framework
438
+ *
439
+ * @beta
440
+ */
441
+ export declare class MsGraphAuthProvider implements AuthenticationProvider {
442
+ private credential;
443
+ private scopes;
444
+ /**
445
+ * Constructor of MsGraphAuthProvider.
446
+ *
447
+ * @param {TokenCredential} credential - Credential used to invoke Microsoft Graph APIs.
448
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
449
+ *
450
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
451
+ *
452
+ * @returns An instance of MsGraphAuthProvider.
453
+ *
454
+ * @beta
455
+ */
456
+ constructor(credential: TokenCredential, scopes?: string | string[]);
457
+ /**
458
+ * Get access token for Microsoft Graph API requests.
459
+ *
460
+ * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
461
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
462
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
463
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
464
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
465
+ *
466
+ * @returns Access token from the credential.
467
+ *
468
+ */
469
+ getAccessToken(): Promise<string>;
470
+ }
471
+
472
+ /**
473
+ * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * loadConfiguration(); // load configuration from environment variables
478
+ * const credential = new OnBehalfOfUserCredential(ssoToken);
479
+ * ```
480
+ *
481
+ * @remarks
482
+ * Can only be used in server side.
483
+ *
484
+ * @beta
485
+ */
486
+ export declare class OnBehalfOfUserCredential implements TokenCredential {
487
+ private msalClient;
488
+ private ssoToken;
489
+ /**
490
+ * Constructor of OnBehalfOfUserCredential
491
+ *
492
+ * @remarks
493
+ * Only works in in server side.
494
+ *
495
+ * @param {string} ssoToken - User token provided by Teams SSO feature.
496
+ *
497
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
498
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
499
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
500
+ *
501
+ * @beta
502
+ */
503
+ constructor(ssoToken: string);
504
+ /**
505
+ * Get access token from credential.
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * await credential.getToken([]) // Get SSO token using empty string array
510
+ * await credential.getToken("") // Get SSO token using empty string
511
+ * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
512
+ * await credential.getToken(".default") // Get Graph access token with default scope using string
513
+ * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
514
+ * await credential.getToken("User.Read") // Get Graph access token for single scope using string
515
+ * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
516
+ * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
517
+ * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
518
+ * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
519
+ * ```
520
+ *
521
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
522
+ * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
523
+ *
524
+ * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
525
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
526
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
527
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
528
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
529
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
530
+ *
531
+ * @returns Access token with expected scopes.
532
+ *
533
+ * @remarks
534
+ * If scopes is empty string or array, it returns SSO token.
535
+ * If scopes is non-empty, it returns access token for target scope.
536
+ *
537
+ * @beta
538
+ */
539
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
540
+ /**
541
+ * Get basic user info from SSO token.
542
+ *
543
+ * @example
544
+ * ```typescript
545
+ * const currentUser = getUserInfo();
546
+ * ```
547
+ *
548
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
549
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
550
+ *
551
+ * @returns Basic user info with user displayName, objectId and preferredUserName.
552
+ *
553
+ * @beta
554
+ */
555
+ getUserInfo(): UserInfo;
556
+ private generateAuthServerError;
557
+ }
558
+
559
+ /**
560
+ * Configuration for resources.
561
+ * @beta
562
+ */
563
+ export declare interface ResourceConfiguration {
564
+ /**
565
+ * Resource type.
566
+ *
567
+ * @readonly
568
+ */
569
+ readonly type: ResourceType;
570
+ /**
571
+ * Resource name.
572
+ *
573
+ * @readonly
574
+ */
575
+ readonly name: string;
576
+ /**
577
+ * Config for the resource.
578
+ *
579
+ * @readonly
580
+ */
581
+ readonly properties: {
582
+ [index: string]: any;
583
+ };
584
+ }
585
+
586
+ /**
587
+ * Available resource type.
588
+ * @beta
589
+ */
590
+ export declare enum ResourceType {
591
+ /**
592
+ * SQL database.
593
+ *
594
+ */
595
+ SQL = 0,
596
+ /**
597
+ * Rest API.
598
+ *
599
+ */
600
+ API = 1
601
+ }
602
+
603
+ /**
604
+ * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
605
+ *
606
+ * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * setLogFunction((level: LogLevel, message: string) => {
611
+ * if (level === LogLevel.Error) {
612
+ * console.log(message);
613
+ * }
614
+ * });
615
+ * ```
616
+ *
617
+ * @beta
618
+ */
619
+ export declare function setLogFunction(logFunction?: LogFunction): void;
620
+
621
+ /**
622
+ * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
623
+ *
624
+ * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * setLogger({
629
+ * verbose: console.debug,
630
+ * info: console.info,
631
+ * warn: console.warn,
632
+ * error: console.error,
633
+ * });
634
+ * ```
635
+ *
636
+ * @beta
637
+ */
638
+ export declare function setLogger(logger?: Logger): void;
639
+
640
+ /**
641
+ * Update log level helper.
642
+ *
643
+ * @param { LogLevel } level - log level in configuration
644
+ *
645
+ * @beta
646
+ */
647
+ export declare function setLogLevel(level: LogLevel): void;
648
+
649
+ /**
650
+ * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
651
+ * help receive oauth token, asks the user to consent if needed.
652
+ *
653
+ * @remarks
654
+ * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
655
+ * the token store.
656
+ *
657
+ * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
658
+ * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
659
+ *
660
+ * @example
661
+ * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
662
+ * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
663
+ * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
664
+ * needed and their access token will be passed as an argument to the callers next waterfall step:
665
+ *
666
+ * ```JavaScript
667
+ * const { ConversationState, MemoryStorage } = require('botbuilder');
668
+ * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
669
+ * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
670
+ *
671
+ * const convoState = new ConversationState(new MemoryStorage());
672
+ * const dialogState = convoState.createProperty('dialogState');
673
+ * const dialogs = new DialogSet(dialogState);
674
+ *
675
+ * loadConfiguration();
676
+ * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
677
+ * scopes: ["User.Read"],
678
+ * }));
679
+ *
680
+ * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
681
+ * async (step) => {
682
+ * return await step.beginDialog('TeamsBotSsoPrompt');
683
+ * },
684
+ * async (step) => {
685
+ * const token = step.result;
686
+ * if (token) {
687
+ *
688
+ * // ... continue with task needing access token ...
689
+ *
690
+ * } else {
691
+ * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
692
+ * return await step.endDialog();
693
+ * }
694
+ * }
695
+ * ]));
696
+ * ```
697
+ *
698
+ * @beta
699
+ */
700
+ export declare class TeamsBotSsoPrompt extends Dialog {
701
+ private settings;
702
+ /**
703
+ * Constructor of TeamsBotSsoPrompt.
704
+ *
705
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
706
+ * @param settings Settings used to configure the prompt.
707
+ *
708
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
709
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
710
+ *
711
+ * @beta
712
+ */
713
+ constructor(dialogId: string, settings: TeamsBotSsoPromptSettings);
714
+ /**
715
+ * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
716
+ * @remarks
717
+ * If the task is successful, the result indicates whether the prompt is still
718
+ * active after the turn has been processed by the prompt.
719
+ *
720
+ * @param dc The DialogContext for the current turn of the conversation.
721
+ *
722
+ * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
723
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
724
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
725
+ *
726
+ * @returns A `Promise` representing the asynchronous operation.
727
+ *
728
+ * @beta
729
+ */
730
+ beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
731
+ /**
732
+ * Called when a prompt dialog is the active dialog and the user replied with a new activity.
733
+ *
734
+ * @remarks
735
+ * If the task is successful, the result indicates whether the dialog is still
736
+ * active after the turn has been processed by the dialog.
737
+ * The prompt generally continues to receive the user's replies until it accepts the
738
+ * user's reply as valid input for the prompt.
739
+ *
740
+ * @param dc The DialogContext for the current turn of the conversation.
741
+ *
742
+ * @returns A `Promise` representing the asynchronous operation.
743
+ *
744
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
745
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
746
+ *
747
+ * @beta
748
+ */
749
+ continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
750
+ /**
751
+ * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
752
+ * @param dc dialog context
753
+ * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
754
+ * @internal
755
+ */
756
+ private ensureMsTeamsChannel;
757
+ /**
758
+ * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
759
+ * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
760
+ *
761
+ * @internal
762
+ */
763
+ private sendOAuthCardAsync;
764
+ /**
765
+ * Get sign in resource.
766
+ *
767
+ * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
768
+ *
769
+ * @internal
770
+ */
771
+ private getSignInResource;
772
+ /**
773
+ * @internal
774
+ */
775
+ private recognizeToken;
776
+ /**
777
+ * @internal
778
+ */
779
+ private getTokenExchangeInvokeResponse;
780
+ /**
781
+ * @internal
782
+ */
783
+ private isTeamsVerificationInvoke;
784
+ /**
785
+ * @internal
786
+ */
787
+ private isTokenExchangeRequestInvoke;
788
+ /**
789
+ * @internal
790
+ */
791
+ private isTokenExchangeRequest;
792
+ }
793
+
794
+ /**
795
+ * Settings used to configure an TeamsBotSsoPrompt instance.
796
+ *
797
+ * @beta
798
+ */
799
+ export declare interface TeamsBotSsoPromptSettings {
800
+ /**
801
+ * The array of strings that declare the desired permissions and the resources requested.
802
+ */
803
+ scopes: string[];
804
+ /**
805
+ * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
806
+ * Defaults to a value `900,000` (15 minutes.)
807
+ */
808
+ timeout?: number;
809
+ /**
810
+ * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
811
+ * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
812
+ * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
813
+ * Defaults to value `true`
814
+ */
815
+ endOnInvalidMessage?: boolean;
816
+ }
817
+
818
+ /**
819
+ * Token response provided by Teams Bot SSO prompt
820
+ *
821
+ * @beta
822
+ */
823
+ export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
824
+ /**
825
+ * SSO token for user
826
+ */
827
+ ssoToken: string;
828
+ /**
829
+ * Expire time of SSO token
830
+ */
831
+ ssoTokenExpiration: string;
832
+ }
833
+
834
+ /**
835
+ * Represent Teams current user's identity, and it is used within Teams client applications.
836
+ *
837
+ * @remarks
838
+ * Can only be used within Teams.
839
+ *
840
+ * @beta
841
+ */
842
+ export declare class TeamsUserCredential implements TokenCredential {
843
+ /**
844
+ * Constructor of TeamsUserCredential.
845
+ * @remarks
846
+ * Can only be used within Teams.
847
+ * @beta
848
+ */
849
+ constructor();
850
+ /**
851
+ * Popup login page to get user's access token with specific scopes.
852
+ * @remarks
853
+ * Can only be used within Teams.
854
+ * @beta
855
+ */
856
+ login(scopes: string | string[]): Promise<void>;
857
+ /**
858
+ * Get access token from credential.
859
+ * @remarks
860
+ * Can only be used within Teams.
861
+ * @beta
862
+ */
863
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
864
+ /**
865
+ * Get basic user info from SSO token
866
+ * @remarks
867
+ * Can only be used within Teams.
868
+ * @beta
869
+ */
870
+ getUserInfo(): Promise<UserInfo>;
871
+ }
872
+ export { TokenCredential }
873
+
874
+ /**
875
+ * UserInfo with user displayName, objectId and preferredUserName.
876
+ *
877
+ * @beta
878
+ */
879
+ export declare interface UserInfo {
880
+ /**
881
+ * User Display Name.
882
+ *
883
+ * @readonly
884
+ */
885
+ displayName: string;
886
+ /**
887
+ * User unique reference within the Azure Active Directory domain.
888
+ *
889
+ * @readonly
890
+ */
891
+ objectId: string;
892
+ /**
893
+ * Usually be the email address.
894
+ *
895
+ * @readonly
896
+ */
897
+ preferredUserName: string;
898
+ }
899
+
900
+ export { }