@microsoft/teamsfx 0.7.0-beta.01d6a9fb3.0 → 0.7.0-beta.1
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/README.md +27 -7
- package/dist/index.esm2017.js +79 -95
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +89 -64
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +72 -86
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +93 -66
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +6 -6
- package/types/teamsfx.d.ts +8 -7
package/README.md
CHANGED
|
@@ -205,14 +205,13 @@ Use `axios` library to make HTTP request to Azure Function.
|
|
|
205
205
|
|
|
206
206
|
```ts
|
|
207
207
|
const teamsfx = new TeamsFx();
|
|
208
|
-
const
|
|
208
|
+
const credential = teamsfx.getCredential();
|
|
209
|
+
// Create an API client that uses SSO token to authenticate requests
|
|
210
|
+
const apiClient = createApiClient(
|
|
211
|
+
teamsfx.getConfig("apiEndpoint"),
|
|
212
|
+
new BearerTokenAuthProvider(async ()=> (await credential.getToken(""))!.token));
|
|
209
213
|
// Call API hosted in Azure Functions on behalf of user
|
|
210
|
-
const
|
|
211
|
-
const response = await axios.default.get(apiEndpoint + "api/httptrigger1", {
|
|
212
|
-
headers: {
|
|
213
|
-
authorization: "Bearer " + token,
|
|
214
|
-
},
|
|
215
|
-
});
|
|
214
|
+
const response = await apiClient.get("/api/" + functionName);
|
|
216
215
|
```
|
|
217
216
|
|
|
218
217
|
### Access SQL database in Azure Function
|
|
@@ -287,6 +286,27 @@ dialogs.add(
|
|
|
287
286
|
);
|
|
288
287
|
```
|
|
289
288
|
|
|
289
|
+
### Create API client to call existing API in Bot / Azure Function
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
const teamsfx = new TeamsFx();
|
|
293
|
+
|
|
294
|
+
// Create an API Key auth provider. Following auth providers are also available:
|
|
295
|
+
// BearerTokenAuthProvider, BasicAuthProvider, CertificateAuthProvider
|
|
296
|
+
const authProvider = new ApiKeyProvider("your_api_key_name",
|
|
297
|
+
teamsfx.getConfig("YOUR_API_KEY_VALUE"), // This reads the value of YOUR_API_KEY_VALUE environment variable
|
|
298
|
+
ApiKeyLocation.Header);
|
|
299
|
+
|
|
300
|
+
// Create an API client using above auth provider
|
|
301
|
+
// You can also implement AuthProvider interface and use it here
|
|
302
|
+
const apiClient = createApiClient(
|
|
303
|
+
teamsfx.getConfig("YOUR_API_ENDPOINT"), // This reads YOUR_API_ENDPOINT environment variable
|
|
304
|
+
authProvider);
|
|
305
|
+
|
|
306
|
+
// Send a GET request to "relative_api_path"
|
|
307
|
+
const response = await apiClient.get("relative_api_path");
|
|
308
|
+
```
|
|
309
|
+
|
|
290
310
|
## Advanced Customization
|
|
291
311
|
|
|
292
312
|
### Configure log
|
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
|
|
@@ -1492,7 +1476,7 @@ function sendAdaptiveCard(target, card) {
|
|
|
1492
1476
|
*/
|
|
1493
1477
|
class Channel {
|
|
1494
1478
|
/**
|
|
1495
|
-
*
|
|
1479
|
+
* Constructor.
|
|
1496
1480
|
*
|
|
1497
1481
|
* @remarks
|
|
1498
1482
|
* Only work on server side.
|
|
@@ -1557,7 +1541,7 @@ class Channel {
|
|
|
1557
1541
|
*/
|
|
1558
1542
|
class Member {
|
|
1559
1543
|
/**
|
|
1560
|
-
*
|
|
1544
|
+
* Constructor.
|
|
1561
1545
|
*
|
|
1562
1546
|
* @remarks
|
|
1563
1547
|
* Only work on server side.
|