@microsoft/teamsfx 1.1.2-alpha.385906a8c.0 → 1.1.2-alpha.7eddd6cf4.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.
@@ -506,18 +506,19 @@ class TeamsUserCredential {
506
506
  * await credential.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
507
507
  * ```
508
508
  * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
509
+ * @param { string[] } resources - The optional list of resources for full trust Teams apps.
509
510
  *
510
511
  * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
511
512
  * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
512
513
  * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
513
514
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
514
515
  */
515
- async login(scopes) {
516
+ async login(scopes, resources) {
516
517
  validateScopesType(scopes);
517
518
  const scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
518
519
  internalLogger.info(`Popup login page to get user's access token with scopes: ${scopesStr}`);
519
520
  if (!this.initialized) {
520
- await this.init();
521
+ await this.init(resources);
521
522
  }
522
523
  return new Promise((resolve, reject) => {
523
524
  microsoftTeams.initialize(() => {
@@ -569,6 +570,9 @@ class TeamsUserCredential {
569
570
  * Get access token from credential.
570
571
  *
571
572
  * Important: Access tokens are stored in sessionStorage, read more here: https://aka.ms/teamsfx-session-storage-notice
573
+ * Important: Full trust applications do not read the resource information from the webApplicationInfo section of the app
574
+ * manifest. Instead, this resource (along with any additional resources from which to request tokens) must be provided
575
+ * as a list of resources to the getToken() method through a GetTeamsUserTokenOptions object.
572
576
  *
573
577
  * @example
574
578
  * ```typescript
@@ -582,6 +586,9 @@ class TeamsUserCredential {
582
586
  * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
583
587
  * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
584
588
  * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
589
+ *
590
+ * const options: GetTeamsUserTokenOptions = { resources: ["https://domain.example.com"] }; // set up resources for full trust apps.
591
+ * await credential.getToken([], options) // Get sso token from teams client - only use this approach for full trust apps.
585
592
  * ```
586
593
  *
587
594
  * @param {string | string[]} scopes - The list of scopes for which the token will have access.
@@ -598,8 +605,10 @@ class TeamsUserCredential {
598
605
  * Throw error if get access token failed.
599
606
  */
600
607
  async getToken(scopes, options) {
608
+ var _a;
601
609
  validateScopesType(scopes);
602
- const ssoToken = await this.getSSOToken();
610
+ const resources = (_a = options) === null || _a === void 0 ? void 0 : _a.resources;
611
+ const ssoToken = await this.getSSOToken(resources);
603
612
  const scopeStr = typeof scopes === "string" ? scopes : scopes.join(" ");
604
613
  if (scopeStr === "") {
605
614
  internalLogger.info("Get SSO token");
@@ -608,7 +617,7 @@ class TeamsUserCredential {
608
617
  else {
609
618
  internalLogger.info("Get access token with scopes: " + scopeStr);
610
619
  if (!this.initialized) {
611
- await this.init();
620
+ await this.init(resources);
612
621
  }
613
622
  let tokenResponse;
614
623
  const scopesArray = typeof scopes === "string" ? scopes.split(" ") : scopes;
@@ -654,6 +663,8 @@ class TeamsUserCredential {
654
663
  /**
655
664
  * Get basic user info from SSO token
656
665
  *
666
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
667
+ *
657
668
  * @example
658
669
  * ```typescript
659
670
  * const currentUser = await credential.getUserInfo();
@@ -665,13 +676,13 @@ class TeamsUserCredential {
665
676
  *
666
677
  * @returns Basic user info with user displayName, objectId and preferredUserName.
667
678
  */
668
- async getUserInfo() {
679
+ async getUserInfo(resources) {
669
680
  internalLogger.info("Get basic user info from SSO token");
670
- const ssoToken = await this.getSSOToken();
681
+ const ssoToken = await this.getSSOToken(resources);
671
682
  return getUserInfoFromSsoToken(ssoToken.token);
672
683
  }
673
- async init() {
674
- const ssoToken = await this.getSSOToken();
684
+ async init(resources) {
685
+ const ssoToken = await this.getSSOToken(resources);
675
686
  const info = getTenantIdAndLoginHintFromSsoToken(ssoToken.token);
676
687
  this.loginHint = info.loginHint;
677
688
  this.tid = info.tid;
@@ -690,9 +701,12 @@ class TeamsUserCredential {
690
701
  /**
691
702
  * Get SSO token using teams SDK
692
703
  * 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
704
+ *
705
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
706
+ *
693
707
  * @returns SSO token
694
708
  */
695
- getSSOToken() {
709
+ getSSOToken(resources) {
696
710
  return new Promise((resolve, reject) => {
697
711
  if (this.ssoToken) {
698
712
  if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
@@ -730,7 +744,7 @@ class TeamsUserCredential {
730
744
  internalLogger.error(errorMsg);
731
745
  reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
732
746
  },
733
- resources: [],
747
+ resources: resources !== null && resources !== void 0 ? resources : [],
734
748
  });
735
749
  });
736
750
  }
@@ -1247,8 +1261,9 @@ class TeamsFx {
1247
1261
  this.configuration = new Map();
1248
1262
  this.loadFromEnv();
1249
1263
  if (customConfig) {
1250
- for (const key of Object.keys(customConfig)) {
1251
- const value = customConfig[key];
1264
+ const myConfig = Object.assign({}, customConfig);
1265
+ for (const key of Object.keys(myConfig)) {
1266
+ const value = myConfig[key];
1252
1267
  if (value) {
1253
1268
  this.configuration.set(key, value);
1254
1269
  }
@@ -1296,11 +1311,11 @@ class TeamsFx {
1296
1311
  }
1297
1312
  return this.teamsUserCredential;
1298
1313
  }
1299
- async getUserInfo() {
1300
- return await this.getCredential().getUserInfo();
1314
+ async getUserInfo(resources) {
1315
+ return await this.getCredential().getUserInfo(resources);
1301
1316
  }
1302
- async login(scopes) {
1303
- await this.getCredential().login(scopes);
1317
+ async login(scopes, resources) {
1318
+ await this.getCredential().login(scopes, resources);
1304
1319
  }
1305
1320
  setSsoToken(ssoToken) {
1306
1321
  return this;