@microsoft/teamsfx 0.4.2-alpha.dc2b9a55.0 → 0.5.0-beta.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/CHANGELOG.md +24 -0
- package/LICENSE +21 -21
- package/NOTICE.txt +9242 -0
- package/README.md +0 -4
- package/dist/index.esm2017.js +96 -100
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +90 -92
- package/dist/index.esm5.js.map +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -45,7 +45,6 @@ Please note that you need to load configuration before using any credentials.
|
|
|
45
45
|
loadConfiguration({
|
|
46
46
|
authentication: {
|
|
47
47
|
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
48
|
-
simpleAuthEndpoint: process.env.REACT_APP_TEAMSFX_ENDPOINT,
|
|
49
48
|
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
50
49
|
},
|
|
51
50
|
});
|
|
@@ -67,7 +66,6 @@ Use the snippet below:
|
|
|
67
66
|
loadConfiguration({
|
|
68
67
|
authentication: {
|
|
69
68
|
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
70
|
-
simpleAuthEndpoint: process.env.REACT_APP_TEAMSFX_ENDPOINT,
|
|
71
69
|
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
72
70
|
},
|
|
73
71
|
});
|
|
@@ -165,7 +163,6 @@ Use `TeamsUserCredential` and `createMicrosoftGraphClient`.
|
|
|
165
163
|
loadConfiguration({
|
|
166
164
|
authentication: {
|
|
167
165
|
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
168
|
-
simpleAuthEndpoint: process.env.REACT_APP_TEAMSFX_ENDPOINT,
|
|
169
166
|
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
170
167
|
},
|
|
171
168
|
});
|
|
@@ -182,7 +179,6 @@ Use `axios` library to make HTTP request to Azure Function.
|
|
|
182
179
|
loadConfiguration({
|
|
183
180
|
authentication: {
|
|
184
181
|
initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
|
|
185
|
-
simpleAuthEndpoint: process.env.REACT_APP_TEAMSFX_ENDPOINT,
|
|
186
182
|
clientId: process.env.REACT_APP_CLIENT_ID,
|
|
187
183
|
},
|
|
188
184
|
});
|
package/dist/index.esm2017.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import jwt_decode from 'jwt-decode';
|
|
2
|
-
import
|
|
2
|
+
import { app, authentication } from '@microsoft/teams-js';
|
|
3
3
|
import { PublicClientApplication } from '@azure/msal-browser';
|
|
4
4
|
import { Client } from '@microsoft/microsoft-graph-client';
|
|
5
5
|
|
|
@@ -604,7 +604,6 @@ class OnBehalfOfUserCredential {
|
|
|
604
604
|
|
|
605
605
|
// Copyright (c) Microsoft Corporation.
|
|
606
606
|
const tokenRefreshTimeSpanInMillisecond = 5 * 60 * 1000;
|
|
607
|
-
const initializeTeamsSdkTimeoutInMillisecond = 5000;
|
|
608
607
|
const loginPageWidth = 600;
|
|
609
608
|
const loginPageHeight = 535;
|
|
610
609
|
/**
|
|
@@ -672,51 +671,48 @@ class TeamsUserCredential {
|
|
|
672
671
|
if (!this.initialized) {
|
|
673
672
|
await this.init();
|
|
674
673
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
});
|
|
718
|
-
});
|
|
719
|
-
});
|
|
674
|
+
await app.initialize();
|
|
675
|
+
let result;
|
|
676
|
+
try {
|
|
677
|
+
const params = {
|
|
678
|
+
url: `${this.config.initiateLoginEndpoint}?clientId=${this.config.clientId}&scope=${encodeURI(scopesStr)}&loginHint=${this.loginHint}`,
|
|
679
|
+
width: loginPageWidth,
|
|
680
|
+
height: loginPageHeight,
|
|
681
|
+
};
|
|
682
|
+
result = await authentication.authenticate(params);
|
|
683
|
+
if (!result) {
|
|
684
|
+
const errorMsg = "Get empty authentication result from MSAL";
|
|
685
|
+
internalLogger.error(errorMsg);
|
|
686
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
catch (err) {
|
|
690
|
+
const errorMsg = `Consent failed for the scope ${scopesStr} with error: ${err.message}`;
|
|
691
|
+
internalLogger.error(errorMsg);
|
|
692
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.ConsentFailed);
|
|
693
|
+
}
|
|
694
|
+
let resultJson = {};
|
|
695
|
+
try {
|
|
696
|
+
resultJson = JSON.parse(result);
|
|
697
|
+
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
// If can not parse result as Json, will throw error.
|
|
700
|
+
const failedToParseResult = "Failed to parse response to Json.";
|
|
701
|
+
internalLogger.error(failedToParseResult);
|
|
702
|
+
throw new ErrorWithCode(failedToParseResult, ErrorCode.InvalidResponse);
|
|
703
|
+
}
|
|
704
|
+
// If code exists in result, user may using previous auth-start and auth-end page.
|
|
705
|
+
if (resultJson.code) {
|
|
706
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
707
|
+
const usingPreviousAuthPage = "Found auth code in response. Auth code is not support for current version of SDK. " +
|
|
708
|
+
`Please refer to the help link for how to fix the issue: ${helpLink}.`;
|
|
709
|
+
internalLogger.error(usingPreviousAuthPage);
|
|
710
|
+
throw new ErrorWithCode(usingPreviousAuthPage, ErrorCode.InvalidResponse);
|
|
711
|
+
}
|
|
712
|
+
// If sessionStorage exists in result, set the values in current session storage.
|
|
713
|
+
if (resultJson.sessionStorage) {
|
|
714
|
+
this.setSessionStorage(resultJson.sessionStorage);
|
|
715
|
+
}
|
|
720
716
|
}
|
|
721
717
|
/**
|
|
722
718
|
* Get access token from credential.
|
|
@@ -849,57 +845,47 @@ class TeamsUserCredential {
|
|
|
849
845
|
* 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
|
|
850
846
|
* @returns SSO token
|
|
851
847
|
*/
|
|
852
|
-
getSSOToken() {
|
|
853
|
-
|
|
854
|
-
if (this.ssoToken) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
resolve(this.ssoToken);
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
848
|
+
async getSSOToken() {
|
|
849
|
+
if (this.ssoToken) {
|
|
850
|
+
if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
|
|
851
|
+
internalLogger.verbose("Get SSO token from memory cache");
|
|
852
|
+
return this.ssoToken;
|
|
860
853
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (!initialized) {
|
|
897
|
-
const errorMsg = "Initialize teams sdk timeout, maybe the code is not running inside Teams";
|
|
898
|
-
internalLogger.error(errorMsg);
|
|
899
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
900
|
-
}
|
|
901
|
-
}, initializeTeamsSdkTimeoutInMillisecond);
|
|
902
|
-
});
|
|
854
|
+
}
|
|
855
|
+
if (this.checkInTeams()) {
|
|
856
|
+
const params = {};
|
|
857
|
+
let token;
|
|
858
|
+
try {
|
|
859
|
+
token = await authentication.getAuthToken(params);
|
|
860
|
+
}
|
|
861
|
+
catch (err) {
|
|
862
|
+
const errorMsg = "Get SSO token failed with error: " + err.message;
|
|
863
|
+
internalLogger.error(errorMsg);
|
|
864
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
865
|
+
}
|
|
866
|
+
if (!token) {
|
|
867
|
+
const errorMsg = "Get empty SSO token from Teams";
|
|
868
|
+
internalLogger.error(errorMsg);
|
|
869
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
870
|
+
}
|
|
871
|
+
const tokenObject = parseJwt(token);
|
|
872
|
+
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
873
|
+
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
874
|
+
internalLogger.error(errorMsg);
|
|
875
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
876
|
+
}
|
|
877
|
+
const ssoToken = {
|
|
878
|
+
token,
|
|
879
|
+
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
880
|
+
};
|
|
881
|
+
this.ssoToken = ssoToken;
|
|
882
|
+
return ssoToken;
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
const errorMsg = "Initialize teams sdk failed due to not running inside Teams";
|
|
886
|
+
internalLogger.error(errorMsg);
|
|
887
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
888
|
+
}
|
|
903
889
|
}
|
|
904
890
|
/**
|
|
905
891
|
* Load and validate authentication configuration
|
|
@@ -926,11 +912,11 @@ class TeamsUserCredential {
|
|
|
926
912
|
internalLogger.error(errorMsg);
|
|
927
913
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidConfiguration);
|
|
928
914
|
}
|
|
929
|
-
setSessionStorage(
|
|
915
|
+
setSessionStorage(sessionStorageValues) {
|
|
930
916
|
try {
|
|
931
|
-
const sessionStorageKeys = Object.keys(
|
|
917
|
+
const sessionStorageKeys = Object.keys(sessionStorageValues);
|
|
932
918
|
sessionStorageKeys.forEach((key) => {
|
|
933
|
-
sessionStorage.setItem(key,
|
|
919
|
+
sessionStorage.setItem(key, sessionStorageValues[key]);
|
|
934
920
|
});
|
|
935
921
|
}
|
|
936
922
|
catch (error) {
|
|
@@ -941,6 +927,16 @@ class TeamsUserCredential {
|
|
|
941
927
|
throw new ErrorWithCode(errorMessage, ErrorCode.InternalError);
|
|
942
928
|
}
|
|
943
929
|
}
|
|
930
|
+
// Come from here: https://github.com/wictorwilen/msteams-react-base-component/blob/master/src/useTeams.ts
|
|
931
|
+
checkInTeams() {
|
|
932
|
+
if ((window.parent === window.self && window.nativeInterface) ||
|
|
933
|
+
window.navigator.userAgent.includes("Teams/") ||
|
|
934
|
+
window.name === "embedded-page-container" ||
|
|
935
|
+
window.name === "extension-tab-frame") {
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
944
940
|
}
|
|
945
941
|
|
|
946
942
|
// Copyright (c) Microsoft Corporation.
|