@microsoft/teamsfx 2.0.1-alpha.264d12800.0 → 2.0.1-alpha.330ae315b.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.esm2017.mjs
CHANGED
|
@@ -454,17 +454,6 @@ function parseCertificate(certificateContent) {
|
|
|
454
454
|
* Only works in in server side.
|
|
455
455
|
*/
|
|
456
456
|
class AppCredential {
|
|
457
|
-
/**
|
|
458
|
-
* Constructor of AppCredential.
|
|
459
|
-
*
|
|
460
|
-
* @remarks
|
|
461
|
-
* Only works in in server side.
|
|
462
|
-
*
|
|
463
|
-
* @param {AuthenticationConfiguration} authConfig - The authentication configuration. Use environment variables if not provided.
|
|
464
|
-
*
|
|
465
|
-
* @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret or tenant id is not found in config.
|
|
466
|
-
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
467
|
-
*/
|
|
468
457
|
constructor(authConfig) {
|
|
469
458
|
internalLogger.info("Create M365 tenant credential");
|
|
470
459
|
const config = this.loadAndValidateConfig(authConfig);
|
|
@@ -570,19 +559,6 @@ class AppCredential {
|
|
|
570
559
|
* Can only be used in server side.
|
|
571
560
|
*/
|
|
572
561
|
class OnBehalfOfUserCredential {
|
|
573
|
-
/**
|
|
574
|
-
* Constructor of OnBehalfOfUserCredential
|
|
575
|
-
*
|
|
576
|
-
* @remarks
|
|
577
|
-
* Only works in in server side.
|
|
578
|
-
*
|
|
579
|
-
* @param {string} ssoToken - User token provided by Teams SSO feature.
|
|
580
|
-
* @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
|
|
581
|
-
*
|
|
582
|
-
* @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
|
|
583
|
-
* @throws {@link ErrorCode|InternalError} when SSO token is not valid.
|
|
584
|
-
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
585
|
-
*/
|
|
586
562
|
constructor(ssoToken, config) {
|
|
587
563
|
internalLogger.info("Get on behalf of user credential");
|
|
588
564
|
const missingConfigurations = [];
|
|
@@ -725,11 +701,6 @@ class OnBehalfOfUserCredential {
|
|
|
725
701
|
* Can only be used within Teams.
|
|
726
702
|
*/
|
|
727
703
|
class TeamsUserCredential {
|
|
728
|
-
/**
|
|
729
|
-
* Constructor of TeamsUserCredential.
|
|
730
|
-
* @remarks
|
|
731
|
-
* Can only be used within Teams.
|
|
732
|
-
*/
|
|
733
704
|
constructor(authConfig) {
|
|
734
705
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), ErrorCode.RuntimeNotSupported);
|
|
735
706
|
}
|
|
@@ -771,18 +742,8 @@ const defaultScope = "https://graph.microsoft.com/.default";
|
|
|
771
742
|
* Microsoft Graph auth provider for Teams Framework
|
|
772
743
|
*/
|
|
773
744
|
class MsGraphAuthProvider {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
*
|
|
777
|
-
* @param {TeamsFx} teamsfx - Used to provide configuration and auth.
|
|
778
|
-
* @param {string | string[]} scopes - The list of scopes for which the token will have access.
|
|
779
|
-
*
|
|
780
|
-
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
781
|
-
*
|
|
782
|
-
* @returns An instance of MsGraphAuthProvider.
|
|
783
|
-
*/
|
|
784
|
-
constructor(teamsfx, scopes) {
|
|
785
|
-
this.teamsfx = teamsfx;
|
|
745
|
+
constructor(credentialOrTeamsFx, scopes) {
|
|
746
|
+
this.credentialOrTeamsFx = credentialOrTeamsFx;
|
|
786
747
|
let scopesStr = defaultScope;
|
|
787
748
|
if (scopes) {
|
|
788
749
|
validateScopesType(scopes);
|
|
@@ -808,7 +769,15 @@ class MsGraphAuthProvider {
|
|
|
808
769
|
*/
|
|
809
770
|
async getAccessToken() {
|
|
810
771
|
internalLogger.info(`Get Graph Access token with scopes: '${this.scopes}'`);
|
|
811
|
-
|
|
772
|
+
let accessToken;
|
|
773
|
+
if (this.credentialOrTeamsFx.getCredential) {
|
|
774
|
+
accessToken = await this.credentialOrTeamsFx
|
|
775
|
+
.getCredential()
|
|
776
|
+
.getToken(this.scopes);
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
accessToken = await this.credentialOrTeamsFx.getToken(this.scopes);
|
|
780
|
+
}
|
|
812
781
|
return new Promise((resolve, reject) => {
|
|
813
782
|
if (accessToken) {
|
|
814
783
|
resolve(accessToken.token);
|
|
@@ -825,7 +794,6 @@ class MsGraphAuthProvider {
|
|
|
825
794
|
// Copyright (c) Microsoft Corporation.
|
|
826
795
|
/**
|
|
827
796
|
* Get Microsoft graph client.
|
|
828
|
-
*
|
|
829
797
|
* @example
|
|
830
798
|
* Get Microsoft graph client by TokenCredential
|
|
831
799
|
* ```typescript
|
|
@@ -879,6 +847,66 @@ function createMicrosoftGraphClient(teamsfx, scopes) {
|
|
|
879
847
|
authProvider,
|
|
880
848
|
});
|
|
881
849
|
return graphClient;
|
|
850
|
+
}
|
|
851
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
852
|
+
/**
|
|
853
|
+
* Get Microsoft graph client.
|
|
854
|
+
* @example
|
|
855
|
+
* Get Microsoft graph client by TokenCredential
|
|
856
|
+
* ```typescript
|
|
857
|
+
* // In browser: TeamsUserCredential
|
|
858
|
+
* const authConfig: TeamsUserCredentialAuthConfig = {
|
|
859
|
+
* clientId: "xxx",
|
|
860
|
+
initiateLoginEndpoint: "https://xxx/auth-start.html",
|
|
861
|
+
* };
|
|
862
|
+
|
|
863
|
+
* const credential = new TeamsUserCredential(authConfig);
|
|
864
|
+
|
|
865
|
+
* const scope = "User.Read";
|
|
866
|
+
* await credential.login(scope);
|
|
867
|
+
|
|
868
|
+
* const client = createMicrosoftGraphClientWithCredential(credential, scope);
|
|
869
|
+
|
|
870
|
+
* // In node: OnBehalfOfUserCredential
|
|
871
|
+
* const oboAuthConfig: OnBehalfOfCredentialAuthConfig = {
|
|
872
|
+
* authorityHost: "xxx",
|
|
873
|
+
* clientId: "xxx",
|
|
874
|
+
* tenantId: "xxx",
|
|
875
|
+
* clientSecret: "xxx",
|
|
876
|
+
* };
|
|
877
|
+
|
|
878
|
+
* const oboCredential = new OnBehalfOfUserCredential(ssoToken, oboAuthConfig);
|
|
879
|
+
* const scope = "User.Read";
|
|
880
|
+
* const client = createMicrosoftGraphClientWithCredential(oboCredential, scope);
|
|
881
|
+
|
|
882
|
+
* // In node: AppCredential
|
|
883
|
+
* const appAuthConfig: AppCredentialAuthConfig = {
|
|
884
|
+
* authorityHost: "xxx",
|
|
885
|
+
* clientId: "xxx",
|
|
886
|
+
* tenantId: "xxx",
|
|
887
|
+
* clientSecret: "xxx",
|
|
888
|
+
* };
|
|
889
|
+
* const appCredential = new AppCredential(appAuthConfig);
|
|
890
|
+
* const scope = "User.Read";
|
|
891
|
+
* const client = createMicrosoftGraphClientWithCredential(appCredential, scope);
|
|
892
|
+
*
|
|
893
|
+
* const profile = await client.api("/me").get();
|
|
894
|
+
* ```
|
|
895
|
+
*
|
|
896
|
+
* @param {TokenCredential} credential - Used to provide configuration and auth.
|
|
897
|
+
* @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
|
|
898
|
+
*
|
|
899
|
+
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
900
|
+
*
|
|
901
|
+
* @returns Graph client with specified scopes.
|
|
902
|
+
*/
|
|
903
|
+
function createMicrosoftGraphClientWithCredential(credential, scopes) {
|
|
904
|
+
internalLogger.info("Create Microsoft Graph Client");
|
|
905
|
+
const authProvider = new MsGraphAuthProvider(credential, scopes);
|
|
906
|
+
const graphClient = Client.initWithMiddleware({
|
|
907
|
+
authProvider,
|
|
908
|
+
});
|
|
909
|
+
return graphClient;
|
|
882
910
|
}
|
|
883
911
|
|
|
884
912
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -890,6 +918,8 @@ const defaultSQLScope = "https://database.windows.net/";
|
|
|
890
918
|
/**
|
|
891
919
|
* Generate connection configuration consumed by tedious.
|
|
892
920
|
*
|
|
921
|
+
* @deprecated we recommend you compose your own Tedious configuration for better flexibility.
|
|
922
|
+
*
|
|
893
923
|
* @param {TeamsFx} teamsfx - Used to provide configuration and auth
|
|
894
924
|
* @param { string? } databaseName - specify database name to override default one if there are multiple databases.
|
|
895
925
|
*
|
|
@@ -1125,22 +1155,20 @@ class TokenExchangeInvokeResponse {
|
|
|
1125
1155
|
* ```
|
|
1126
1156
|
*/
|
|
1127
1157
|
class TeamsBotSsoPrompt extends Dialog {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
this.settings
|
|
1142
|
-
validateScopesType(settings.scopes);
|
|
1143
|
-
this.loadAndValidateConfig();
|
|
1158
|
+
constructor(authConfig, ...args) {
|
|
1159
|
+
super(arguments.length === 3 ? args[0] : args[1]);
|
|
1160
|
+
if (authConfig.getCredential) {
|
|
1161
|
+
const teamsfx = authConfig;
|
|
1162
|
+
this.authConfig = this.loadAndValidateConfig(teamsfx);
|
|
1163
|
+
this.initiateLoginEndpoint = teamsfx.getConfig("initiateLoginEndpoint");
|
|
1164
|
+
this.settings = args[1];
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
this.initiateLoginEndpoint = args[0];
|
|
1168
|
+
this.authConfig = authConfig;
|
|
1169
|
+
this.settings = args[2];
|
|
1170
|
+
}
|
|
1171
|
+
validateScopesType(this.settings.scopes);
|
|
1144
1172
|
internalLogger.info("Create a new Teams Bot SSO Prompt");
|
|
1145
1173
|
}
|
|
1146
1174
|
/**
|
|
@@ -1237,20 +1265,20 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1237
1265
|
return Dialog.EndOfTurn;
|
|
1238
1266
|
}
|
|
1239
1267
|
}
|
|
1240
|
-
loadAndValidateConfig() {
|
|
1241
|
-
if (
|
|
1242
|
-
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported,
|
|
1268
|
+
loadAndValidateConfig(teamsfx) {
|
|
1269
|
+
if (teamsfx.getIdentityType() !== IdentityType.User) {
|
|
1270
|
+
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported, teamsfx.getIdentityType().toString(), "TeamsBotSsoPrompt");
|
|
1243
1271
|
internalLogger.error(errorMsg);
|
|
1244
1272
|
throw new ErrorWithCode(errorMsg, ErrorCode.IdentityTypeNotSupported);
|
|
1245
1273
|
}
|
|
1246
1274
|
const missingConfigurations = [];
|
|
1247
|
-
if (!
|
|
1275
|
+
if (!teamsfx.hasConfig("initiateLoginEndpoint")) {
|
|
1248
1276
|
missingConfigurations.push("initiateLoginEndpoint");
|
|
1249
1277
|
}
|
|
1250
|
-
if (!
|
|
1278
|
+
if (!teamsfx.hasConfig("clientId")) {
|
|
1251
1279
|
missingConfigurations.push("clientId");
|
|
1252
1280
|
}
|
|
1253
|
-
if (!
|
|
1281
|
+
if (!teamsfx.hasConfig("tenantId")) {
|
|
1254
1282
|
missingConfigurations.push("tenantId");
|
|
1255
1283
|
}
|
|
1256
1284
|
if (missingConfigurations.length != 0) {
|
|
@@ -1258,6 +1286,24 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1258
1286
|
internalLogger.error(errorMsg);
|
|
1259
1287
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidConfiguration);
|
|
1260
1288
|
}
|
|
1289
|
+
let authConfig;
|
|
1290
|
+
if (teamsfx.getConfig("clientSecret")) {
|
|
1291
|
+
authConfig = {
|
|
1292
|
+
authorityHost: teamsfx.getConfig("authorityHost"),
|
|
1293
|
+
clientId: teamsfx.getConfig("clientId"),
|
|
1294
|
+
tenantId: teamsfx.getConfig("tenantId"),
|
|
1295
|
+
clientSecret: teamsfx.getConfig("clientSecret"),
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
authConfig = {
|
|
1300
|
+
authorityHost: teamsfx.getConfig("authorityHost"),
|
|
1301
|
+
clientId: teamsfx.getConfig("clientId"),
|
|
1302
|
+
tenantId: teamsfx.getConfig("tenantId"),
|
|
1303
|
+
certificateContent: teamsfx.getConfig("certificateContent"),
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
return authConfig;
|
|
1261
1307
|
}
|
|
1262
1308
|
/**
|
|
1263
1309
|
* Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
|
|
@@ -1299,7 +1345,7 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1299
1345
|
*/
|
|
1300
1346
|
getSignInResource(loginHint) {
|
|
1301
1347
|
internalLogger.verbose("Get sign in authentication configuration");
|
|
1302
|
-
const signInLink = `${this.
|
|
1348
|
+
const signInLink = `${this.initiateLoginEndpoint}?scope=${encodeURI(this.settings.scopes.join(" "))}&clientId=${this.authConfig.clientId}&tenantId=${this.authConfig.tenantId}&loginHint=${loginHint}`;
|
|
1303
1349
|
internalLogger.verbose("Sign in link: " + signInLink);
|
|
1304
1350
|
const tokenExchangeResource = {
|
|
1305
1351
|
id: v4(),
|
|
@@ -1325,8 +1371,7 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1325
1371
|
}
|
|
1326
1372
|
else {
|
|
1327
1373
|
const ssoToken = context.activity.value.token;
|
|
1328
|
-
this.
|
|
1329
|
-
const credential = this.teamsfx.getCredential();
|
|
1374
|
+
const credential = new OnBehalfOfUserCredential(ssoToken, this.authConfig);
|
|
1330
1375
|
let exchangedToken;
|
|
1331
1376
|
try {
|
|
1332
1377
|
exchangedToken = await credential.getToken(this.settings.scopes);
|
|
@@ -2368,8 +2413,17 @@ function getTargetType(conversationReference) {
|
|
|
2368
2413
|
* @internal
|
|
2369
2414
|
*/
|
|
2370
2415
|
function getTeamsBotInstallationId(context) {
|
|
2371
|
-
var _a, _b, _c
|
|
2372
|
-
|
|
2416
|
+
var _a, _b, _c;
|
|
2417
|
+
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;
|
|
2418
|
+
if (teamId) {
|
|
2419
|
+
return teamId;
|
|
2420
|
+
}
|
|
2421
|
+
// Fallback to use conversation id.
|
|
2422
|
+
// the conversation id is equal to team id only when the bot app is installed into the General channel.
|
|
2423
|
+
if (context.activity.conversation.name === undefined) {
|
|
2424
|
+
return context.activity.conversation.id;
|
|
2425
|
+
}
|
|
2426
|
+
return undefined;
|
|
2373
2427
|
}
|
|
2374
2428
|
|
|
2375
2429
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -3022,6 +3076,7 @@ class NotificationBot {
|
|
|
3022
3076
|
}
|
|
3023
3077
|
/**
|
|
3024
3078
|
* Returns the first {@link Channel} where predicate is true, and undefined otherwise.
|
|
3079
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise undefined will be returned.)
|
|
3025
3080
|
*
|
|
3026
3081
|
* @param predicate find calls predicate once for each channel of the installation,
|
|
3027
3082
|
* until it finds one where predicate returns true. If such a channel is found, find
|
|
@@ -3064,6 +3119,7 @@ class NotificationBot {
|
|
|
3064
3119
|
}
|
|
3065
3120
|
/**
|
|
3066
3121
|
* Returns all {@link Channel} where predicate is true, and empty array otherwise.
|
|
3122
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise empty array will be returned.)
|
|
3067
3123
|
*
|
|
3068
3124
|
* @param predicate find calls predicate for each channel of the installation.
|
|
3069
3125
|
* @returns an array of {@link Channel} where predicate is true, and empty array otherwise.
|
|
@@ -3122,27 +3178,29 @@ let COMMAND_ROUTE_DIALOG = "CommandRouteDialog";
|
|
|
3122
3178
|
* Sso execution dialog, use to handle sso command
|
|
3123
3179
|
*/
|
|
3124
3180
|
class BotSsoExecutionDialog extends ComponentDialog {
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
* @param settings The list of scopes for which the token will have access
|
|
3129
|
-
* @param teamsfx {@link TeamsFx} instance for authentication
|
|
3130
|
-
*/
|
|
3131
|
-
constructor(dedupStorage, ssoPromptSettings, teamsfx, dialogName) {
|
|
3132
|
-
super(dialogName !== null && dialogName !== void 0 ? dialogName : DIALOG_NAME);
|
|
3181
|
+
constructor(dedupStorage, ssoPromptSettings, authConfig, ...args) {
|
|
3182
|
+
var _a;
|
|
3183
|
+
super((_a = (authConfig.getCredential ? args[0] : args[1])) !== null && _a !== void 0 ? _a : DIALOG_NAME);
|
|
3133
3184
|
this.dedupStorageKeys = [];
|
|
3134
3185
|
// Map to store the commandId and triggerPatterns, key: commandId, value: triggerPatterns
|
|
3135
3186
|
this.commandMapping = new Map();
|
|
3187
|
+
const dialogName = authConfig.getCredential ? args[0] : args[1];
|
|
3136
3188
|
if (dialogName) {
|
|
3137
3189
|
DIALOG_NAME = dialogName;
|
|
3138
3190
|
TEAMS_SSO_PROMPT_ID = dialogName + TEAMS_SSO_PROMPT_ID;
|
|
3139
3191
|
COMMAND_ROUTE_DIALOG = dialogName + COMMAND_ROUTE_DIALOG;
|
|
3140
3192
|
}
|
|
3193
|
+
let ssoDialog;
|
|
3194
|
+
if (authConfig.getCredential) {
|
|
3195
|
+
ssoDialog = new TeamsBotSsoPrompt(authConfig, TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3196
|
+
}
|
|
3197
|
+
else {
|
|
3198
|
+
ssoDialog = new TeamsBotSsoPrompt(authConfig, args[0], TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3199
|
+
}
|
|
3200
|
+
this.addDialog(ssoDialog);
|
|
3141
3201
|
this.initialDialogId = COMMAND_ROUTE_DIALOG;
|
|
3142
3202
|
this.dedupStorage = dedupStorage;
|
|
3143
3203
|
this.dedupStorageKeys = [];
|
|
3144
|
-
const ssoDialog = new TeamsBotSsoPrompt(teamsfx, TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3145
|
-
this.addDialog(ssoDialog);
|
|
3146
3204
|
const commandRouteDialog = new WaterfallDialog(COMMAND_ROUTE_DIALOG, [
|
|
3147
3205
|
this.commandRouteStep.bind(this),
|
|
3148
3206
|
]);
|
|
@@ -3728,6 +3786,34 @@ class MessageBuilder {
|
|
|
3728
3786
|
}
|
|
3729
3787
|
|
|
3730
3788
|
// Copyright (c) Microsoft Corporation.
|
|
3789
|
+
/**
|
|
3790
|
+
* Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
|
|
3791
|
+
* This method only work on MessageExtension with Query now.
|
|
3792
|
+
*
|
|
3793
|
+
* @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
|
|
3794
|
+
* @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
|
|
3795
|
+
* @param {string | string[]} scopes - The list of scopes for which the token will have access.
|
|
3796
|
+
*
|
|
3797
|
+
* @returns SignIn link CardAction with 200 status code.
|
|
3798
|
+
*/
|
|
3799
|
+
function getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes) {
|
|
3800
|
+
const scopesArray = getScopesArray(scopes);
|
|
3801
|
+
const signInLink = `${initiateLoginEndpoint}?scope=${encodeURI(scopesArray.join(" "))}&clientId=${authConfig.clientId}&tenantId=${authConfig.tenantId}`;
|
|
3802
|
+
return {
|
|
3803
|
+
composeExtension: {
|
|
3804
|
+
type: "silentAuth",
|
|
3805
|
+
suggestedActions: {
|
|
3806
|
+
actions: [
|
|
3807
|
+
{
|
|
3808
|
+
type: "openUrl",
|
|
3809
|
+
value: signInLink,
|
|
3810
|
+
title: "Message Extension OAuth",
|
|
3811
|
+
},
|
|
3812
|
+
],
|
|
3813
|
+
},
|
|
3814
|
+
},
|
|
3815
|
+
};
|
|
3816
|
+
}
|
|
3731
3817
|
/**
|
|
3732
3818
|
* Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
|
|
3733
3819
|
* This method only work on MessageExtension with Query now.
|
|
@@ -3755,6 +3841,54 @@ function getSignInResponseForMessageExtension(teamsfx, scopes) {
|
|
|
3755
3841
|
},
|
|
3756
3842
|
};
|
|
3757
3843
|
}
|
|
3844
|
+
/**
|
|
3845
|
+
* execution in message extension with SSO token.
|
|
3846
|
+
*
|
|
3847
|
+
* @param {TurnContext} context - The context object for the current turn.
|
|
3848
|
+
* @param {OnBehalfOfCredentialAuthConfig} authConfig - User custom the message extension authentication configuration.
|
|
3849
|
+
* @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
|
|
3850
|
+
* @param {string[]} scopes - The list of scopes for which the token will have access.
|
|
3851
|
+
* @param {function} logic - Business logic when executing the query in message extension with SSO or access token.
|
|
3852
|
+
*
|
|
3853
|
+
* @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
|
|
3854
|
+
* @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
|
|
3855
|
+
* @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
|
|
3856
|
+
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
3857
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
3858
|
+
*
|
|
3859
|
+
* @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
|
|
3860
|
+
*/
|
|
3861
|
+
async function executionWithTokenAndConfig(context, authConfig, initiateLoginEndpoint, scopes, logic) {
|
|
3862
|
+
const valueObj = context.activity.value;
|
|
3863
|
+
if (!valueObj.authentication || !valueObj.authentication.token) {
|
|
3864
|
+
internalLogger.verbose("No AccessToken in request, return silentAuth for AccessToken");
|
|
3865
|
+
return getSignInResponseForMessageExtensionWithAuthConfig(authConfig, initiateLoginEndpoint, scopes);
|
|
3866
|
+
}
|
|
3867
|
+
try {
|
|
3868
|
+
const credential = new OnBehalfOfUserCredential(valueObj.authentication.token, authConfig);
|
|
3869
|
+
const token = await credential.getToken(scopes);
|
|
3870
|
+
const ssoTokenExpiration = parseJwt(valueObj.authentication.token).exp;
|
|
3871
|
+
const tokenRes = {
|
|
3872
|
+
ssoToken: valueObj.authentication.token,
|
|
3873
|
+
ssoTokenExpiration: new Date(ssoTokenExpiration * 1000).toISOString(),
|
|
3874
|
+
token: token.token,
|
|
3875
|
+
expiration: token.expiresOnTimestamp.toString(),
|
|
3876
|
+
connectionName: "",
|
|
3877
|
+
};
|
|
3878
|
+
if (logic) {
|
|
3879
|
+
return await logic(tokenRes);
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
catch (err) {
|
|
3883
|
+
if (err instanceof ErrorWithCode && err.code === ErrorCode.UiRequiredError) {
|
|
3884
|
+
internalLogger.verbose("User not consent yet, return 412 to user consent first.");
|
|
3885
|
+
const response = { status: 412 };
|
|
3886
|
+
await context.sendActivity({ value: response, type: ActivityTypes.InvokeResponse });
|
|
3887
|
+
return;
|
|
3888
|
+
}
|
|
3889
|
+
throw err;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3758
3892
|
/**
|
|
3759
3893
|
* execution in message extension with SSO token.
|
|
3760
3894
|
*
|
|
@@ -3802,9 +3936,11 @@ async function executionWithToken(context, config, scopes, logic) {
|
|
|
3802
3936
|
throw err;
|
|
3803
3937
|
}
|
|
3804
3938
|
}
|
|
3939
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
3805
3940
|
/**
|
|
3806
3941
|
* Users execute query in message extension with SSO or access token.
|
|
3807
3942
|
*
|
|
3943
|
+
*
|
|
3808
3944
|
* @param {TurnContext} context - The context object for the current turn.
|
|
3809
3945
|
* @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
|
|
3810
3946
|
* @param {string| string[]} scopes - The list of scopes for which the token will have access.
|
|
@@ -3825,7 +3961,32 @@ async function handleMessageExtensionQueryWithToken(context, config, scopes, log
|
|
|
3825
3961
|
throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInQueryActivity), ErrorCode.FailedOperation);
|
|
3826
3962
|
}
|
|
3827
3963
|
return await executionWithToken(context, config !== null && config !== void 0 ? config : {}, scopes, logic);
|
|
3964
|
+
}
|
|
3965
|
+
/**
|
|
3966
|
+
* Users execute query in message extension with SSO or access token.
|
|
3967
|
+
*
|
|
3968
|
+
* @param {TurnContext} context - The context object for the current turn.
|
|
3969
|
+
* @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
|
|
3970
|
+
* @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
|
|
3971
|
+
* @param {string| string[]} scopes - The list of scopes for which the token will have access.
|
|
3972
|
+
* @param {function} logic - Business logic when executing the query in message extension with SSO or access token.
|
|
3973
|
+
*
|
|
3974
|
+
* @throws {@link ErrorCode|InternalError} when User invoke not response to message extension query.
|
|
3975
|
+
* @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
|
|
3976
|
+
* @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
|
|
3977
|
+
* @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
|
|
3978
|
+
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
3979
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
3980
|
+
*
|
|
3981
|
+
* @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
|
|
3982
|
+
*/
|
|
3983
|
+
async function handleMessageExtensionQueryWithSSO(context, config, initiateLoginEndpoint, scopes, logic) {
|
|
3984
|
+
if (context.activity.name != "composeExtension/query") {
|
|
3985
|
+
internalLogger.error(ErrorMessage.OnlySupportInQueryActivity);
|
|
3986
|
+
throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInQueryActivity), ErrorCode.FailedOperation);
|
|
3987
|
+
}
|
|
3988
|
+
return await executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
|
|
3828
3989
|
}
|
|
3829
3990
|
|
|
3830
|
-
export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, BotSsoExecutionDialog, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, InvokeResponseFactory, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, SearchScope, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, handleMessageExtensionQueryWithToken, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
3991
|
+
export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, BotSsoExecutionDialog, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, InvokeResponseFactory, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, SearchScope, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createMicrosoftGraphClientWithCredential, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, handleMessageExtensionQueryWithSSO, handleMessageExtensionQueryWithToken, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
3831
3992
|
//# sourceMappingURL=index.esm2017.mjs.map
|