@microsoft/teamsfx 1.2.1 → 2.0.0-alpha.fcb7f02f1.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.
- package/dist/index.esm2017.js +87 -103
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +2 -0
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +80 -94
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +2 -0
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +5 -5
- package/types/teamsfx.d.ts +2 -0
package/dist/index.esm5.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
2
|
import jwt_decode from 'jwt-decode';
|
|
3
|
-
import
|
|
3
|
+
import { app, authentication } from '@microsoft/teams-js';
|
|
4
4
|
import { PublicClientApplication } from '@azure/msal-browser';
|
|
5
5
|
import { Client } from '@microsoft/microsoft-graph-client';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -560,51 +560,48 @@ class TeamsUserCredential {
|
|
|
560
560
|
if (!this.initialized) {
|
|
561
561
|
yield this.init(resources);
|
|
562
562
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
});
|
|
563
|
+
yield app.initialize();
|
|
564
|
+
let result;
|
|
565
|
+
try {
|
|
566
|
+
const params = {
|
|
567
|
+
url: `${this.config.initiateLoginEndpoint}?clientId=${this.config.clientId}&scope=${encodeURI(scopesStr)}&loginHint=${this.loginHint}`,
|
|
568
|
+
width: loginPageWidth,
|
|
569
|
+
height: loginPageHeight,
|
|
570
|
+
};
|
|
571
|
+
result = yield authentication.authenticate(params);
|
|
572
|
+
if (!result) {
|
|
573
|
+
const errorMsg = "Get empty authentication result from MSAL";
|
|
574
|
+
internalLogger.error(errorMsg);
|
|
575
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
catch (err) {
|
|
579
|
+
const errorMsg = `Consent failed for the scope ${scopesStr} with error: ${err.message}`;
|
|
580
|
+
internalLogger.error(errorMsg);
|
|
581
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.ConsentFailed);
|
|
582
|
+
}
|
|
583
|
+
let resultJson = {};
|
|
584
|
+
try {
|
|
585
|
+
resultJson = typeof result == "string" ? JSON.parse(result) : result;
|
|
586
|
+
}
|
|
587
|
+
catch (error) {
|
|
588
|
+
// If can not parse result as Json, will throw error.
|
|
589
|
+
const failedToParseResult = "Failed to parse response to Json.";
|
|
590
|
+
internalLogger.error(failedToParseResult);
|
|
591
|
+
throw new ErrorWithCode(failedToParseResult, ErrorCode.InvalidResponse);
|
|
592
|
+
}
|
|
593
|
+
// If code exists in result, user may using previous auth-start and auth-end page.
|
|
594
|
+
if (resultJson.code) {
|
|
595
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
596
|
+
const usingPreviousAuthPage = "Found auth code in response. Auth code is not support for current version of SDK. " +
|
|
597
|
+
`Please refer to the help link for how to fix the issue: ${helpLink}.`;
|
|
598
|
+
internalLogger.error(usingPreviousAuthPage);
|
|
599
|
+
throw new ErrorWithCode(usingPreviousAuthPage, ErrorCode.InvalidResponse);
|
|
600
|
+
}
|
|
601
|
+
// If sessionStorage exists in result, set the values in current session storage.
|
|
602
|
+
if (resultJson.sessionStorage) {
|
|
603
|
+
this.setSessionStorage(resultJson.sessionStorage);
|
|
604
|
+
}
|
|
608
605
|
});
|
|
609
606
|
}
|
|
610
607
|
/**
|
|
@@ -754,52 +751,48 @@ class TeamsUserCredential {
|
|
|
754
751
|
* @returns SSO token
|
|
755
752
|
*/
|
|
756
753
|
getSSOToken(resources) {
|
|
757
|
-
return
|
|
754
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
758
755
|
if (this.ssoToken) {
|
|
759
756
|
if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
|
|
760
757
|
internalLogger.verbose("Get SSO token from memory cache");
|
|
761
|
-
|
|
762
|
-
return;
|
|
758
|
+
return this.ssoToken;
|
|
763
759
|
}
|
|
764
760
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (!token) {
|
|
770
|
-
const errorMsg = "Get empty SSO token from Teams";
|
|
771
|
-
internalLogger.error(errorMsg);
|
|
772
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
773
|
-
return;
|
|
774
|
-
}
|
|
775
|
-
const tokenObject = parseJwt(token);
|
|
776
|
-
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
777
|
-
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
778
|
-
internalLogger.error(errorMsg);
|
|
779
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
const ssoToken = {
|
|
783
|
-
token,
|
|
784
|
-
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
785
|
-
};
|
|
786
|
-
this.ssoToken = ssoToken;
|
|
787
|
-
resolve(ssoToken);
|
|
788
|
-
},
|
|
789
|
-
failureCallback: (errMessage) => {
|
|
790
|
-
const errorMsg = "Get SSO token failed with error: " + errMessage;
|
|
791
|
-
internalLogger.error(errorMsg);
|
|
792
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
793
|
-
},
|
|
794
|
-
resources: resources !== null && resources !== void 0 ? resources : [],
|
|
795
|
-
});
|
|
796
|
-
});
|
|
761
|
+
const params = { resources: resources !== null && resources !== void 0 ? resources : [] };
|
|
762
|
+
let token;
|
|
763
|
+
try {
|
|
764
|
+
yield app.initialize();
|
|
797
765
|
}
|
|
798
|
-
|
|
799
|
-
const errorMsg = "Initialize teams sdk failed due to not running inside Teams";
|
|
766
|
+
catch (err) {
|
|
767
|
+
const errorMsg = "Initialize teams sdk failed due to not running inside Teams environment";
|
|
768
|
+
internalLogger.error(errorMsg);
|
|
769
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
770
|
+
}
|
|
771
|
+
try {
|
|
772
|
+
token = yield authentication.getAuthToken(params);
|
|
773
|
+
}
|
|
774
|
+
catch (err) {
|
|
775
|
+
const errorMsg = "Get SSO token failed with error: " + err.message;
|
|
776
|
+
internalLogger.error(errorMsg);
|
|
777
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
778
|
+
}
|
|
779
|
+
if (!token) {
|
|
780
|
+
const errorMsg = "Get empty SSO token from Teams";
|
|
800
781
|
internalLogger.error(errorMsg);
|
|
801
|
-
|
|
782
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
802
783
|
}
|
|
784
|
+
const tokenObject = parseJwt(token);
|
|
785
|
+
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
786
|
+
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
787
|
+
internalLogger.error(errorMsg);
|
|
788
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
789
|
+
}
|
|
790
|
+
const ssoToken = {
|
|
791
|
+
token,
|
|
792
|
+
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
793
|
+
};
|
|
794
|
+
this.ssoToken = ssoToken;
|
|
795
|
+
return ssoToken;
|
|
803
796
|
});
|
|
804
797
|
}
|
|
805
798
|
/**
|
|
@@ -840,16 +833,6 @@ class TeamsUserCredential {
|
|
|
840
833
|
throw new ErrorWithCode(errorMessage, ErrorCode.InternalError);
|
|
841
834
|
}
|
|
842
835
|
}
|
|
843
|
-
// Come from here: https://github.com/wictorwilen/msteams-react-base-component/blob/master/src/useTeams.ts
|
|
844
|
-
checkInTeams() {
|
|
845
|
-
if ((window.parent === window.self && window.nativeInterface) ||
|
|
846
|
-
window.navigator.userAgent.includes("Teams/") ||
|
|
847
|
-
window.name === "embedded-page-container" ||
|
|
848
|
-
window.name === "extension-tab-frame") {
|
|
849
|
-
return true;
|
|
850
|
-
}
|
|
851
|
-
return false;
|
|
852
|
-
}
|
|
853
836
|
}
|
|
854
837
|
|
|
855
838
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -973,6 +956,9 @@ function createMicrosoftGraphClient(teamsfx, scopes) {
|
|
|
973
956
|
// Copyright (c) Microsoft Corporation.
|
|
974
957
|
/**
|
|
975
958
|
* Generate connection configuration consumed by tedious.
|
|
959
|
+
*
|
|
960
|
+
* @deprecated we recommend you compose your own Tedious configuration for better flexibility.
|
|
961
|
+
*
|
|
976
962
|
* @remarks
|
|
977
963
|
* Only works in in server side.
|
|
978
964
|
*/
|