@microsoft/teamsfx 2.1.1-alpha.121c64dd9.0 → 2.1.1-alpha.169762110.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/README.md CHANGED
@@ -23,7 +23,7 @@ Please check the [README](https://github.com/OfficeDev/TeamsFx/blob/main/package
23
23
 
24
24
  - Node.js version 10.x.x or higher
25
25
  - A project created by the Teams Toolkit VS Code extension or `teamsfx` CLI tool.
26
- - If your project has installed `botbuilder` related [packages](https://github.com/Microsoft/botbuilder-js#packages) as dependencies, ensure they are of the same version and the version `>= 4.15.0`. ([Issue - all of the BOTBUILDER packages should be the same version](https://github.com/BotBuilderCommunity/botbuilder-community-js/issues/57#issuecomment-508538548))
26
+ - If your project has installed `botbuilder` related [packages](https://github.com/Microsoft/botbuilder-js#packages) as dependencies, ensure they are of the same version and the version `>= 4.18.0`. ([Issue - all of the BOTBUILDER packages should be the same version](https://github.com/BotBuilderCommunity/botbuilder-community-js/issues/57#issuecomment-508538548))
27
27
 
28
28
  ### Install the `@microsoft/teamsfx` package
29
29
 
@@ -36,6 +36,7 @@ npm install @microsoft/teamsfx
36
36
  ### Scenarios
37
37
 
38
38
  TeamsFx SDK is built to be used in browser and NodeJS environment. Common scenarios include:
39
+
39
40
  - Teams tab application
40
41
  - Azure Function
41
42
  - Teams bot
@@ -78,26 +79,30 @@ const profile = await graphClient.api("/users/{object_id_of_another_people}").ge
78
79
  ## Core Concepts & Code Structure
79
80
 
80
81
  ### TeamsFx class
82
+
81
83
  `TeamsFx` class instance reads all TeamsFx settings from environment variables by default. You can also set customized configuration values to override the default values. Please check [Override configuration](#override-configuration) for details.
82
84
 
83
85
  When creating a TeamsFx instance, you also need to specify the identity type. There are 2 identity types:
84
86
 
85
87
  #### User Identity
88
+
86
89
  Using `new TeamsFx(IdentityType.User)` means the application will be authenticated as current Teams user. This one is the default choice. You need to call `TeamsFx:setSsoToken()` when you use user identity in NodeJS environment(without browser).
87
90
 
88
91
  You can use `TeamsFx:getUserInfo()` to get user's basic information.
89
92
  `TeamsFx:login()` is used to let user perform consent process if you want to use SSO to get access token for certain OAuth scopes.
90
93
 
91
94
  #### Application Identity
95
+
92
96
  Using `new TeamsFx(IdentityType.App)` means the application will be authenticated as an application. The permission usually need administrator's approval.
93
97
 
94
98
  `TeamsFx:getCredential()` provides credential instances automatically corresponding to identity type:
99
+
95
100
  - User Identity: It means that you can access resources on behalf of current Teams user.
96
101
  - App Identity: It means that you are acting as a managed app identity which usually need admin consent for resources.
97
102
 
98
103
  ### Credential
99
104
 
100
- //Developers should choose identity type when initializing TeamsFx. SDK provides 2 types: User and App.
105
+ Developers should choose identity type when initializing TeamsFx. SDK provides 2 types: User and App.
101
106
  After developer has specified the identity type when initializing TeamsFx, SDK uses different kinds of credential class to represent the identity and get access token by corresponding auth flow.
102
107
 
103
108
  There are 3 credential classes that are used to help simplifying authentication. They are located under [credential](src/credential) folder.
@@ -106,16 +111,19 @@ Credential classes implements `TokenCredential` interface that is broadly used i
106
111
  Here's the corresponding scenarios that each credential class targets.
107
112
 
108
113
  #### User Identity in browser environment
114
+
109
115
  `TeamsUserCredential` represents Teams current user's identity. Using this credential will request user consent at the first time. It leverages the Teams SSO and On-Behalf-Of flow to do token exchange. SDK uses this credential when developer choose "User" identity in browser environment.
110
116
 
111
117
  Required configuration: initiateLoginEndpoint, clientId.
112
118
 
113
119
  #### User Identity in NodeJS environment
120
+
114
121
  `OnBehalfOfUserCredential` uses On-Behalf-Of flow and need Teams ssoToken. It's designed to be used in Azure Function or Bot scenarios. SDK uses this credential when developer choose "User" identity in NodeJS environment.
115
122
 
116
123
  Required configuration: authorityHost, tenantId, clientId, clientSecret / certificateContent.
117
124
 
118
125
  #### Application Identity in NodeJS environment
126
+
119
127
  `AppCredential` represents the application identity. It is usually used when user is not involved like time-triggered automation job. SDK uses this credential when developer choose "App" identity in NodeJS environment.
120
128
 
121
129
  Required configuration: tenantId, clientId, clientSecret / certificateContent.
@@ -133,12 +141,15 @@ Required configuration: initiateLoginEndpoint, tenantId, clientId, applicationId
133
141
  TeamsFx SDK provides several helper functions to ease the configuration for third-party libraries. They are located under [core](src/core) folder.
134
142
 
135
143
  #### Microsoft Graph Service
144
+
136
145
  `createMicrosoftGraphClient` and `MsGraphAuthProvider` help to create authenticated Graph instance.
137
146
 
138
147
  #### SQL
139
- `getTediousConnectionConfig` returns a tedious connection config.
148
+
149
+ `getTediousConnectionConfig` returns a tedious connection config. This API is now deprecated, we recommend you compose your own Tedious configuration for better flexibility.
140
150
 
141
151
  Required configuration:
152
+
142
153
  - sqlServerEndpoint, sqlUsername, sqlPassword if you want to use user identity
143
154
  - sqlServerEndpoint, sqlIdentityId if you want to use MSI identity
144
155
 
@@ -209,7 +220,8 @@ const credential = teamsfx.getCredential();
209
220
  // Create an API client that uses SSO token to authenticate requests
210
221
  const apiClient = createApiClient(
211
222
  teamsfx.getConfig("apiEndpoint"),
212
- new BearerTokenAuthProvider(async ()=> (await credential.getToken(""))!.token));
223
+ new BearerTokenAuthProvider(async () => (await credential.getToken(""))!.token)
224
+ );
213
225
  // Call API hosted in Azure Functions on behalf of user
214
226
  const response = await apiClient.get("/api/" + functionName);
215
227
  ```
@@ -219,6 +231,8 @@ const response = await apiClient.get("/api/" + functionName);
219
231
  Use `tedious` library to access SQL and leverage `DefaultTediousConnectionConfiguration` that manages authentication.
220
232
  Apart from `tedious`, you can also compose connection config of other SQL libraries based on the result of `sqlConnectionConfig.getConfig()`.
221
233
 
234
+ The `tedious` library is now deprecated, we recommend you compose your own Tedious configuration for better flexibility.
235
+
222
236
  ```ts
223
237
  // Equivalent to:
224
238
  // const sqlConnectConfig = new DefaultTediousConnectionConfiguration({
@@ -243,7 +257,7 @@ connection.on("connect", (error) => {
243
257
 
244
258
  ```ts
245
259
  const teamsfx = new TeamsFx(IdentityType.App, {
246
- certificateContent: "The content of a PEM-encoded public/private key certificate"
260
+ certificateContent: "The content of a PEM-encoded public/private key certificate",
247
261
  });
248
262
  const token = teamsfx.getCredential().getToken();
249
263
  ```
@@ -293,15 +307,18 @@ const teamsfx = new TeamsFx();
293
307
 
294
308
  // Create an API Key auth provider. Following auth providers are also available:
295
309
  // BearerTokenAuthProvider, BasicAuthProvider, CertificateAuthProvider
296
- const authProvider = new ApiKeyProvider("your_api_key_name",
310
+ const authProvider = new ApiKeyProvider(
311
+ "your_api_key_name",
297
312
  teamsfx.getConfig("YOUR_API_KEY_VALUE"), // This reads the value of YOUR_API_KEY_VALUE environment variable
298
- ApiKeyLocation.Header);
313
+ ApiKeyLocation.Header
314
+ );
299
315
 
300
316
  // Create an API client using above auth provider
301
317
  // You can also implement AuthProvider interface and use it here
302
318
  const apiClient = createApiClient(
303
319
  teamsfx.getConfig("YOUR_API_ENDPOINT"), // This reads YOUR_API_ENDPOINT environment variable
304
- authProvider);
320
+ authProvider
321
+ );
305
322
 
306
323
  // Send a GET request to "relative_api_path"
307
324
  const response = await apiClient.get("relative_api_path");
@@ -352,36 +369,38 @@ setLogFunction((level: LogLevel, message: string) => {
352
369
  });
353
370
  ```
354
371
 
355
-
356
372
  ### Override configuration
373
+
357
374
  You can pass custom config when creating `TeamsFx` instance to override default configuration or set required fields when environment variables are missing.
358
375
 
359
376
  - If you have created tab project using VS Code toolkit, the following config values will be used from pre-configured environment variables:
360
- * authorityHost (REACT_APP_AUTHORITY_HOST)
361
- * tenantId (REACT_APP_TENANT_ID)
362
- * clientId (REACT_APP_CLIENT_ID)
363
- * initiateLoginEndpoint (REACT_APP_START_LOGIN_PAGE_URL)
364
- * applicationIdUri (REACT_APP_START_LOGIN_PAGE_URL)
365
- * apiEndpoint (REACT_APP_FUNC_ENDPOINT)
366
- * apiName (REACT_APP_FUNC_NAME)
377
+
378
+ - authorityHost (REACT_APP_AUTHORITY_HOST)
379
+ - tenantId (REACT_APP_TENANT_ID)
380
+ - clientId (REACT_APP_CLIENT_ID)
381
+ - initiateLoginEndpoint (REACT_APP_START_LOGIN_PAGE_URL)
382
+ - applicationIdUri (REACT_APP_START_LOGIN_PAGE_URL)
383
+ - apiEndpoint (REACT_APP_FUNC_ENDPOINT)
384
+ - apiName (REACT_APP_FUNC_NAME)
367
385
 
368
386
  - If you have created Azure Function / Bot project using VS Code toolkit, the following config values will be used from pre-configured environment variables:
369
- * initiateLoginEndpoint (INITIATE_LOGIN_ENDPOINT)
370
- * authorityHost (M365_AUTHORITY_HOST)
371
- * tenantId (M365_TENANT_ID)
372
- * clientId (M365_CLIENT_ID)
373
- * clientSecret (M365_CLIENT_SECRET)
374
- * applicationIdUri (M365_APPLICATION_ID_URI)
375
- * apiEndpoint (API_ENDPOINT)
376
- * sqlServerEndpoint (SQL_ENDPOINT)
377
- * sqlUsername (SQL_USER_NAME)
378
- * sqlPassword (SQL_PASSWORD)
379
- * sqlDatabaseName (SQL_DATABASE_NAME)
380
- * sqlIdentityId (IDENTITY_ID)
387
+ - initiateLoginEndpoint (INITIATE_LOGIN_ENDPOINT)
388
+ - authorityHost (M365_AUTHORITY_HOST)
389
+ - tenantId (M365_TENANT_ID)
390
+ - clientId (M365_CLIENT_ID)
391
+ - clientSecret (M365_CLIENT_SECRET)
392
+ - applicationIdUri (M365_APPLICATION_ID_URI)
393
+ - apiEndpoint (API_ENDPOINT)
394
+ - sqlServerEndpoint (SQL_ENDPOINT)
395
+ - sqlUsername (SQL_USER_NAME)
396
+ - sqlPassword (SQL_PASSWORD)
397
+ - sqlDatabaseName (SQL_DATABASE_NAME)
398
+ - sqlIdentityId (IDENTITY_ID)
381
399
 
382
400
  ## How to fix the breaking change if upgraded from previous SDK version
383
401
 
384
402
  If you are using the version of SDK that has `loadConfiguration()`, you can follow these steps to upgrade to the latest SDK version.
403
+
385
404
  1. Remove `loadConfiguration()` and pass customized settings using `new TeamsFx(IdentityType.User, { ...customConfig })`.
386
405
  2. Replace `new TeamsUserCredential()` with `new TeamsFx()`.
387
406
  3. Replace `new M365TenantCredential()` with `new TeamsFx(IdentityType.App)`.
@@ -390,6 +409,29 @@ If you are using the version of SDK that has `loadConfiguration()`, you can foll
390
409
 
391
410
  Also see [TeamsFx class](#teamsfx-class) for furthur description.
392
411
 
412
+ ## How to use SDK implemented with `CloudAdapter`
413
+
414
+ From `botbuilder@4.16.0`, `BotFrameworkAdapter` is deprecated, and `CloudAdapter` is recommended to be used instead. You can import `ConversationBot` from `BotBuilderCloudAdapter` to use the latest SDK implemented with `CloudAdapter`.
415
+
416
+ ```ts
417
+ const { BotBuilderCloudAdapter } = require("@microsoft/teamsfx");
418
+ const ConversationBot = BotBuilderCloudAdapter.ConversationBot;
419
+
420
+ const commandBot = new ConversationBot({
421
+ // The bot id and password to create CloudAdapter.
422
+ // See https://aka.ms/about-bot-adapter to learn more about adapters.
423
+ adapterConfig: {
424
+ MicrosoftAppId: config.botId,
425
+ MicrosoftAppPassword: config.botPassword,
426
+ MicrosoftAppType: "MultiTenant",
427
+ },
428
+ command: {
429
+ enabled: true,
430
+ commands: [new HelloWorldCommandHandler()],
431
+ },
432
+ });
433
+ ```
434
+
393
435
  ## Next steps
394
436
 
395
437
  Please take a look at the [Samples](https://github.com/OfficeDev/TeamsFx-Samples) project for detailed examples on how to use this library.