@microsoft/teamsfx 2.0.1-alpha.ba6cc7dba.0 → 2.0.1-alpha.bfcdf09e3.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 +86 -56
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +242 -81
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +88 -56
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +247 -80
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +7 -7
- package/types/teamsfx.d.ts +2119 -1926
package/dist/index.node.cjs.js
CHANGED
|
@@ -483,17 +483,6 @@ function parseCertificate(certificateContent) {
|
|
|
483
483
|
* Only works in in server side.
|
|
484
484
|
*/
|
|
485
485
|
class AppCredential {
|
|
486
|
-
/**
|
|
487
|
-
* Constructor of AppCredential.
|
|
488
|
-
*
|
|
489
|
-
* @remarks
|
|
490
|
-
* Only works in in server side.
|
|
491
|
-
*
|
|
492
|
-
* @param {AuthenticationConfiguration} authConfig - The authentication configuration. Use environment variables if not provided.
|
|
493
|
-
*
|
|
494
|
-
* @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret or tenant id is not found in config.
|
|
495
|
-
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
496
|
-
*/
|
|
497
486
|
constructor(authConfig) {
|
|
498
487
|
internalLogger.info("Create M365 tenant credential");
|
|
499
488
|
const config = this.loadAndValidateConfig(authConfig);
|
|
@@ -601,19 +590,6 @@ class AppCredential {
|
|
|
601
590
|
* Can only be used in server side.
|
|
602
591
|
*/
|
|
603
592
|
class OnBehalfOfUserCredential {
|
|
604
|
-
/**
|
|
605
|
-
* Constructor of OnBehalfOfUserCredential
|
|
606
|
-
*
|
|
607
|
-
* @remarks
|
|
608
|
-
* Only works in in server side.
|
|
609
|
-
*
|
|
610
|
-
* @param {string} ssoToken - User token provided by Teams SSO feature.
|
|
611
|
-
* @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
|
|
612
|
-
*
|
|
613
|
-
* @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
|
|
614
|
-
* @throws {@link ErrorCode|InternalError} when SSO token is not valid.
|
|
615
|
-
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
616
|
-
*/
|
|
617
593
|
constructor(ssoToken, config) {
|
|
618
594
|
internalLogger.info("Get on behalf of user credential");
|
|
619
595
|
const missingConfigurations = [];
|
|
@@ -758,11 +734,6 @@ class OnBehalfOfUserCredential {
|
|
|
758
734
|
* Can only be used within Teams.
|
|
759
735
|
*/
|
|
760
736
|
class TeamsUserCredential {
|
|
761
|
-
/**
|
|
762
|
-
* Constructor of TeamsUserCredential.
|
|
763
|
-
* @remarks
|
|
764
|
-
* Can only be used within Teams.
|
|
765
|
-
*/
|
|
766
737
|
constructor(authConfig) {
|
|
767
738
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
768
739
|
}
|
|
@@ -808,18 +779,8 @@ const defaultScope = "https://graph.microsoft.com/.default";
|
|
|
808
779
|
* Microsoft Graph auth provider for Teams Framework
|
|
809
780
|
*/
|
|
810
781
|
class MsGraphAuthProvider {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
*
|
|
814
|
-
* @param {TeamsFx} teamsfx - Used to provide configuration and auth.
|
|
815
|
-
* @param {string | string[]} scopes - The list of scopes for which the token will have access.
|
|
816
|
-
*
|
|
817
|
-
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
818
|
-
*
|
|
819
|
-
* @returns An instance of MsGraphAuthProvider.
|
|
820
|
-
*/
|
|
821
|
-
constructor(teamsfx, scopes) {
|
|
822
|
-
this.teamsfx = teamsfx;
|
|
782
|
+
constructor(credentialOrTeamsFx, scopes) {
|
|
783
|
+
this.credentialOrTeamsFx = credentialOrTeamsFx;
|
|
823
784
|
let scopesStr = defaultScope;
|
|
824
785
|
if (scopes) {
|
|
825
786
|
validateScopesType(scopes);
|
|
@@ -846,7 +807,15 @@ class MsGraphAuthProvider {
|
|
|
846
807
|
getAccessToken() {
|
|
847
808
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
848
809
|
internalLogger.info(`Get Graph Access token with scopes: '${this.scopes}'`);
|
|
849
|
-
|
|
810
|
+
let accessToken;
|
|
811
|
+
if (this.credentialOrTeamsFx.getCredential) {
|
|
812
|
+
accessToken = yield this.credentialOrTeamsFx
|
|
813
|
+
.getCredential()
|
|
814
|
+
.getToken(this.scopes);
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
accessToken = yield this.credentialOrTeamsFx.getToken(this.scopes);
|
|
818
|
+
}
|
|
850
819
|
return new Promise((resolve, reject) => {
|
|
851
820
|
if (accessToken) {
|
|
852
821
|
resolve(accessToken.token);
|
|
@@ -864,7 +833,6 @@ class MsGraphAuthProvider {
|
|
|
864
833
|
// Copyright (c) Microsoft Corporation.
|
|
865
834
|
/**
|
|
866
835
|
* Get Microsoft graph client.
|
|
867
|
-
*
|
|
868
836
|
* @example
|
|
869
837
|
* Get Microsoft graph client by TokenCredential
|
|
870
838
|
* ```typescript
|
|
@@ -918,6 +886,66 @@ function createMicrosoftGraphClient(teamsfx, scopes) {
|
|
|
918
886
|
authProvider,
|
|
919
887
|
});
|
|
920
888
|
return graphClient;
|
|
889
|
+
}
|
|
890
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
891
|
+
/**
|
|
892
|
+
* Get Microsoft graph client.
|
|
893
|
+
* @example
|
|
894
|
+
* Get Microsoft graph client by TokenCredential
|
|
895
|
+
* ```typescript
|
|
896
|
+
* // In browser: TeamsUserCredential
|
|
897
|
+
* const authConfig: TeamsUserCredentialAuthConfig = {
|
|
898
|
+
* clientId: "xxx",
|
|
899
|
+
initiateLoginEndpoint: "https://xxx/auth-start.html",
|
|
900
|
+
* };
|
|
901
|
+
|
|
902
|
+
* const credential = new TeamsUserCredential(authConfig);
|
|
903
|
+
|
|
904
|
+
* const scope = "User.Read";
|
|
905
|
+
* await credential.login(scope);
|
|
906
|
+
|
|
907
|
+
* const client = createMicrosoftGraphClientWithCredential(credential, scope);
|
|
908
|
+
|
|
909
|
+
* // In node: OnBehalfOfUserCredential
|
|
910
|
+
* const oboAuthConfig: OnBehalfOfCredentialAuthConfig = {
|
|
911
|
+
* authorityHost: "xxx",
|
|
912
|
+
* clientId: "xxx",
|
|
913
|
+
* tenantId: "xxx",
|
|
914
|
+
* clientSecret: "xxx",
|
|
915
|
+
* };
|
|
916
|
+
|
|
917
|
+
* const oboCredential = new OnBehalfOfUserCredential(ssoToken, oboAuthConfig);
|
|
918
|
+
* const scope = "User.Read";
|
|
919
|
+
* const client = createMicrosoftGraphClientWithCredential(oboCredential, scope);
|
|
920
|
+
|
|
921
|
+
* // In node: AppCredential
|
|
922
|
+
* const appAuthConfig: AppCredentialAuthConfig = {
|
|
923
|
+
* authorityHost: "xxx",
|
|
924
|
+
* clientId: "xxx",
|
|
925
|
+
* tenantId: "xxx",
|
|
926
|
+
* clientSecret: "xxx",
|
|
927
|
+
* };
|
|
928
|
+
* const appCredential = new AppCredential(appAuthConfig);
|
|
929
|
+
* const scope = "User.Read";
|
|
930
|
+
* const client = createMicrosoftGraphClientWithCredential(appCredential, scope);
|
|
931
|
+
*
|
|
932
|
+
* const profile = await client.api("/me").get();
|
|
933
|
+
* ```
|
|
934
|
+
*
|
|
935
|
+
* @param {TokenCredential} credential - Used to provide configuration and auth.
|
|
936
|
+
* @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
|
|
937
|
+
*
|
|
938
|
+
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
939
|
+
*
|
|
940
|
+
* @returns Graph client with specified scopes.
|
|
941
|
+
*/
|
|
942
|
+
function createMicrosoftGraphClientWithCredential(credential, scopes) {
|
|
943
|
+
internalLogger.info("Create Microsoft Graph Client");
|
|
944
|
+
const authProvider = new MsGraphAuthProvider(credential, scopes);
|
|
945
|
+
const graphClient = microsoftGraphClient.Client.initWithMiddleware({
|
|
946
|
+
authProvider,
|
|
947
|
+
});
|
|
948
|
+
return graphClient;
|
|
921
949
|
}
|
|
922
950
|
|
|
923
951
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -929,6 +957,8 @@ const defaultSQLScope = "https://database.windows.net/";
|
|
|
929
957
|
/**
|
|
930
958
|
* Generate connection configuration consumed by tedious.
|
|
931
959
|
*
|
|
960
|
+
* @deprecated we recommend you compose your own Tedious configuration for better flexibility.
|
|
961
|
+
*
|
|
932
962
|
* @param {TeamsFx} teamsfx - Used to provide configuration and auth
|
|
933
963
|
* @param { string? } databaseName - specify database name to override default one if there are multiple databases.
|
|
934
964
|
*
|
|
@@ -1168,22 +1198,20 @@ class TokenExchangeInvokeResponse {
|
|
|
1168
1198
|
* ```
|
|
1169
1199
|
*/
|
|
1170
1200
|
class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
this.settings
|
|
1185
|
-
validateScopesType(settings.scopes);
|
|
1186
|
-
this.loadAndValidateConfig();
|
|
1201
|
+
constructor(authConfig, ...args) {
|
|
1202
|
+
super(arguments.length === 3 ? args[0] : args[1]);
|
|
1203
|
+
if (authConfig.getCredential) {
|
|
1204
|
+
const teamsfx = authConfig;
|
|
1205
|
+
this.authConfig = this.loadAndValidateConfig(teamsfx);
|
|
1206
|
+
this.initiateLoginEndpoint = teamsfx.getConfig("initiateLoginEndpoint");
|
|
1207
|
+
this.settings = args[1];
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
this.initiateLoginEndpoint = args[0];
|
|
1211
|
+
this.authConfig = authConfig;
|
|
1212
|
+
this.settings = args[2];
|
|
1213
|
+
}
|
|
1214
|
+
validateScopesType(this.settings.scopes);
|
|
1187
1215
|
internalLogger.info("Create a new Teams Bot SSO Prompt");
|
|
1188
1216
|
}
|
|
1189
1217
|
/**
|
|
@@ -1284,20 +1312,20 @@ class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
|
|
|
1284
1312
|
}
|
|
1285
1313
|
});
|
|
1286
1314
|
}
|
|
1287
|
-
loadAndValidateConfig() {
|
|
1288
|
-
if (
|
|
1289
|
-
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported,
|
|
1315
|
+
loadAndValidateConfig(teamsfx) {
|
|
1316
|
+
if (teamsfx.getIdentityType() !== exports.IdentityType.User) {
|
|
1317
|
+
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported, teamsfx.getIdentityType().toString(), "TeamsBotSsoPrompt");
|
|
1290
1318
|
internalLogger.error(errorMsg);
|
|
1291
1319
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.IdentityTypeNotSupported);
|
|
1292
1320
|
}
|
|
1293
1321
|
const missingConfigurations = [];
|
|
1294
|
-
if (!
|
|
1322
|
+
if (!teamsfx.hasConfig("initiateLoginEndpoint")) {
|
|
1295
1323
|
missingConfigurations.push("initiateLoginEndpoint");
|
|
1296
1324
|
}
|
|
1297
|
-
if (!
|
|
1325
|
+
if (!teamsfx.hasConfig("clientId")) {
|
|
1298
1326
|
missingConfigurations.push("clientId");
|
|
1299
1327
|
}
|
|
1300
|
-
if (!
|
|
1328
|
+
if (!teamsfx.hasConfig("tenantId")) {
|
|
1301
1329
|
missingConfigurations.push("tenantId");
|
|
1302
1330
|
}
|
|
1303
1331
|
if (missingConfigurations.length != 0) {
|
|
@@ -1305,6 +1333,24 @@ class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
|
|
|
1305
1333
|
internalLogger.error(errorMsg);
|
|
1306
1334
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidConfiguration);
|
|
1307
1335
|
}
|
|
1336
|
+
let authConfig;
|
|
1337
|
+
if (teamsfx.getConfig("clientSecret")) {
|
|
1338
|
+
authConfig = {
|
|
1339
|
+
authorityHost: teamsfx.getConfig("authorityHost"),
|
|
1340
|
+
clientId: teamsfx.getConfig("clientId"),
|
|
1341
|
+
tenantId: teamsfx.getConfig("tenantId"),
|
|
1342
|
+
clientSecret: teamsfx.getConfig("clientSecret"),
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
else {
|
|
1346
|
+
authConfig = {
|
|
1347
|
+
authorityHost: teamsfx.getConfig("authorityHost"),
|
|
1348
|
+
clientId: teamsfx.getConfig("clientId"),
|
|
1349
|
+
tenantId: teamsfx.getConfig("tenantId"),
|
|
1350
|
+
certificateContent: teamsfx.getConfig("certificateContent"),
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
return authConfig;
|
|
1308
1354
|
}
|
|
1309
1355
|
/**
|
|
1310
1356
|
* Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
|
|
@@ -1348,7 +1394,7 @@ class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
|
|
|
1348
1394
|
*/
|
|
1349
1395
|
getSignInResource(loginHint) {
|
|
1350
1396
|
internalLogger.verbose("Get sign in authentication configuration");
|
|
1351
|
-
const signInLink = `${this.
|
|
1397
|
+
const signInLink = `${this.initiateLoginEndpoint}?scope=${encodeURI(this.settings.scopes.join(" "))}&clientId=${this.authConfig.clientId}&tenantId=${this.authConfig.tenantId}&loginHint=${loginHint}`;
|
|
1352
1398
|
internalLogger.verbose("Sign in link: " + signInLink);
|
|
1353
1399
|
const tokenExchangeResource = {
|
|
1354
1400
|
id: uuid.v4(),
|
|
@@ -1375,8 +1421,7 @@ class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
|
|
|
1375
1421
|
}
|
|
1376
1422
|
else {
|
|
1377
1423
|
const ssoToken = context.activity.value.token;
|
|
1378
|
-
this.
|
|
1379
|
-
const credential = this.teamsfx.getCredential();
|
|
1424
|
+
const credential = new OnBehalfOfUserCredential(ssoToken, this.authConfig);
|
|
1380
1425
|
let exchangedToken;
|
|
1381
1426
|
try {
|
|
1382
1427
|
exchangedToken = yield credential.getToken(this.settings.scopes);
|
|
@@ -2441,8 +2486,17 @@ function getTargetType(conversationReference) {
|
|
|
2441
2486
|
* @internal
|
|
2442
2487
|
*/
|
|
2443
2488
|
function getTeamsBotInstallationId(context) {
|
|
2444
|
-
var _a, _b, _c
|
|
2445
|
-
|
|
2489
|
+
var _a, _b, _c;
|
|
2490
|
+
const teamId = (_c = (_b = (_a = context.activity) === null || _a === void 0 ? void 0 : _a.channelData) === null || _b === void 0 ? void 0 : _b.team) === null || _c === void 0 ? void 0 : _c.id;
|
|
2491
|
+
if (teamId) {
|
|
2492
|
+
return teamId;
|
|
2493
|
+
}
|
|
2494
|
+
// Fallback to use conversation id.
|
|
2495
|
+
// the conversation id is equal to team id only when the bot app is installed into the General channel.
|
|
2496
|
+
if (context.activity.conversation.name === undefined) {
|
|
2497
|
+
return context.activity.conversation.id;
|
|
2498
|
+
}
|
|
2499
|
+
return undefined;
|
|
2446
2500
|
}
|
|
2447
2501
|
|
|
2448
2502
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -3137,6 +3191,7 @@ class NotificationBot {
|
|
|
3137
3191
|
}
|
|
3138
3192
|
/**
|
|
3139
3193
|
* Returns the first {@link Channel} where predicate is true, and undefined otherwise.
|
|
3194
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise undefined will be returned.)
|
|
3140
3195
|
*
|
|
3141
3196
|
* @param predicate find calls predicate once for each channel of the installation,
|
|
3142
3197
|
* until it finds one where predicate returns true. If such a channel is found, find
|
|
@@ -3183,6 +3238,7 @@ class NotificationBot {
|
|
|
3183
3238
|
}
|
|
3184
3239
|
/**
|
|
3185
3240
|
* Returns all {@link Channel} where predicate is true, and empty array otherwise.
|
|
3241
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise empty array will be returned.)
|
|
3186
3242
|
*
|
|
3187
3243
|
* @param predicate find calls predicate for each channel of the installation.
|
|
3188
3244
|
* @returns an array of {@link Channel} where predicate is true, and empty array otherwise.
|
|
@@ -3243,27 +3299,29 @@ let COMMAND_ROUTE_DIALOG = "CommandRouteDialog";
|
|
|
3243
3299
|
* Sso execution dialog, use to handle sso command
|
|
3244
3300
|
*/
|
|
3245
3301
|
class BotSsoExecutionDialog extends botbuilderDialogs.ComponentDialog {
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
* @param settings The list of scopes for which the token will have access
|
|
3250
|
-
* @param teamsfx {@link TeamsFx} instance for authentication
|
|
3251
|
-
*/
|
|
3252
|
-
constructor(dedupStorage, ssoPromptSettings, teamsfx, dialogName) {
|
|
3253
|
-
super(dialogName !== null && dialogName !== void 0 ? dialogName : DIALOG_NAME);
|
|
3302
|
+
constructor(dedupStorage, ssoPromptSettings, authConfig, ...args) {
|
|
3303
|
+
var _a;
|
|
3304
|
+
super((_a = (authConfig.getCredential ? args[0] : args[1])) !== null && _a !== void 0 ? _a : DIALOG_NAME);
|
|
3254
3305
|
this.dedupStorageKeys = [];
|
|
3255
3306
|
// Map to store the commandId and triggerPatterns, key: commandId, value: triggerPatterns
|
|
3256
3307
|
this.commandMapping = new Map();
|
|
3308
|
+
const dialogName = authConfig.getCredential ? args[0] : args[1];
|
|
3257
3309
|
if (dialogName) {
|
|
3258
3310
|
DIALOG_NAME = dialogName;
|
|
3259
3311
|
TEAMS_SSO_PROMPT_ID = dialogName + TEAMS_SSO_PROMPT_ID;
|
|
3260
3312
|
COMMAND_ROUTE_DIALOG = dialogName + COMMAND_ROUTE_DIALOG;
|
|
3261
3313
|
}
|
|
3314
|
+
let ssoDialog;
|
|
3315
|
+
if (authConfig.getCredential) {
|
|
3316
|
+
ssoDialog = new TeamsBotSsoPrompt(authConfig, TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3317
|
+
}
|
|
3318
|
+
else {
|
|
3319
|
+
ssoDialog = new TeamsBotSsoPrompt(authConfig, args[0], TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3320
|
+
}
|
|
3321
|
+
this.addDialog(ssoDialog);
|
|
3262
3322
|
this.initialDialogId = COMMAND_ROUTE_DIALOG;
|
|
3263
3323
|
this.dedupStorage = dedupStorage;
|
|
3264
3324
|
this.dedupStorageKeys = [];
|
|
3265
|
-
const ssoDialog = new TeamsBotSsoPrompt(teamsfx, TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3266
|
-
this.addDialog(ssoDialog);
|
|
3267
3325
|
const commandRouteDialog = new botbuilderDialogs.WaterfallDialog(COMMAND_ROUTE_DIALOG, [
|
|
3268
3326
|
this.commandRouteStep.bind(this),
|
|
3269
3327
|
]);
|
|
@@ -3872,6 +3930,34 @@ class MessageBuilder {
|
|
|
3872
3930
|
}
|
|
3873
3931
|
|
|
3874
3932
|
// Copyright (c) Microsoft Corporation.
|
|
3933
|
+
/**
|
|
3934
|
+
* Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
|
|
3935
|
+
* This method only work on MessageExtension with Query now.
|
|
3936
|
+
*
|
|
3937
|
+
* @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
|
|
3938
|
+
* @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
|
|
3939
|
+
* @param {string | string[]} scopes - The list of scopes for which the token will have access.
|
|
3940
|
+
*
|
|
3941
|
+
* @returns SignIn link CardAction with 200 status code.
|
|
3942
|
+
*/
|
|
3943
|
+
function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
|
|
3944
|
+
const scopesArray = getScopesArray(scopes);
|
|
3945
|
+
const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
|
|
3946
|
+
return {
|
|
3947
|
+
composeExtension: {
|
|
3948
|
+
type: "silentAuth",
|
|
3949
|
+
suggestedActions: {
|
|
3950
|
+
actions: [
|
|
3951
|
+
{
|
|
3952
|
+
type: "openUrl",
|
|
3953
|
+
value: signInLink,
|
|
3954
|
+
title: "Message Extension OAuth",
|
|
3955
|
+
},
|
|
3956
|
+
],
|
|
3957
|
+
},
|
|
3958
|
+
},
|
|
3959
|
+
};
|
|
3960
|
+
}
|
|
3875
3961
|
/**
|
|
3876
3962
|
* Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
|
|
3877
3963
|
* This method only work on MessageExtension with Query now.
|
|
@@ -3899,6 +3985,56 @@ function getSignInResponseForMessageExtension(teamsfx, scopes) {
|
|
|
3899
3985
|
},
|
|
3900
3986
|
};
|
|
3901
3987
|
}
|
|
3988
|
+
/**
|
|
3989
|
+
* execution in message extension with SSO token.
|
|
3990
|
+
*
|
|
3991
|
+
* @param {TurnContext} context - The context object for the current turn.
|
|
3992
|
+
* @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
|
|
3993
|
+
* @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
|
|
3994
|
+
* @param {string[]} scopes - The list of scopes for which the token will have access.
|
|
3995
|
+
* @param {function} logic - Business logic when executing the query in message extension with SSO or access token.
|
|
3996
|
+
*
|
|
3997
|
+
* @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
|
|
3998
|
+
* @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
|
|
3999
|
+
* @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
|
|
4000
|
+
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
4001
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
4002
|
+
*
|
|
4003
|
+
* @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
|
|
4004
|
+
*/
|
|
4005
|
+
function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint, scopes, logic) {
|
|
4006
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4007
|
+
const valueObj = context.activity.value;
|
|
4008
|
+
if (!valueObj.authentication || !valueObj.authentication.token) {
|
|
4009
|
+
internalLogger.verbose("No AccessToken in request, return silentAuth for AccessToken");
|
|
4010
|
+
return getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
|
|
4011
|
+
}
|
|
4012
|
+
try {
|
|
4013
|
+
const credential = new OnBehalfOfUserCredential(valueObj.authentication.token, authConfig);
|
|
4014
|
+
const token = yield credential.getToken(scopes);
|
|
4015
|
+
const ssoTokenExpiration = parseJwt(valueObj.authentication.token).exp;
|
|
4016
|
+
const tokenRes = {
|
|
4017
|
+
ssoToken: valueObj.authentication.token,
|
|
4018
|
+
ssoTokenExpiration: new Date(ssoTokenExpiration * 1000).toISOString(),
|
|
4019
|
+
token: token.token,
|
|
4020
|
+
expiration: token.expiresOnTimestamp.toString(),
|
|
4021
|
+
connectionName: "",
|
|
4022
|
+
};
|
|
4023
|
+
if (logic) {
|
|
4024
|
+
return yield logic(tokenRes);
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
catch (err) {
|
|
4028
|
+
if (err instanceof ErrorWithCode && err.code === exports.ErrorCode.UiRequiredError) {
|
|
4029
|
+
internalLogger.verbose("User not consent yet, return 412 to user consent first.");
|
|
4030
|
+
const response = { status: 412 };
|
|
4031
|
+
yield context.sendActivity({ value: response, type: botbuilder.ActivityTypes.InvokeResponse });
|
|
4032
|
+
return;
|
|
4033
|
+
}
|
|
4034
|
+
throw err;
|
|
4035
|
+
}
|
|
4036
|
+
});
|
|
4037
|
+
}
|
|
3902
4038
|
/**
|
|
3903
4039
|
* execution in message extension with SSO token.
|
|
3904
4040
|
*
|
|
@@ -3948,9 +4084,11 @@ function executionWithToken(context, config, scopes, logic) {
|
|
|
3948
4084
|
}
|
|
3949
4085
|
});
|
|
3950
4086
|
}
|
|
4087
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
3951
4088
|
/**
|
|
3952
4089
|
* Users execute query in message extension with SSO or access token.
|
|
3953
4090
|
*
|
|
4091
|
+
*
|
|
3954
4092
|
* @param {TurnContext} context - The context object for the current turn.
|
|
3955
4093
|
* @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
|
|
3956
4094
|
* @param {string| string[]} scopes - The list of scopes for which the token will have access.
|
|
@@ -3973,6 +4111,33 @@ function handleMessageExtensionQueryWithToken(context, config, scopes, logic) {
|
|
|
3973
4111
|
}
|
|
3974
4112
|
return yield executionWithToken(context, config !== null && config !== void 0 ? config : {}, scopes, logic);
|
|
3975
4113
|
});
|
|
4114
|
+
}
|
|
4115
|
+
/**
|
|
4116
|
+
* Users execute query in message extension with SSO or access token.
|
|
4117
|
+
*
|
|
4118
|
+
* @param {TurnContext} context - The context object for the current turn.
|
|
4119
|
+
* @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
|
|
4120
|
+
* @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
|
|
4121
|
+
* @param {string| string[]} scopes - The list of scopes for which the token will have access.
|
|
4122
|
+
* @param {function} logic - Business logic when executing the query in message extension with SSO or access token.
|
|
4123
|
+
*
|
|
4124
|
+
* @throws {@link ErrorCode|InternalError} when User invoke not response to message extension query.
|
|
4125
|
+
* @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
|
|
4126
|
+
* @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
|
|
4127
|
+
* @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
|
|
4128
|
+
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
4129
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
4130
|
+
*
|
|
4131
|
+
* @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
|
|
4132
|
+
*/
|
|
4133
|
+
function handleMessageExtensionQueryWithSSO(context, config, initiateLoginEndpoint, scopes, logic) {
|
|
4134
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4135
|
+
if (context.activity.name != "composeExtension/query") {
|
|
4136
|
+
internalLogger.error(ErrorMessage.OnlySupportInQueryActivity);
|
|
4137
|
+
throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInQueryActivity), exports.ErrorCode.FailedOperation);
|
|
4138
|
+
}
|
|
4139
|
+
return yield executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
|
|
4140
|
+
});
|
|
3976
4141
|
}
|
|
3977
4142
|
|
|
3978
4143
|
exports.ApiKeyProvider = ApiKeyProvider;
|
|
@@ -3998,10 +4163,12 @@ exports.TeamsFx = TeamsFx;
|
|
|
3998
4163
|
exports.TeamsUserCredential = TeamsUserCredential;
|
|
3999
4164
|
exports.createApiClient = createApiClient;
|
|
4000
4165
|
exports.createMicrosoftGraphClient = createMicrosoftGraphClient;
|
|
4166
|
+
exports.createMicrosoftGraphClientWithCredential = createMicrosoftGraphClientWithCredential;
|
|
4001
4167
|
exports.createPemCertOption = createPemCertOption;
|
|
4002
4168
|
exports.createPfxCertOption = createPfxCertOption;
|
|
4003
4169
|
exports.getLogLevel = getLogLevel;
|
|
4004
4170
|
exports.getTediousConnectionConfig = getTediousConnectionConfig;
|
|
4171
|
+
exports.handleMessageExtensionQueryWithSSO = handleMessageExtensionQueryWithSSO;
|
|
4005
4172
|
exports.handleMessageExtensionQueryWithToken = handleMessageExtensionQueryWithToken;
|
|
4006
4173
|
exports.sendAdaptiveCard = sendAdaptiveCard;
|
|
4007
4174
|
exports.sendMessage = sendMessage;
|