@microsoft/teamsfx 2.0.1-alpha.7cc75315f.0 → 2.0.1-alpha.abb9aa5bf.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 +83 -56
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +240 -81
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +85 -56
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +245 -80
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +7 -7
- package/types/teamsfx.d.ts +2119 -1928
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.
|
|
@@ -1127,22 +1155,20 @@ class TokenExchangeInvokeResponse {
|
|
|
1127
1155
|
* ```
|
|
1128
1156
|
*/
|
|
1129
1157
|
class TeamsBotSsoPrompt extends Dialog {
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
this.settings
|
|
1144
|
-
validateScopesType(settings.scopes);
|
|
1145
|
-
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);
|
|
1146
1172
|
internalLogger.info("Create a new Teams Bot SSO Prompt");
|
|
1147
1173
|
}
|
|
1148
1174
|
/**
|
|
@@ -1239,20 +1265,20 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1239
1265
|
return Dialog.EndOfTurn;
|
|
1240
1266
|
}
|
|
1241
1267
|
}
|
|
1242
|
-
loadAndValidateConfig() {
|
|
1243
|
-
if (
|
|
1244
|
-
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported,
|
|
1268
|
+
loadAndValidateConfig(teamsfx) {
|
|
1269
|
+
if (teamsfx.getIdentityType() !== IdentityType.User) {
|
|
1270
|
+
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported, teamsfx.getIdentityType().toString(), "TeamsBotSsoPrompt");
|
|
1245
1271
|
internalLogger.error(errorMsg);
|
|
1246
1272
|
throw new ErrorWithCode(errorMsg, ErrorCode.IdentityTypeNotSupported);
|
|
1247
1273
|
}
|
|
1248
1274
|
const missingConfigurations = [];
|
|
1249
|
-
if (!
|
|
1275
|
+
if (!teamsfx.hasConfig("initiateLoginEndpoint")) {
|
|
1250
1276
|
missingConfigurations.push("initiateLoginEndpoint");
|
|
1251
1277
|
}
|
|
1252
|
-
if (!
|
|
1278
|
+
if (!teamsfx.hasConfig("clientId")) {
|
|
1253
1279
|
missingConfigurations.push("clientId");
|
|
1254
1280
|
}
|
|
1255
|
-
if (!
|
|
1281
|
+
if (!teamsfx.hasConfig("tenantId")) {
|
|
1256
1282
|
missingConfigurations.push("tenantId");
|
|
1257
1283
|
}
|
|
1258
1284
|
if (missingConfigurations.length != 0) {
|
|
@@ -1260,6 +1286,24 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1260
1286
|
internalLogger.error(errorMsg);
|
|
1261
1287
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidConfiguration);
|
|
1262
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;
|
|
1263
1307
|
}
|
|
1264
1308
|
/**
|
|
1265
1309
|
* Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
|
|
@@ -1301,7 +1345,7 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1301
1345
|
*/
|
|
1302
1346
|
getSignInResource(loginHint) {
|
|
1303
1347
|
internalLogger.verbose("Get sign in authentication configuration");
|
|
1304
|
-
const signInLink = `${this.
|
|
1348
|
+
const signInLink = `${this.initiateLoginEndpoint}?scope=${encodeURI(this.settings.scopes.join(" "))}&clientId=${this.authConfig.clientId}&tenantId=${this.authConfig.tenantId}&loginHint=${loginHint}`;
|
|
1305
1349
|
internalLogger.verbose("Sign in link: " + signInLink);
|
|
1306
1350
|
const tokenExchangeResource = {
|
|
1307
1351
|
id: v4(),
|
|
@@ -1327,8 +1371,7 @@ class TeamsBotSsoPrompt extends Dialog {
|
|
|
1327
1371
|
}
|
|
1328
1372
|
else {
|
|
1329
1373
|
const ssoToken = context.activity.value.token;
|
|
1330
|
-
this.
|
|
1331
|
-
const credential = this.teamsfx.getCredential();
|
|
1374
|
+
const credential = new OnBehalfOfUserCredential(ssoToken, this.authConfig);
|
|
1332
1375
|
let exchangedToken;
|
|
1333
1376
|
try {
|
|
1334
1377
|
exchangedToken = await credential.getToken(this.settings.scopes);
|
|
@@ -2370,8 +2413,17 @@ function getTargetType(conversationReference) {
|
|
|
2370
2413
|
* @internal
|
|
2371
2414
|
*/
|
|
2372
2415
|
function getTeamsBotInstallationId(context) {
|
|
2373
|
-
var _a, _b, _c
|
|
2374
|
-
|
|
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;
|
|
2375
2427
|
}
|
|
2376
2428
|
|
|
2377
2429
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -3024,6 +3076,7 @@ class NotificationBot {
|
|
|
3024
3076
|
}
|
|
3025
3077
|
/**
|
|
3026
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.)
|
|
3027
3080
|
*
|
|
3028
3081
|
* @param predicate find calls predicate once for each channel of the installation,
|
|
3029
3082
|
* until it finds one where predicate returns true. If such a channel is found, find
|
|
@@ -3066,6 +3119,7 @@ class NotificationBot {
|
|
|
3066
3119
|
}
|
|
3067
3120
|
/**
|
|
3068
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.)
|
|
3069
3123
|
*
|
|
3070
3124
|
* @param predicate find calls predicate for each channel of the installation.
|
|
3071
3125
|
* @returns an array of {@link Channel} where predicate is true, and empty array otherwise.
|
|
@@ -3124,27 +3178,29 @@ let COMMAND_ROUTE_DIALOG = "CommandRouteDialog";
|
|
|
3124
3178
|
* Sso execution dialog, use to handle sso command
|
|
3125
3179
|
*/
|
|
3126
3180
|
class BotSsoExecutionDialog extends ComponentDialog {
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
* @param settings The list of scopes for which the token will have access
|
|
3131
|
-
* @param teamsfx {@link TeamsFx} instance for authentication
|
|
3132
|
-
*/
|
|
3133
|
-
constructor(dedupStorage, ssoPromptSettings, teamsfx, dialogName) {
|
|
3134
|
-
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);
|
|
3135
3184
|
this.dedupStorageKeys = [];
|
|
3136
3185
|
// Map to store the commandId and triggerPatterns, key: commandId, value: triggerPatterns
|
|
3137
3186
|
this.commandMapping = new Map();
|
|
3187
|
+
const dialogName = authConfig.getCredential ? args[0] : args[1];
|
|
3138
3188
|
if (dialogName) {
|
|
3139
3189
|
DIALOG_NAME = dialogName;
|
|
3140
3190
|
TEAMS_SSO_PROMPT_ID = dialogName + TEAMS_SSO_PROMPT_ID;
|
|
3141
3191
|
COMMAND_ROUTE_DIALOG = dialogName + COMMAND_ROUTE_DIALOG;
|
|
3142
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);
|
|
3143
3201
|
this.initialDialogId = COMMAND_ROUTE_DIALOG;
|
|
3144
3202
|
this.dedupStorage = dedupStorage;
|
|
3145
3203
|
this.dedupStorageKeys = [];
|
|
3146
|
-
const ssoDialog = new TeamsBotSsoPrompt(teamsfx, TEAMS_SSO_PROMPT_ID, ssoPromptSettings);
|
|
3147
|
-
this.addDialog(ssoDialog);
|
|
3148
3204
|
const commandRouteDialog = new WaterfallDialog(COMMAND_ROUTE_DIALOG, [
|
|
3149
3205
|
this.commandRouteStep.bind(this),
|
|
3150
3206
|
]);
|
|
@@ -3730,6 +3786,34 @@ class MessageBuilder {
|
|
|
3730
3786
|
}
|
|
3731
3787
|
|
|
3732
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
|
+
}
|
|
3733
3817
|
/**
|
|
3734
3818
|
* Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions.
|
|
3735
3819
|
* This method only work on MessageExtension with Query now.
|
|
@@ -3757,6 +3841,54 @@ function getSignInResponseForMessageExtension(teamsfx, scopes) {
|
|
|
3757
3841
|
},
|
|
3758
3842
|
};
|
|
3759
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
|
+
}
|
|
3760
3892
|
/**
|
|
3761
3893
|
* execution in message extension with SSO token.
|
|
3762
3894
|
*
|
|
@@ -3804,9 +3936,11 @@ async function executionWithToken(context, config, scopes, logic) {
|
|
|
3804
3936
|
throw err;
|
|
3805
3937
|
}
|
|
3806
3938
|
}
|
|
3939
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
3807
3940
|
/**
|
|
3808
3941
|
* Users execute query in message extension with SSO or access token.
|
|
3809
3942
|
*
|
|
3943
|
+
*
|
|
3810
3944
|
* @param {TurnContext} context - The context object for the current turn.
|
|
3811
3945
|
* @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
|
|
3812
3946
|
* @param {string| string[]} scopes - The list of scopes for which the token will have access.
|
|
@@ -3827,7 +3961,32 @@ async function handleMessageExtensionQueryWithToken(context, config, scopes, log
|
|
|
3827
3961
|
throw new ErrorWithCode(formatString(ErrorMessage.OnlySupportInQueryActivity), ErrorCode.FailedOperation);
|
|
3828
3962
|
}
|
|
3829
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);
|
|
3830
3989
|
}
|
|
3831
3990
|
|
|
3832
|
-
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 };
|
|
3833
3992
|
//# sourceMappingURL=index.esm2017.mjs.map
|