@microsoft/teamsfx 1.0.0-rc.0 → 2.0.0-experimental.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 +28 -0
- package/LICENSE +21 -21
- package/NOTICE.txt +9242 -0
- package/dist/index.esm2017.js +77 -93
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +70 -84
- package/dist/index.esm5.js.map +1 -1
- package/package.json +5 -5
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
|
import axios from 'axios';
|
|
@@ -548,51 +548,48 @@ class TeamsUserCredential {
|
|
|
548
548
|
if (!this.initialized) {
|
|
549
549
|
await this.init();
|
|
550
550
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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
|
-
});
|
|
551
|
+
await app.initialize();
|
|
552
|
+
let result;
|
|
553
|
+
try {
|
|
554
|
+
const params = {
|
|
555
|
+
url: `${this.config.initiateLoginEndpoint}?clientId=${this.config.clientId}&scope=${encodeURI(scopesStr)}&loginHint=${this.loginHint}`,
|
|
556
|
+
width: loginPageWidth,
|
|
557
|
+
height: loginPageHeight,
|
|
558
|
+
};
|
|
559
|
+
result = await authentication.authenticate(params);
|
|
560
|
+
if (!result) {
|
|
561
|
+
const errorMsg = "Get empty authentication result from MSAL";
|
|
562
|
+
internalLogger.error(errorMsg);
|
|
563
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
catch (err) {
|
|
567
|
+
const errorMsg = `Consent failed for the scope ${scopesStr} with error: ${err.message}`;
|
|
568
|
+
internalLogger.error(errorMsg);
|
|
569
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.ConsentFailed);
|
|
570
|
+
}
|
|
571
|
+
let resultJson = {};
|
|
572
|
+
try {
|
|
573
|
+
resultJson = typeof result == "string" ? JSON.parse(result) : result;
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
// If can not parse result as Json, will throw error.
|
|
577
|
+
const failedToParseResult = "Failed to parse response to Json.";
|
|
578
|
+
internalLogger.error(failedToParseResult);
|
|
579
|
+
throw new ErrorWithCode(failedToParseResult, ErrorCode.InvalidResponse);
|
|
580
|
+
}
|
|
581
|
+
// If code exists in result, user may using previous auth-start and auth-end page.
|
|
582
|
+
if (resultJson.code) {
|
|
583
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
584
|
+
const usingPreviousAuthPage = "Found auth code in response. Auth code is not support for current version of SDK. " +
|
|
585
|
+
`Please refer to the help link for how to fix the issue: ${helpLink}.`;
|
|
586
|
+
internalLogger.error(usingPreviousAuthPage);
|
|
587
|
+
throw new ErrorWithCode(usingPreviousAuthPage, ErrorCode.InvalidResponse);
|
|
588
|
+
}
|
|
589
|
+
// If sessionStorage exists in result, set the values in current session storage.
|
|
590
|
+
if (resultJson.sessionStorage) {
|
|
591
|
+
this.setSessionStorage(resultJson.sessionStorage);
|
|
592
|
+
}
|
|
596
593
|
}
|
|
597
594
|
/**
|
|
598
595
|
* Get access token from credential.
|
|
@@ -725,54 +722,41 @@ class TeamsUserCredential {
|
|
|
725
722
|
* 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
|
|
726
723
|
* @returns SSO token
|
|
727
724
|
*/
|
|
728
|
-
getSSOToken() {
|
|
729
|
-
|
|
730
|
-
if (this.ssoToken) {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
resolve(this.ssoToken);
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
725
|
+
async getSSOToken() {
|
|
726
|
+
if (this.ssoToken) {
|
|
727
|
+
if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
|
|
728
|
+
internalLogger.verbose("Get SSO token from memory cache");
|
|
729
|
+
return this.ssoToken;
|
|
736
730
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
resources: [],
|
|
767
|
-
});
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
const errorMsg = "Initialize teams sdk failed due to not running inside Teams";
|
|
772
|
-
internalLogger.error(errorMsg);
|
|
773
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
774
|
-
}
|
|
775
|
-
});
|
|
731
|
+
}
|
|
732
|
+
const params = {};
|
|
733
|
+
let token;
|
|
734
|
+
try {
|
|
735
|
+
await app.initialize();
|
|
736
|
+
token = await authentication.getAuthToken(params);
|
|
737
|
+
}
|
|
738
|
+
catch (err) {
|
|
739
|
+
const errorMsg = "Get SSO token failed with error: " + err.message;
|
|
740
|
+
internalLogger.error(errorMsg);
|
|
741
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
742
|
+
}
|
|
743
|
+
if (!token) {
|
|
744
|
+
const errorMsg = "Get empty SSO token from Teams";
|
|
745
|
+
internalLogger.error(errorMsg);
|
|
746
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
747
|
+
}
|
|
748
|
+
const tokenObject = parseJwt(token);
|
|
749
|
+
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
750
|
+
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
751
|
+
internalLogger.error(errorMsg);
|
|
752
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
753
|
+
}
|
|
754
|
+
const ssoToken = {
|
|
755
|
+
token,
|
|
756
|
+
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
757
|
+
};
|
|
758
|
+
this.ssoToken = ssoToken;
|
|
759
|
+
return ssoToken;
|
|
776
760
|
}
|
|
777
761
|
/**
|
|
778
762
|
* Load and validate authentication configuration
|