@microsoft/teamsfx 1.1.2-alpha.988c78cba.0 → 1.1.2-alpha.9bd0cb559.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.
@@ -32,6 +32,30 @@ var ErrorCode;
32
32
  * Channel is not supported error.
33
33
  */
34
34
  ErrorCode["ChannelNotSupported"] = "ChannelNotSupported";
35
+ /**
36
+ * Failed to retrieve sso token
37
+ */
38
+ ErrorCode["FailedToRetrieveSsoToken"] = "FailedToRetrieveSsoToken";
39
+ /**
40
+ * Failed to process sso handler
41
+ */
42
+ ErrorCode["FailedToProcessSsoHandler"] = "FailedToProcessSsoHandler";
43
+ /**
44
+ * Cannot find command
45
+ */
46
+ ErrorCode["CannotFindCommand"] = "CannotFindCommand";
47
+ /**
48
+ * Failed to run sso step
49
+ */
50
+ ErrorCode["FailedToRunSsoStep"] = "FailedToRunSsoStep";
51
+ /**
52
+ * Failed to run dedup step
53
+ */
54
+ ErrorCode["FailedToRunDedupStep"] = "FailedToRunDedupStep";
55
+ /**
56
+ * Sso activity handler is undefined
57
+ */
58
+ ErrorCode["SsoActivityHandlerIsUndefined"] = "SsoActivityHandlerIsUndefined";
35
59
  /**
36
60
  * Runtime is not supported error.
37
61
  */
@@ -87,6 +111,15 @@ ErrorMessage.NodejsRuntimeNotSupported = "{0} is not supported in Node.";
87
111
  ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token on behalf of user: {0}";
88
112
  // ChannelNotSupported Error
89
113
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
114
+ ErrorMessage.FailedToProcessSsoHandler = "Failed to process sso handler: {0}";
115
+ // FailedToRetrieveSsoToken Error
116
+ ErrorMessage.FailedToRetrieveSsoToken = "Failed to retrieve sso token, user failed to finish the AAD consent flow.";
117
+ // CannotFindCommand Error
118
+ ErrorMessage.CannotFindCommand = "Cannot find command: {0}";
119
+ ErrorMessage.FailedToRunSsoStep = "Failed to run dialog to retrieve sso token: {0}";
120
+ ErrorMessage.FailedToRunDedupStep = "Failed to run dialog to remove duplicated messages: {0}";
121
+ // SsoActivityHandlerIsUndefined Error
122
+ ErrorMessage.SsoActivityHandlerIsNull = "Sso command can only be used or added when sso activity handler is not undefined";
90
123
  // IdentityTypeNotSupported Error
91
124
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
92
125
  // AuthorizationInfoError
@@ -511,19 +544,20 @@ class TeamsUserCredential {
511
544
  * await credential.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
512
545
  * ```
513
546
  * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
547
+ * @param { string[] } resources - The optional list of resources for full trust Teams apps.
514
548
  *
515
549
  * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
516
550
  * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
517
551
  * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
518
552
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
519
553
  */
520
- login(scopes) {
554
+ login(scopes, resources) {
521
555
  return __awaiter(this, void 0, void 0, function* () {
522
556
  validateScopesType(scopes);
523
557
  const scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
524
558
  internalLogger.info(`Popup login page to get user's access token with scopes: ${scopesStr}`);
525
559
  if (!this.initialized) {
526
- yield this.init();
560
+ yield this.init(resources);
527
561
  }
528
562
  return new Promise((resolve, reject) => {
529
563
  microsoftTeams.initialize(() => {
@@ -576,6 +610,9 @@ class TeamsUserCredential {
576
610
  * Get access token from credential.
577
611
  *
578
612
  * Important: Access tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
613
+ * Important: Full trust applications do not read the resource information from the webApplicationInfo section of the app
614
+ * manifest. Instead, this resource (along with any additional resources from which to request tokens) must be provided
615
+ * as a list of resources to the getToken() method through a GetTeamsUserTokenOptions object.
579
616
  *
580
617
  * @example
581
618
  * ```typescript
@@ -589,6 +626,9 @@ class TeamsUserCredential {
589
626
  * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
590
627
  * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
591
628
  * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
629
+ *
630
+ * const options: GetTeamsUserTokenOptions = { resources: ["https://domain.example.com"] }; // set up resources for full trust apps.
631
+ * await credential.getToken([], options) // Get sso token from teams client - only use this approach for full trust apps.
592
632
  * ```
593
633
  *
594
634
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
@@ -605,9 +645,11 @@ class TeamsUserCredential {
605
645
  * Throw error if get access token failed.
606
646
  */
607
647
  getToken(scopes, options) {
648
+ var _a;
608
649
  return __awaiter(this, void 0, void 0, function* () {
609
650
  validateScopesType(scopes);
610
- const ssoToken = yield this.getSSOToken();
651
+ const resources = (_a = options) === null || _a === void 0 ? void 0 : _a.resources;
652
+ const ssoToken = yield this.getSSOToken(resources);
611
653
  const scopeStr = typeof scopes === "string" ? scopes : scopes.join(" ");
612
654
  if (scopeStr === "") {
613
655
  internalLogger.info("Get SSO token");
@@ -616,7 +658,7 @@ class TeamsUserCredential {
616
658
  else {
617
659
  internalLogger.info("Get access token with scopes: " + scopeStr);
618
660
  if (!this.initialized) {
619
- yield this.init();
661
+ yield this.init(resources);
620
662
  }
621
663
  let tokenResponse;
622
664
  const scopesArray = typeof scopes === "string" ? scopes.split(" ") : scopes;
@@ -663,6 +705,8 @@ class TeamsUserCredential {
663
705
  /**
664
706
  * Get basic user info from SSO token
665
707
  *
708
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
709
+ *
666
710
  * @example
667
711
  * ```typescript
668
712
  * const currentUser = await credential.getUserInfo();
@@ -674,16 +718,16 @@ class TeamsUserCredential {
674
718
  *
675
719
  * @returns Basic user info with user displayName, objectId and preferredUserName.
676
720
  */
677
- getUserInfo() {
721
+ getUserInfo(resources) {
678
722
  return __awaiter(this, void 0, void 0, function* () {
679
723
  internalLogger.info("Get basic user info from SSO token");
680
- const ssoToken = yield this.getSSOToken();
724
+ const ssoToken = yield this.getSSOToken(resources);
681
725
  return getUserInfoFromSsoToken(ssoToken.token);
682
726
  });
683
727
  }
684
- init() {
728
+ init(resources) {
685
729
  return __awaiter(this, void 0, void 0, function* () {
686
- const ssoToken = yield this.getSSOToken();
730
+ const ssoToken = yield this.getSSOToken(resources);
687
731
  const info = getTenantIdAndLoginHintFromSsoToken(ssoToken.token);
688
732
  this.loginHint = info.loginHint;
689
733
  this.tid = info.tid;
@@ -703,9 +747,12 @@ class TeamsUserCredential {
703
747
  /**
704
748
  * Get SSO token using teams SDK
705
749
  * It will try to get SSO token from memory first, if SSO token doesn't exist or about to expired, then it will using teams SDK to get SSO token
750
+ *
751
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
752
+ *
706
753
  * @returns SSO token
707
754
  */
708
- getSSOToken() {
755
+ getSSOToken(resources) {
709
756
  return new Promise((resolve, reject) => {
710
757
  if (this.ssoToken) {
711
758
  if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
@@ -743,7 +790,7 @@ class TeamsUserCredential {
743
790
  internalLogger.error(errorMsg);
744
791
  reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
745
792
  },
746
- resources: [],
793
+ resources: resources !== null && resources !== void 0 ? resources : [],
747
794
  });
748
795
  });
749
796
  }
@@ -1278,8 +1325,9 @@ class TeamsFx {
1278
1325
  this.configuration = new Map();
1279
1326
  this.loadFromEnv();
1280
1327
  if (customConfig) {
1281
- for (const key of Object.keys(customConfig)) {
1282
- const value = customConfig[key];
1328
+ const myConfig = Object.assign({}, customConfig);
1329
+ for (const key of Object.keys(myConfig)) {
1330
+ const value = myConfig[key];
1283
1331
  if (value) {
1284
1332
  this.configuration.set(key, value);
1285
1333
  }
@@ -1327,14 +1375,14 @@ class TeamsFx {
1327
1375
  }
1328
1376
  return this.teamsUserCredential;
1329
1377
  }
1330
- getUserInfo() {
1378
+ getUserInfo(resources) {
1331
1379
  return __awaiter(this, void 0, void 0, function* () {
1332
- return yield this.getCredential().getUserInfo();
1380
+ return yield this.getCredential().getUserInfo(resources);
1333
1381
  });
1334
1382
  }
1335
- login(scopes) {
1383
+ login(scopes, resources) {
1336
1384
  return __awaiter(this, void 0, void 0, function* () {
1337
- yield this.getCredential().login(scopes);
1385
+ yield this.getCredential().login(scopes, resources);
1338
1386
  });
1339
1387
  }
1340
1388
  setSsoToken(ssoToken) {
@@ -1460,6 +1508,117 @@ class ConversationBot {
1460
1508
  }
1461
1509
  }
1462
1510
 
1511
+ // Copyright (c) Microsoft Corporation.
1512
+ /*
1513
+ * Sso execution dialog, use to handle sso command
1514
+ */
1515
+ class BotSsoExecutionDialog {
1516
+ /**
1517
+ * Creates a new instance of the BotSsoExecutionDialog.
1518
+ * @param dedupStorage Helper storage to remove duplicated messages
1519
+ * @param requiredScopes The list of scopes for which the token will have access
1520
+ * @param teamsfx {@link TeamsFx} instance for authentication
1521
+ */
1522
+ constructor(dedupStorage, requiredScopes, teamsfx) {
1523
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1524
+ }
1525
+ /**
1526
+ * Add TeamsFxBotSsoCommandHandler instance
1527
+ * @param handler {@link BotSsoExecutionDialogHandler} callback function
1528
+ * @param triggerPatterns The trigger pattern
1529
+ */
1530
+ addCommand(handler, triggerPatterns) {
1531
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1532
+ }
1533
+ /**
1534
+ * The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system.
1535
+ *
1536
+ * @param context The context object for the current turn.
1537
+ * @param accessor The instance of StatePropertyAccessor for dialog system.
1538
+ */
1539
+ run(context, accessor) {
1540
+ return __awaiter(this, void 0, void 0, function* () {
1541
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1542
+ });
1543
+ }
1544
+ /**
1545
+ * Called when the component is ending.
1546
+ *
1547
+ * @param context Context for the current turn of conversation.
1548
+ */
1549
+ onEndDialog(context) {
1550
+ return __awaiter(this, void 0, void 0, function* () {
1551
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "BotSsoExecutionDialog"), ErrorCode.RuntimeNotSupported);
1552
+ });
1553
+ }
1554
+ }
1555
+
1556
+ // Copyright (c) Microsoft Corporation.
1557
+ /**
1558
+ * Default sso execution activity handler
1559
+ */
1560
+ class DefaultBotSsoExecutionActivityHandler {
1561
+ /**
1562
+ * Creates a new instance of the DefaultBotSsoExecutionActivityHandler.
1563
+ * @param ssoConfig configuration for sso command bot
1564
+ */
1565
+ constructor(ssoConfig) {
1566
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultBotSsoExecutionActivityHandler"), ErrorCode.RuntimeNotSupported);
1567
+ }
1568
+ /**
1569
+ * Add TeamsFxBotSsoCommandHandler instance to sso execution dialog
1570
+ * @param handler {@link BotSsoExecutionDialogHandler} callback function
1571
+ * @param triggerPatterns The trigger pattern
1572
+ */
1573
+ addCommand(handler, triggerPatterns) {
1574
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultBotSsoExecutionActivityHandler"), ErrorCode.RuntimeNotSupported);
1575
+ }
1576
+ /**
1577
+ * Called to initiate the event emission process.
1578
+ * @param context The context object for the current turn.
1579
+ */
1580
+ run(context) {
1581
+ return __awaiter(this, void 0, void 0, function* () {
1582
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultBotSsoExecutionActivityHandler"), ErrorCode.RuntimeNotSupported);
1583
+ });
1584
+ }
1585
+ /**
1586
+ * Receives invoke activities with Activity name of 'signin/verifyState'.
1587
+ * @param context A context object for this turn.
1588
+ * @param query Signin state (part of signin action auth flow) verification invoke query.
1589
+ * @returns A promise that represents the work queued.
1590
+ */
1591
+ handleTeamsSigninVerifyState(context, query) {
1592
+ return __awaiter(this, void 0, void 0, function* () {
1593
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultBotSsoExecutionActivityHandler"), ErrorCode.RuntimeNotSupported);
1594
+ });
1595
+ }
1596
+ /**
1597
+ * Receives invoke activities with Activity name of 'signin/tokenExchange'
1598
+ * @param context A context object for this turn.
1599
+ * @param query Signin state (part of signin action auth flow) verification invoke query
1600
+ * @returns A promise that represents the work queued.
1601
+ */
1602
+ handleTeamsSigninTokenExchange(context, query) {
1603
+ return __awaiter(this, void 0, void 0, function* () {
1604
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultBotSsoExecutionActivityHandler"), ErrorCode.RuntimeNotSupported);
1605
+ });
1606
+ }
1607
+ /**
1608
+ * Handle signin invoke activity type.
1609
+ *
1610
+ * @param context The context object for the current turn.
1611
+ *
1612
+ * @remarks
1613
+ * Override this method to support channel-specific behavior across multiple channels.
1614
+ */
1615
+ onSignInInvoke(context) {
1616
+ return __awaiter(this, void 0, void 0, function* () {
1617
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultBotSsoExecutionActivityHandler"), ErrorCode.RuntimeNotSupported);
1618
+ });
1619
+ }
1620
+ }
1621
+
1463
1622
  // Copyright (c) Microsoft Corporation.
1464
1623
  /**
1465
1624
  * Send a plain text message to a notification target.
@@ -1774,6 +1933,22 @@ class CommandBot {
1774
1933
  registerCommands(commands) {
1775
1934
  throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1776
1935
  }
1936
+ /**
1937
+ * Registers a sso command into the command bot.
1938
+ *
1939
+ * @param command The command to register.
1940
+ */
1941
+ registerSsoCommand(ssoCommand) {
1942
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1943
+ }
1944
+ /**
1945
+ * Registers commands into the command bot.
1946
+ *
1947
+ * @param commands The commands to register.
1948
+ */
1949
+ registerSsoCommands(ssoCommands) {
1950
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1951
+ }
1777
1952
  }
1778
1953
 
1779
1954
  /**
@@ -1814,5 +1989,5 @@ class CardActionBot {
1814
1989
  }
1815
1990
  }
1816
1991
 
1817
- export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, LogLevel, Member, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1992
+ export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, BotSsoExecutionDialog, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, DefaultBotSsoExecutionActivityHandler, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, LogLevel, Member, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1818
1993
  //# sourceMappingURL=index.esm5.js.map