@microsoft/teamsfx 0.4.2-alpha.01a113d2.0 → 0.4.2-alpha.4ce002ea.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 +0 -4
- package/dist/index.esm2017.js +9 -10
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +2 -2
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +300 -384
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +435 -552
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +2 -2
- package/types/teamsfx.d.ts +2 -2
package/dist/index.node.cjs.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var jwt_decode = require('jwt-decode');
|
|
6
|
+
var tslib = require('tslib');
|
|
7
7
|
var msalNode = require('@azure/msal-node');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
9
|
var microsoftGraphClient = require('@microsoft/microsoft-graph-client');
|
|
@@ -17,6 +17,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
17
17
|
var jwt_decode__default = /*#__PURE__*/_interopDefaultLegacy(jwt_decode);
|
|
18
18
|
|
|
19
19
|
// Copyright (c) Microsoft Corporation.
|
|
20
|
+
// Licensed under the MIT license.
|
|
20
21
|
/**
|
|
21
22
|
* Error code to trace the error types.
|
|
22
23
|
* @beta
|
|
@@ -68,38 +69,34 @@ exports.ErrorCode = void 0;
|
|
|
68
69
|
*/
|
|
69
70
|
ErrorCode["FailedOperation"] = "FailedOperation";
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
+
* Invalid response error.
|
|
72
73
|
*/
|
|
73
|
-
ErrorCode["
|
|
74
|
+
ErrorCode["InvalidResponse"] = "InvalidResponse";
|
|
74
75
|
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
75
76
|
/**
|
|
76
77
|
* @internal
|
|
77
78
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
|
|
94
|
-
return ErrorMessage;
|
|
95
|
-
}());
|
|
79
|
+
class ErrorMessage {
|
|
80
|
+
}
|
|
81
|
+
// InvalidConfiguration Error
|
|
82
|
+
ErrorMessage.InvalidConfiguration = "{0} in configuration is invalid: {1}.";
|
|
83
|
+
ErrorMessage.ConfigurationNotExists = "Configuration does not exist. {0}";
|
|
84
|
+
ErrorMessage.ResourceConfigurationNotExists = "{0} resource configuration does not exist.";
|
|
85
|
+
ErrorMessage.MissingResourceConfiguration = "Missing resource configuration with type: {0}, name: {1}.";
|
|
86
|
+
ErrorMessage.AuthenticationConfigurationNotExists = "Authentication configuration does not exist.";
|
|
87
|
+
// RuntimeNotSupported Error
|
|
88
|
+
ErrorMessage.BrowserRuntimeNotSupported = "{0} is not supported in browser.";
|
|
89
|
+
ErrorMessage.NodejsRuntimeNotSupported = "{0} is not supported in Node.";
|
|
90
|
+
// Internal Error
|
|
91
|
+
ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token on behalf of user: {0}";
|
|
92
|
+
// ChannelNotSupported Error
|
|
93
|
+
ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
|
|
96
94
|
/**
|
|
97
95
|
* Error class with code and message thrown by the SDK.
|
|
98
96
|
*
|
|
99
97
|
* @beta
|
|
100
98
|
*/
|
|
101
|
-
|
|
102
|
-
tslib.__extends(ErrorWithCode, _super);
|
|
99
|
+
class ErrorWithCode extends Error {
|
|
103
100
|
/**
|
|
104
101
|
* Constructor of ErrorWithCode.
|
|
105
102
|
*
|
|
@@ -108,21 +105,17 @@ var ErrorWithCode = /** @class */ (function (_super) {
|
|
|
108
105
|
*
|
|
109
106
|
* @beta
|
|
110
107
|
*/
|
|
111
|
-
|
|
112
|
-
var _newTarget = this.constructor;
|
|
113
|
-
var _this = this;
|
|
108
|
+
constructor(message, code) {
|
|
114
109
|
if (!code) {
|
|
115
|
-
|
|
116
|
-
return
|
|
110
|
+
super(message);
|
|
111
|
+
return this;
|
|
117
112
|
}
|
|
118
|
-
|
|
119
|
-
Object.setPrototypeOf(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return _this;
|
|
113
|
+
super(message);
|
|
114
|
+
Object.setPrototypeOf(this, ErrorWithCode.prototype);
|
|
115
|
+
this.name = `${new.target.name}.${code}`;
|
|
116
|
+
this.code = code;
|
|
123
117
|
}
|
|
124
|
-
|
|
125
|
-
}(Error));
|
|
118
|
+
}
|
|
126
119
|
|
|
127
120
|
// Copyright (c) Microsoft Corporation.
|
|
128
121
|
// Licensed under the MIT license.
|
|
@@ -190,8 +183,8 @@ function setLogLevel(level) {
|
|
|
190
183
|
function getLogLevel() {
|
|
191
184
|
return internalLogger.level;
|
|
192
185
|
}
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
class InternalLogger {
|
|
187
|
+
constructor(name, logLevel) {
|
|
195
188
|
this.level = undefined;
|
|
196
189
|
this.defaultLogger = {
|
|
197
190
|
verbose: console.debug,
|
|
@@ -202,31 +195,31 @@ var InternalLogger = /** @class */ (function () {
|
|
|
202
195
|
this.name = name;
|
|
203
196
|
this.level = logLevel;
|
|
204
197
|
}
|
|
205
|
-
|
|
206
|
-
this.log(exports.LogLevel.Error,
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.log(exports.LogLevel.Warn,
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.log(exports.LogLevel.Info,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
this.log(exports.LogLevel.Verbose,
|
|
216
|
-
}
|
|
217
|
-
|
|
198
|
+
error(message) {
|
|
199
|
+
this.log(exports.LogLevel.Error, (x) => x.error, message);
|
|
200
|
+
}
|
|
201
|
+
warn(message) {
|
|
202
|
+
this.log(exports.LogLevel.Warn, (x) => x.warn, message);
|
|
203
|
+
}
|
|
204
|
+
info(message) {
|
|
205
|
+
this.log(exports.LogLevel.Info, (x) => x.info, message);
|
|
206
|
+
}
|
|
207
|
+
verbose(message) {
|
|
208
|
+
this.log(exports.LogLevel.Verbose, (x) => x.verbose, message);
|
|
209
|
+
}
|
|
210
|
+
log(logLevel, logFunction, message) {
|
|
218
211
|
if (message.trim() === "") {
|
|
219
212
|
return;
|
|
220
213
|
}
|
|
221
|
-
|
|
222
|
-
|
|
214
|
+
const timestamp = new Date().toUTCString();
|
|
215
|
+
let logHeader;
|
|
223
216
|
if (this.name) {
|
|
224
|
-
logHeader =
|
|
217
|
+
logHeader = `[${timestamp}] : @microsoft/teamsfx - ${this.name} : ${exports.LogLevel[logLevel]} - `;
|
|
225
218
|
}
|
|
226
219
|
else {
|
|
227
|
-
logHeader =
|
|
220
|
+
logHeader = `[${timestamp}] : @microsoft/teamsfx : ${exports.LogLevel[logLevel]} - `;
|
|
228
221
|
}
|
|
229
|
-
|
|
222
|
+
const logMessage = `${logHeader}${message}`;
|
|
230
223
|
if (this.level !== undefined && this.level <= logLevel) {
|
|
231
224
|
if (this.customLogger) {
|
|
232
225
|
logFunction(this.customLogger)(logMessage);
|
|
@@ -238,15 +231,14 @@ var InternalLogger = /** @class */ (function () {
|
|
|
238
231
|
logFunction(this.defaultLogger)(logMessage);
|
|
239
232
|
}
|
|
240
233
|
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
}());
|
|
234
|
+
}
|
|
235
|
+
}
|
|
244
236
|
/**
|
|
245
237
|
* Logger instance used internally
|
|
246
238
|
*
|
|
247
239
|
* @internal
|
|
248
240
|
*/
|
|
249
|
-
|
|
241
|
+
const internalLogger = new InternalLogger();
|
|
250
242
|
/**
|
|
251
243
|
* Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
|
|
252
244
|
*
|
|
@@ -299,14 +291,14 @@ function setLogFunction(logFunction) {
|
|
|
299
291
|
*/
|
|
300
292
|
function parseJwt(token) {
|
|
301
293
|
try {
|
|
302
|
-
|
|
294
|
+
const tokenObj = jwt_decode__default["default"](token);
|
|
303
295
|
if (!tokenObj || !tokenObj.exp) {
|
|
304
296
|
throw new ErrorWithCode("Decoded token is null or exp claim does not exists.", exports.ErrorCode.InternalError);
|
|
305
297
|
}
|
|
306
298
|
return tokenObj;
|
|
307
299
|
}
|
|
308
300
|
catch (err) {
|
|
309
|
-
|
|
301
|
+
const errorMsg = "Parse jwt token failed in node env with error: " + err.message;
|
|
310
302
|
internalLogger.error(errorMsg);
|
|
311
303
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InternalError);
|
|
312
304
|
}
|
|
@@ -316,12 +308,12 @@ function parseJwt(token) {
|
|
|
316
308
|
*/
|
|
317
309
|
function getUserInfoFromSsoToken(ssoToken) {
|
|
318
310
|
if (!ssoToken) {
|
|
319
|
-
|
|
311
|
+
const errorMsg = "SSO token is undefined.";
|
|
320
312
|
internalLogger.error(errorMsg);
|
|
321
313
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
322
314
|
}
|
|
323
|
-
|
|
324
|
-
|
|
315
|
+
const tokenObject = parseJwt(ssoToken);
|
|
316
|
+
const userInfo = {
|
|
325
317
|
displayName: tokenObject.name,
|
|
326
318
|
objectId: tokenObject.oid,
|
|
327
319
|
preferredUserName: "",
|
|
@@ -348,12 +340,8 @@ function getUserInfoFromSsoToken(ssoToken) {
|
|
|
348
340
|
*
|
|
349
341
|
* @internal
|
|
350
342
|
*/
|
|
351
|
-
function formatString(str) {
|
|
352
|
-
|
|
353
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
354
|
-
replacements[_i - 1] = arguments[_i];
|
|
355
|
-
}
|
|
356
|
-
var args = replacements;
|
|
343
|
+
function formatString(str, ...replacements) {
|
|
344
|
+
const args = replacements;
|
|
357
345
|
return str.replace(/{(\d+)}/g, function (match, number) {
|
|
358
346
|
return typeof args[number] != "undefined" ? args[number] : match;
|
|
359
347
|
});
|
|
@@ -371,10 +359,10 @@ function validateScopesType(value) {
|
|
|
371
359
|
return;
|
|
372
360
|
}
|
|
373
361
|
// string array
|
|
374
|
-
if (Array.isArray(value) && value.length > 0 && value.every(
|
|
362
|
+
if (Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string")) {
|
|
375
363
|
return;
|
|
376
364
|
}
|
|
377
|
-
|
|
365
|
+
const errorMsg = "The type of scopes is not valid, it must be string or string array";
|
|
378
366
|
internalLogger.error(errorMsg);
|
|
379
367
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
380
368
|
}
|
|
@@ -382,20 +370,20 @@ function validateScopesType(value) {
|
|
|
382
370
|
* @internal
|
|
383
371
|
*/
|
|
384
372
|
function getScopesArray(scopes) {
|
|
385
|
-
|
|
386
|
-
return scopesArray.filter(
|
|
373
|
+
const scopesArray = typeof scopes === "string" ? scopes.split(" ") : scopes;
|
|
374
|
+
return scopesArray.filter((x) => x !== null && x !== "");
|
|
387
375
|
}
|
|
388
376
|
/**
|
|
389
377
|
* @internal
|
|
390
378
|
*/
|
|
391
379
|
function getAuthority(authorityHost, tenantId) {
|
|
392
|
-
|
|
380
|
+
const normalizedAuthorityHost = authorityHost.replace(/\/+$/g, "");
|
|
393
381
|
return normalizedAuthorityHost + "/" + tenantId;
|
|
394
382
|
}
|
|
395
383
|
/**
|
|
396
384
|
* @internal
|
|
397
385
|
*/
|
|
398
|
-
|
|
386
|
+
const isNode = typeof process !== "undefined" &&
|
|
399
387
|
!!process.version &&
|
|
400
388
|
!!process.versions &&
|
|
401
389
|
!!process.versions.node;
|
|
@@ -405,7 +393,7 @@ var isNode = typeof process !== "undefined" &&
|
|
|
405
393
|
* Global configuration instance
|
|
406
394
|
*
|
|
407
395
|
*/
|
|
408
|
-
|
|
396
|
+
let config;
|
|
409
397
|
/**
|
|
410
398
|
* Initialize configuration from environment variables or configuration object and set the global instance
|
|
411
399
|
*
|
|
@@ -420,7 +408,7 @@ function loadConfiguration(configuration) {
|
|
|
420
408
|
// browser environment
|
|
421
409
|
if (!isNode) {
|
|
422
410
|
if (!configuration) {
|
|
423
|
-
|
|
411
|
+
const errorMsg = "You are running the code in browser. Configuration must be passed in.";
|
|
424
412
|
internalLogger.error(errorMsg);
|
|
425
413
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
426
414
|
}
|
|
@@ -428,9 +416,9 @@ function loadConfiguration(configuration) {
|
|
|
428
416
|
return;
|
|
429
417
|
}
|
|
430
418
|
// node environment
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
419
|
+
let newAuthentication;
|
|
420
|
+
let newResources = [];
|
|
421
|
+
const defaultResourceName = "default";
|
|
434
422
|
if (configuration === null || configuration === void 0 ? void 0 : configuration.authentication) {
|
|
435
423
|
newAuthentication = configuration.authentication;
|
|
436
424
|
}
|
|
@@ -488,15 +476,14 @@ function loadConfiguration(configuration) {
|
|
|
488
476
|
*
|
|
489
477
|
* @beta
|
|
490
478
|
*/
|
|
491
|
-
function getResourceConfiguration(resourceType, resourceName) {
|
|
479
|
+
function getResourceConfiguration(resourceType, resourceName = "default") {
|
|
492
480
|
var _a;
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
var result = (_a = config.resources) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.type === resourceType && item.name === resourceName; });
|
|
481
|
+
internalLogger.info(`Get resource configuration of ${exports.ResourceType[resourceType]} from ${resourceName}`);
|
|
482
|
+
const result = (_a = config.resources) === null || _a === void 0 ? void 0 : _a.find((item) => item.type === resourceType && item.name === resourceName);
|
|
496
483
|
if (result) {
|
|
497
484
|
return result.properties;
|
|
498
485
|
}
|
|
499
|
-
|
|
486
|
+
const errorMsg = formatString(ErrorMessage.MissingResourceConfiguration, exports.ResourceType[resourceType], resourceName);
|
|
500
487
|
internalLogger.error(errorMsg);
|
|
501
488
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidConfiguration);
|
|
502
489
|
}
|
|
@@ -514,7 +501,7 @@ function getAuthenticationConfiguration() {
|
|
|
514
501
|
if (config) {
|
|
515
502
|
return config.authentication;
|
|
516
503
|
}
|
|
517
|
-
|
|
504
|
+
const errorMsg = "Please call loadConfiguration() first before calling getAuthenticationConfiguration().";
|
|
518
505
|
internalLogger.error(errorMsg);
|
|
519
506
|
throw new ErrorWithCode(formatString(ErrorMessage.ConfigurationNotExists, errorMsg), exports.ErrorCode.InvalidConfiguration);
|
|
520
507
|
}
|
|
@@ -523,9 +510,9 @@ function getAuthenticationConfiguration() {
|
|
|
523
510
|
* @internal
|
|
524
511
|
*/
|
|
525
512
|
function createConfidentialClientApplication(authentication) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
513
|
+
const authority = getAuthority(authentication.authorityHost, authentication.tenantId);
|
|
514
|
+
const clientCertificate = parseCertificate(authentication.certificateContent);
|
|
515
|
+
const auth = {
|
|
529
516
|
clientId: authentication.clientId,
|
|
530
517
|
authority: authority,
|
|
531
518
|
};
|
|
@@ -536,7 +523,7 @@ function createConfidentialClientApplication(authentication) {
|
|
|
536
523
|
auth.clientSecret = authentication.clientSecret;
|
|
537
524
|
}
|
|
538
525
|
return new msalNode.ConfidentialClientApplication({
|
|
539
|
-
auth
|
|
526
|
+
auth,
|
|
540
527
|
});
|
|
541
528
|
}
|
|
542
529
|
/**
|
|
@@ -546,14 +533,14 @@ function parseCertificate(certificateContent) {
|
|
|
546
533
|
if (!certificateContent) {
|
|
547
534
|
return undefined;
|
|
548
535
|
}
|
|
549
|
-
|
|
550
|
-
|
|
536
|
+
const certificatePattern = /(-+BEGIN CERTIFICATE-+)(\n\r?|\r\n?)([A-Za-z0-9+/\n\r]+=*)(\n\r?|\r\n?)(-+END CERTIFICATE-+)/;
|
|
537
|
+
const match = certificatePattern.exec(certificateContent);
|
|
551
538
|
if (!match) {
|
|
552
|
-
|
|
539
|
+
const errorMsg = "The certificate content does not contain a PEM-encoded certificate.";
|
|
553
540
|
internalLogger.error(errorMsg);
|
|
554
541
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidCertificate);
|
|
555
542
|
}
|
|
556
|
-
|
|
543
|
+
const thumbprint = crypto.createHash("sha1")
|
|
557
544
|
.update(Buffer.from(match[3], "base64"))
|
|
558
545
|
.digest("hex")
|
|
559
546
|
.toUpperCase();
|
|
@@ -578,7 +565,7 @@ function parseCertificate(certificateContent) {
|
|
|
578
565
|
*
|
|
579
566
|
* @beta
|
|
580
567
|
*/
|
|
581
|
-
|
|
568
|
+
class M365TenantCredential {
|
|
582
569
|
/**
|
|
583
570
|
* Constructor of M365TenantCredential.
|
|
584
571
|
*
|
|
@@ -590,9 +577,9 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
590
577
|
*
|
|
591
578
|
* @beta
|
|
592
579
|
*/
|
|
593
|
-
|
|
580
|
+
constructor() {
|
|
594
581
|
internalLogger.info("Create M365 tenant credential");
|
|
595
|
-
|
|
582
|
+
const config = this.loadAndValidateConfig();
|
|
596
583
|
this.msalClient = createConfidentialClientApplication(config);
|
|
597
584
|
}
|
|
598
585
|
/**
|
|
@@ -621,54 +608,44 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
621
608
|
*
|
|
622
609
|
* @beta
|
|
623
610
|
*/
|
|
624
|
-
|
|
625
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
case 2:
|
|
641
|
-
authenticationResult = _a.sent();
|
|
642
|
-
if (authenticationResult) {
|
|
643
|
-
accessToken = {
|
|
644
|
-
token: authenticationResult.accessToken,
|
|
645
|
-
expiresOnTimestamp: authenticationResult.expiresOn.getTime(),
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
return [3 /*break*/, 4];
|
|
649
|
-
case 3:
|
|
650
|
-
err_1 = _a.sent();
|
|
651
|
-
errorMsg = "Get M365 tenant credential failed with error: " + err_1.message;
|
|
652
|
-
internalLogger.error(errorMsg);
|
|
653
|
-
throw new ErrorWithCode(errorMsg, exports.ErrorCode.ServiceError);
|
|
654
|
-
case 4:
|
|
655
|
-
if (!accessToken) {
|
|
656
|
-
errorMsg = "Get M365 tenant credential access token failed with empty access token";
|
|
657
|
-
internalLogger.error(errorMsg);
|
|
658
|
-
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InternalError);
|
|
659
|
-
}
|
|
660
|
-
return [2 /*return*/, accessToken];
|
|
611
|
+
getToken(scopes, options) {
|
|
612
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
613
|
+
let accessToken;
|
|
614
|
+
validateScopesType(scopes);
|
|
615
|
+
const scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
|
|
616
|
+
internalLogger.info("Get access token with scopes: " + scopesStr);
|
|
617
|
+
try {
|
|
618
|
+
const scopesArray = getScopesArray(scopes);
|
|
619
|
+
const authenticationResult = yield this.msalClient.acquireTokenByClientCredential({
|
|
620
|
+
scopes: scopesArray,
|
|
621
|
+
});
|
|
622
|
+
if (authenticationResult) {
|
|
623
|
+
accessToken = {
|
|
624
|
+
token: authenticationResult.accessToken,
|
|
625
|
+
expiresOnTimestamp: authenticationResult.expiresOn.getTime(),
|
|
626
|
+
};
|
|
661
627
|
}
|
|
662
|
-
}
|
|
628
|
+
}
|
|
629
|
+
catch (err) {
|
|
630
|
+
const errorMsg = "Get M365 tenant credential failed with error: " + err.message;
|
|
631
|
+
internalLogger.error(errorMsg);
|
|
632
|
+
throw new ErrorWithCode(errorMsg, exports.ErrorCode.ServiceError);
|
|
633
|
+
}
|
|
634
|
+
if (!accessToken) {
|
|
635
|
+
const errorMsg = "Get M365 tenant credential access token failed with empty access token";
|
|
636
|
+
internalLogger.error(errorMsg);
|
|
637
|
+
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InternalError);
|
|
638
|
+
}
|
|
639
|
+
return accessToken;
|
|
663
640
|
});
|
|
664
|
-
}
|
|
641
|
+
}
|
|
665
642
|
/**
|
|
666
643
|
* Load and validate authentication configuration
|
|
667
644
|
* @returns Authentication configuration
|
|
668
645
|
*/
|
|
669
|
-
|
|
646
|
+
loadAndValidateConfig() {
|
|
670
647
|
internalLogger.verbose("Validate authentication configuration");
|
|
671
|
-
|
|
648
|
+
const config = getAuthenticationConfiguration();
|
|
672
649
|
if (!config) {
|
|
673
650
|
internalLogger.error(ErrorMessage.AuthenticationConfigurationNotExists);
|
|
674
651
|
throw new ErrorWithCode(ErrorMessage.AuthenticationConfigurationNotExists, exports.ErrorCode.InvalidConfiguration);
|
|
@@ -676,7 +653,7 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
676
653
|
if (config.clientId && (config.clientSecret || config.certificateContent) && config.tenantId) {
|
|
677
654
|
return config;
|
|
678
655
|
}
|
|
679
|
-
|
|
656
|
+
const missingValues = [];
|
|
680
657
|
if (!config.clientId) {
|
|
681
658
|
missingValues.push("clientId");
|
|
682
659
|
}
|
|
@@ -686,12 +663,11 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
686
663
|
if (!config.tenantId) {
|
|
687
664
|
missingValues.push("tenantId");
|
|
688
665
|
}
|
|
689
|
-
|
|
666
|
+
const errorMsg = formatString(ErrorMessage.InvalidConfiguration, missingValues.join(", "), "undefined");
|
|
690
667
|
internalLogger.error(errorMsg);
|
|
691
668
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidConfiguration);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
}());
|
|
669
|
+
}
|
|
670
|
+
}
|
|
695
671
|
|
|
696
672
|
// Copyright (c) Microsoft Corporation.
|
|
697
673
|
/**
|
|
@@ -708,7 +684,7 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
708
684
|
*
|
|
709
685
|
* @beta
|
|
710
686
|
*/
|
|
711
|
-
|
|
687
|
+
class OnBehalfOfUserCredential {
|
|
712
688
|
/**
|
|
713
689
|
* Constructor of OnBehalfOfUserCredential
|
|
714
690
|
*
|
|
@@ -723,10 +699,10 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
723
699
|
*
|
|
724
700
|
* @beta
|
|
725
701
|
*/
|
|
726
|
-
|
|
702
|
+
constructor(ssoToken) {
|
|
727
703
|
var _a, _b, _c, _d, _e;
|
|
728
704
|
internalLogger.info("Get on behalf of user credential");
|
|
729
|
-
|
|
705
|
+
const missingConfigurations = [];
|
|
730
706
|
if (!((_a = config === null || config === void 0 ? void 0 : config.authentication) === null || _a === void 0 ? void 0 : _a.clientId)) {
|
|
731
707
|
missingConfigurations.push("clientId");
|
|
732
708
|
}
|
|
@@ -740,12 +716,12 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
740
716
|
missingConfigurations.push("tenantId");
|
|
741
717
|
}
|
|
742
718
|
if (missingConfigurations.length != 0) {
|
|
743
|
-
|
|
719
|
+
const errorMsg = formatString(ErrorMessage.InvalidConfiguration, missingConfigurations.join(", "), "undefined");
|
|
744
720
|
internalLogger.error(errorMsg);
|
|
745
721
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidConfiguration);
|
|
746
722
|
}
|
|
747
723
|
this.msalClient = createConfidentialClientApplication(config.authentication);
|
|
748
|
-
|
|
724
|
+
const decodedSsoToken = parseJwt(ssoToken);
|
|
749
725
|
this.ssoToken = {
|
|
750
726
|
token: ssoToken,
|
|
751
727
|
expiresOnTimestamp: decodedSsoToken.exp,
|
|
@@ -786,55 +762,45 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
786
762
|
*
|
|
787
763
|
* @beta
|
|
788
764
|
*/
|
|
789
|
-
|
|
790
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
errorMsg = "Sso token has already expired.";
|
|
801
|
-
internalLogger.error(errorMsg);
|
|
802
|
-
throw new ErrorWithCode(errorMsg, exports.ErrorCode.TokenExpiredError);
|
|
803
|
-
}
|
|
804
|
-
result = this.ssoToken;
|
|
805
|
-
return [3 /*break*/, 6];
|
|
806
|
-
case 1:
|
|
807
|
-
internalLogger.info("Get access token with scopes: " + scopesArray.join(" "));
|
|
808
|
-
authenticationResult = void 0;
|
|
809
|
-
_a.label = 2;
|
|
810
|
-
case 2:
|
|
811
|
-
_a.trys.push([2, 4, , 5]);
|
|
812
|
-
return [4 /*yield*/, this.msalClient.acquireTokenOnBehalfOf({
|
|
813
|
-
oboAssertion: this.ssoToken.token,
|
|
814
|
-
scopes: scopesArray,
|
|
815
|
-
})];
|
|
816
|
-
case 3:
|
|
817
|
-
authenticationResult = _a.sent();
|
|
818
|
-
return [3 /*break*/, 5];
|
|
819
|
-
case 4:
|
|
820
|
-
error_1 = _a.sent();
|
|
821
|
-
throw this.generateAuthServerError(error_1);
|
|
822
|
-
case 5:
|
|
823
|
-
if (!authenticationResult) {
|
|
824
|
-
errorMsg = "Access token is null";
|
|
825
|
-
internalLogger.error(errorMsg);
|
|
826
|
-
throw new ErrorWithCode(formatString(ErrorMessage.FailToAcquireTokenOnBehalfOfUser, errorMsg), exports.ErrorCode.InternalError);
|
|
827
|
-
}
|
|
828
|
-
result = {
|
|
829
|
-
token: authenticationResult.accessToken,
|
|
830
|
-
expiresOnTimestamp: authenticationResult.expiresOn.getTime(),
|
|
831
|
-
};
|
|
832
|
-
_a.label = 6;
|
|
833
|
-
case 6: return [2 /*return*/, result];
|
|
765
|
+
getToken(scopes, options) {
|
|
766
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
767
|
+
validateScopesType(scopes);
|
|
768
|
+
const scopesArray = getScopesArray(scopes);
|
|
769
|
+
let result;
|
|
770
|
+
if (!scopesArray.length) {
|
|
771
|
+
internalLogger.info("Get SSO token.");
|
|
772
|
+
if (Math.floor(Date.now() / 1000) > this.ssoToken.expiresOnTimestamp) {
|
|
773
|
+
const errorMsg = "Sso token has already expired.";
|
|
774
|
+
internalLogger.error(errorMsg);
|
|
775
|
+
throw new ErrorWithCode(errorMsg, exports.ErrorCode.TokenExpiredError);
|
|
834
776
|
}
|
|
835
|
-
|
|
777
|
+
result = this.ssoToken;
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
internalLogger.info("Get access token with scopes: " + scopesArray.join(" "));
|
|
781
|
+
let authenticationResult;
|
|
782
|
+
try {
|
|
783
|
+
authenticationResult = yield this.msalClient.acquireTokenOnBehalfOf({
|
|
784
|
+
oboAssertion: this.ssoToken.token,
|
|
785
|
+
scopes: scopesArray,
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
catch (error) {
|
|
789
|
+
throw this.generateAuthServerError(error);
|
|
790
|
+
}
|
|
791
|
+
if (!authenticationResult) {
|
|
792
|
+
const errorMsg = "Access token is null";
|
|
793
|
+
internalLogger.error(errorMsg);
|
|
794
|
+
throw new ErrorWithCode(formatString(ErrorMessage.FailToAcquireTokenOnBehalfOfUser, errorMsg), exports.ErrorCode.InternalError);
|
|
795
|
+
}
|
|
796
|
+
result = {
|
|
797
|
+
token: authenticationResult.accessToken,
|
|
798
|
+
expiresOnTimestamp: authenticationResult.expiresOn.getTime(),
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
return result;
|
|
836
802
|
});
|
|
837
|
-
}
|
|
803
|
+
}
|
|
838
804
|
/**
|
|
839
805
|
* Get basic user info from SSO token.
|
|
840
806
|
*
|
|
@@ -850,30 +816,29 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
850
816
|
*
|
|
851
817
|
* @beta
|
|
852
818
|
*/
|
|
853
|
-
|
|
819
|
+
getUserInfo() {
|
|
854
820
|
internalLogger.info("Get basic user info from SSO token");
|
|
855
821
|
return getUserInfoFromSsoToken(this.ssoToken.token);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
|
|
822
|
+
}
|
|
823
|
+
generateAuthServerError(err) {
|
|
824
|
+
const errorMessage = err.errorMessage;
|
|
859
825
|
if (err.name === "InteractionRequiredAuthError") {
|
|
860
|
-
|
|
826
|
+
const fullErrorMsg = "Failed to get access token from AAD server, interaction required: " + errorMessage;
|
|
861
827
|
internalLogger.warn(fullErrorMsg);
|
|
862
828
|
return new ErrorWithCode(fullErrorMsg, exports.ErrorCode.UiRequiredError);
|
|
863
829
|
}
|
|
864
830
|
else if (errorMessage && errorMessage.indexOf("AADSTS500133") >= 0) {
|
|
865
|
-
|
|
831
|
+
const fullErrorMsg = "Failed to get access token from AAD server, sso token expired: " + errorMessage;
|
|
866
832
|
internalLogger.error(fullErrorMsg);
|
|
867
833
|
return new ErrorWithCode(fullErrorMsg, exports.ErrorCode.TokenExpiredError);
|
|
868
834
|
}
|
|
869
835
|
else {
|
|
870
|
-
|
|
836
|
+
const fullErrorMsg = formatString(ErrorMessage.FailToAcquireTokenOnBehalfOfUser, errorMessage);
|
|
871
837
|
internalLogger.error(fullErrorMsg);
|
|
872
838
|
return new ErrorWithCode(fullErrorMsg, exports.ErrorCode.ServiceError);
|
|
873
839
|
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
}());
|
|
840
|
+
}
|
|
841
|
+
}
|
|
877
842
|
|
|
878
843
|
// Copyright (c) Microsoft Corporation.
|
|
879
844
|
/**
|
|
@@ -884,14 +849,14 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
884
849
|
*
|
|
885
850
|
* @beta
|
|
886
851
|
*/
|
|
887
|
-
|
|
852
|
+
class TeamsUserCredential {
|
|
888
853
|
/**
|
|
889
854
|
* Constructor of TeamsUserCredential.
|
|
890
855
|
* @remarks
|
|
891
856
|
* Can only be used within Teams.
|
|
892
857
|
* @beta
|
|
893
858
|
*/
|
|
894
|
-
|
|
859
|
+
constructor() {
|
|
895
860
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
896
861
|
}
|
|
897
862
|
/**
|
|
@@ -900,46 +865,41 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
900
865
|
* Can only be used within Teams.
|
|
901
866
|
* @beta
|
|
902
867
|
*/
|
|
903
|
-
|
|
904
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
905
|
-
|
|
906
|
-
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
907
|
-
});
|
|
868
|
+
login(scopes) {
|
|
869
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
870
|
+
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
908
871
|
});
|
|
909
|
-
}
|
|
872
|
+
}
|
|
910
873
|
/**
|
|
911
874
|
* Get access token from credential.
|
|
912
875
|
* @remarks
|
|
913
876
|
* Can only be used within Teams.
|
|
914
877
|
* @beta
|
|
915
878
|
*/
|
|
916
|
-
|
|
917
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
918
|
-
|
|
919
|
-
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
920
|
-
});
|
|
879
|
+
getToken(scopes, options) {
|
|
880
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
881
|
+
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
921
882
|
});
|
|
922
|
-
}
|
|
883
|
+
}
|
|
923
884
|
/**
|
|
924
885
|
* Get basic user info from SSO token
|
|
925
886
|
* @remarks
|
|
926
887
|
* Can only be used within Teams.
|
|
927
888
|
* @beta
|
|
928
889
|
*/
|
|
929
|
-
|
|
890
|
+
getUserInfo() {
|
|
930
891
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
}());
|
|
892
|
+
}
|
|
893
|
+
}
|
|
934
894
|
|
|
935
895
|
// Copyright (c) Microsoft Corporation.
|
|
936
|
-
|
|
896
|
+
const defaultScope = "https://graph.microsoft.com/.default";
|
|
937
897
|
/**
|
|
938
898
|
* Microsoft Graph auth provider for Teams Framework
|
|
939
899
|
*
|
|
940
900
|
* @beta
|
|
941
901
|
*/
|
|
942
|
-
|
|
902
|
+
class MsGraphAuthProvider {
|
|
943
903
|
/**
|
|
944
904
|
* Constructor of MsGraphAuthProvider.
|
|
945
905
|
*
|
|
@@ -952,9 +912,9 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
952
912
|
*
|
|
953
913
|
* @beta
|
|
954
914
|
*/
|
|
955
|
-
|
|
915
|
+
constructor(credential, scopes) {
|
|
956
916
|
this.credential = credential;
|
|
957
|
-
|
|
917
|
+
let scopesStr = defaultScope;
|
|
958
918
|
if (scopes) {
|
|
959
919
|
validateScopesType(scopes);
|
|
960
920
|
scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
|
|
@@ -962,7 +922,7 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
962
922
|
scopesStr = defaultScope;
|
|
963
923
|
}
|
|
964
924
|
}
|
|
965
|
-
internalLogger.info(
|
|
925
|
+
internalLogger.info(`Create Microsoft Graph Authentication Provider with scopes: '${scopesStr}'`);
|
|
966
926
|
this.scopes = scopesStr;
|
|
967
927
|
}
|
|
968
928
|
/**
|
|
@@ -977,32 +937,23 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
977
937
|
* @returns Access token from the credential.
|
|
978
938
|
*
|
|
979
939
|
*/
|
|
980
|
-
|
|
981
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
resolve(accessToken.token);
|
|
993
|
-
}
|
|
994
|
-
else {
|
|
995
|
-
var errorMsg = "Graph access token is undefined or empty";
|
|
996
|
-
internalLogger.error(errorMsg);
|
|
997
|
-
reject(new ErrorWithCode(errorMsg, exports.ErrorCode.InternalError));
|
|
998
|
-
}
|
|
999
|
-
})];
|
|
940
|
+
getAccessToken() {
|
|
941
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
942
|
+
internalLogger.info(`Get Graph Access token with scopes: '${this.scopes}'`);
|
|
943
|
+
const accessToken = yield this.credential.getToken(this.scopes);
|
|
944
|
+
return new Promise((resolve, reject) => {
|
|
945
|
+
if (accessToken) {
|
|
946
|
+
resolve(accessToken.token);
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
const errorMsg = "Graph access token is undefined or empty";
|
|
950
|
+
internalLogger.error(errorMsg);
|
|
951
|
+
reject(new ErrorWithCode(errorMsg, exports.ErrorCode.InternalError));
|
|
1000
952
|
}
|
|
1001
953
|
});
|
|
1002
954
|
});
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
}());
|
|
955
|
+
}
|
|
956
|
+
}
|
|
1006
957
|
|
|
1007
958
|
// Copyright (c) Microsoft Corporation.
|
|
1008
959
|
/**
|
|
@@ -1058,9 +1009,9 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
1058
1009
|
*/
|
|
1059
1010
|
function createMicrosoftGraphClient(credential, scopes) {
|
|
1060
1011
|
internalLogger.info("Create Microsoft Graph Client");
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
authProvider
|
|
1012
|
+
const authProvider = new MsGraphAuthProvider(credential, scopes);
|
|
1013
|
+
const graphClient = microsoftGraphClient.Client.initWithMiddleware({
|
|
1014
|
+
authProvider,
|
|
1064
1015
|
});
|
|
1065
1016
|
return graphClient;
|
|
1066
1017
|
}
|
|
@@ -1074,8 +1025,8 @@ function createMicrosoftGraphClient(credential, scopes) {
|
|
|
1074
1025
|
* @beta
|
|
1075
1026
|
*
|
|
1076
1027
|
*/
|
|
1077
|
-
|
|
1078
|
-
|
|
1028
|
+
class DefaultTediousConnectionConfiguration {
|
|
1029
|
+
constructor() {
|
|
1079
1030
|
/**
|
|
1080
1031
|
* MSSQL default scope
|
|
1081
1032
|
* https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi
|
|
@@ -1095,62 +1046,52 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1095
1046
|
*
|
|
1096
1047
|
* @beta
|
|
1097
1048
|
*/
|
|
1098
|
-
|
|
1099
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
case 2:
|
|
1127
|
-
configWithToken = _a.sent();
|
|
1128
|
-
internalLogger.verbose("SQL configuration with MSI token generated");
|
|
1129
|
-
return [2 /*return*/, configWithToken];
|
|
1130
|
-
case 3:
|
|
1131
|
-
error_1 = _a.sent();
|
|
1132
|
-
throw error_1;
|
|
1133
|
-
case 4: return [2 /*return*/];
|
|
1134
|
-
}
|
|
1135
|
-
});
|
|
1049
|
+
getConfig(databaseName) {
|
|
1050
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1051
|
+
internalLogger.info("Get SQL configuration");
|
|
1052
|
+
const configuration = getResourceConfiguration(exports.ResourceType.SQL);
|
|
1053
|
+
if (!configuration) {
|
|
1054
|
+
const errMsg = "SQL resource configuration not exist";
|
|
1055
|
+
internalLogger.error(errMsg);
|
|
1056
|
+
throw new ErrorWithCode(errMsg, exports.ErrorCode.InvalidConfiguration);
|
|
1057
|
+
}
|
|
1058
|
+
try {
|
|
1059
|
+
this.isSQLConfigurationValid(configuration);
|
|
1060
|
+
}
|
|
1061
|
+
catch (err) {
|
|
1062
|
+
throw err;
|
|
1063
|
+
}
|
|
1064
|
+
if (!this.isMsiAuthentication()) {
|
|
1065
|
+
const configWithUPS = this.generateDefaultConfig(configuration, databaseName);
|
|
1066
|
+
internalLogger.verbose("SQL configuration with username and password generated");
|
|
1067
|
+
return configWithUPS;
|
|
1068
|
+
}
|
|
1069
|
+
try {
|
|
1070
|
+
const configWithToken = yield this.generateTokenConfig(configuration, databaseName);
|
|
1071
|
+
internalLogger.verbose("SQL configuration with MSI token generated");
|
|
1072
|
+
return configWithToken;
|
|
1073
|
+
}
|
|
1074
|
+
catch (error) {
|
|
1075
|
+
throw error;
|
|
1076
|
+
}
|
|
1136
1077
|
});
|
|
1137
|
-
}
|
|
1078
|
+
}
|
|
1138
1079
|
/**
|
|
1139
1080
|
* Check SQL use MSI identity or username and password.
|
|
1140
1081
|
*
|
|
1141
1082
|
* @returns false - login with SQL MSI identity, true - login with username and password.
|
|
1142
1083
|
* @internal
|
|
1143
1084
|
*/
|
|
1144
|
-
|
|
1085
|
+
isMsiAuthentication() {
|
|
1145
1086
|
internalLogger.verbose("Check connection config using MSI access token or username and password");
|
|
1146
|
-
|
|
1087
|
+
const configuration = getResourceConfiguration(exports.ResourceType.SQL);
|
|
1147
1088
|
if ((configuration === null || configuration === void 0 ? void 0 : configuration.sqlUsername) != null && (configuration === null || configuration === void 0 ? void 0 : configuration.sqlPassword) != null) {
|
|
1148
1089
|
internalLogger.verbose("Login with username and password");
|
|
1149
1090
|
return false;
|
|
1150
1091
|
}
|
|
1151
1092
|
internalLogger.verbose("Login with MSI identity");
|
|
1152
1093
|
return true;
|
|
1153
|
-
}
|
|
1094
|
+
}
|
|
1154
1095
|
/**
|
|
1155
1096
|
* check configuration is an available configurations.
|
|
1156
1097
|
* @param { SqlConfiguration } sqlConfig
|
|
@@ -1159,19 +1100,19 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1159
1100
|
* false - configuration is not valid.
|
|
1160
1101
|
* @internal
|
|
1161
1102
|
*/
|
|
1162
|
-
|
|
1103
|
+
isSQLConfigurationValid(sqlConfig) {
|
|
1163
1104
|
internalLogger.verbose("Check SQL configuration if valid");
|
|
1164
1105
|
if (!sqlConfig.sqlServerEndpoint) {
|
|
1165
1106
|
internalLogger.error("SQL configuration is not valid without SQL server endpoint exist");
|
|
1166
1107
|
throw new ErrorWithCode("SQL configuration error without SQL server endpoint exist", exports.ErrorCode.InvalidConfiguration);
|
|
1167
1108
|
}
|
|
1168
1109
|
if (!(sqlConfig.sqlUsername && sqlConfig.sqlPassword) && !sqlConfig.sqlIdentityId) {
|
|
1169
|
-
|
|
1110
|
+
const errMsg = `SQL configuration is not valid without ${sqlConfig.sqlIdentityId ? "" : "identity id "} ${sqlConfig.sqlUsername ? "" : "SQL username "} ${sqlConfig.sqlPassword ? "" : "SQL password"} exist`;
|
|
1170
1111
|
internalLogger.error(errMsg);
|
|
1171
1112
|
throw new ErrorWithCode(errMsg, exports.ErrorCode.InvalidConfiguration);
|
|
1172
1113
|
}
|
|
1173
1114
|
internalLogger.verbose("SQL configuration is valid");
|
|
1174
|
-
}
|
|
1115
|
+
}
|
|
1175
1116
|
/**
|
|
1176
1117
|
* Generate tedious connection configuration with default authentication type.
|
|
1177
1118
|
*
|
|
@@ -1180,13 +1121,13 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1180
1121
|
* @returns Tedious connection configuration with username and password.
|
|
1181
1122
|
* @internal
|
|
1182
1123
|
*/
|
|
1183
|
-
|
|
1124
|
+
generateDefaultConfig(sqlConfig, databaseName) {
|
|
1184
1125
|
if (databaseName === "") {
|
|
1185
|
-
internalLogger.warn(
|
|
1126
|
+
internalLogger.warn(`SQL database name is empty string`);
|
|
1186
1127
|
}
|
|
1187
|
-
|
|
1188
|
-
internalLogger.verbose(
|
|
1189
|
-
|
|
1128
|
+
const dbName = databaseName !== null && databaseName !== void 0 ? databaseName : sqlConfig.sqlDatabaseName;
|
|
1129
|
+
internalLogger.verbose(`SQL server ${sqlConfig.sqlServerEndpoint}, user name ${sqlConfig.sqlUsername}, database name ${dbName}`);
|
|
1130
|
+
const config = {
|
|
1190
1131
|
server: sqlConfig.sqlServerEndpoint,
|
|
1191
1132
|
authentication: {
|
|
1192
1133
|
type: TediousAuthenticationType.default,
|
|
@@ -1201,7 +1142,7 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1201
1142
|
},
|
|
1202
1143
|
};
|
|
1203
1144
|
return config;
|
|
1204
|
-
}
|
|
1145
|
+
}
|
|
1205
1146
|
/**
|
|
1206
1147
|
* Generate tedious connection configuration with azure-active-directory-access-token authentication type.
|
|
1207
1148
|
*
|
|
@@ -1210,55 +1151,44 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1210
1151
|
* @returns Tedious connection configuration with access token.
|
|
1211
1152
|
* @internal
|
|
1212
1153
|
*/
|
|
1213
|
-
|
|
1214
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
encrypt: true,
|
|
1249
|
-
},
|
|
1250
|
-
};
|
|
1251
|
-
internalLogger.verbose("Generate token configuration success, server endpoint is " + sqlConfig.sqlServerEndpoint + ", database name is " + (databaseName !== null && databaseName !== void 0 ? databaseName : sqlConfig.sqlDatabaseName));
|
|
1252
|
-
return [2 /*return*/, config];
|
|
1253
|
-
}
|
|
1254
|
-
internalLogger.error("Generate token configuration, server endpoint is " + sqlConfig.sqlServerEndpoint + ", MSI token is not valid");
|
|
1255
|
-
throw new ErrorWithCode("MSI token is not valid", exports.ErrorCode.InternalError);
|
|
1256
|
-
}
|
|
1257
|
-
});
|
|
1154
|
+
generateTokenConfig(sqlConfig, databaseName) {
|
|
1155
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1156
|
+
internalLogger.verbose("Generate tedious config with MSI token");
|
|
1157
|
+
if (databaseName === "") {
|
|
1158
|
+
internalLogger.warn(`SQL database name is empty string`);
|
|
1159
|
+
}
|
|
1160
|
+
let token;
|
|
1161
|
+
try {
|
|
1162
|
+
const credential = new identity.ManagedIdentityCredential(sqlConfig.sqlIdentityId);
|
|
1163
|
+
token = yield credential.getToken(this.defaultSQLScope);
|
|
1164
|
+
}
|
|
1165
|
+
catch (error) {
|
|
1166
|
+
const errMsg = "Get user MSI token failed";
|
|
1167
|
+
internalLogger.error(errMsg);
|
|
1168
|
+
throw new ErrorWithCode(errMsg, exports.ErrorCode.InternalError);
|
|
1169
|
+
}
|
|
1170
|
+
if (token) {
|
|
1171
|
+
const config = {
|
|
1172
|
+
server: sqlConfig.sqlServerEndpoint,
|
|
1173
|
+
authentication: {
|
|
1174
|
+
type: TediousAuthenticationType.MSI,
|
|
1175
|
+
options: {
|
|
1176
|
+
token: token.token,
|
|
1177
|
+
},
|
|
1178
|
+
},
|
|
1179
|
+
options: {
|
|
1180
|
+
database: databaseName !== null && databaseName !== void 0 ? databaseName : sqlConfig.sqlDatabaseName,
|
|
1181
|
+
encrypt: true,
|
|
1182
|
+
},
|
|
1183
|
+
};
|
|
1184
|
+
internalLogger.verbose(`Generate token configuration success, server endpoint is ${sqlConfig.sqlServerEndpoint}, database name is ${databaseName !== null && databaseName !== void 0 ? databaseName : sqlConfig.sqlDatabaseName}`);
|
|
1185
|
+
return config;
|
|
1186
|
+
}
|
|
1187
|
+
internalLogger.error(`Generate token configuration, server endpoint is ${sqlConfig.sqlServerEndpoint}, MSI token is not valid`);
|
|
1188
|
+
throw new ErrorWithCode("MSI token is not valid", exports.ErrorCode.InternalError);
|
|
1258
1189
|
});
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
}());
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1262
1192
|
/**
|
|
1263
1193
|
* tedious connection config authentication type.
|
|
1264
1194
|
* https://tediousjs.github.io/tedious/api-connection.html
|
|
@@ -1271,19 +1201,18 @@ var TediousAuthenticationType;
|
|
|
1271
1201
|
})(TediousAuthenticationType || (TediousAuthenticationType = {}));
|
|
1272
1202
|
|
|
1273
1203
|
// Copyright (c) Microsoft Corporation.
|
|
1274
|
-
|
|
1204
|
+
const invokeResponseType = "invokeResponse";
|
|
1275
1205
|
/**
|
|
1276
1206
|
* Response body returned for a token exchange invoke activity.
|
|
1277
1207
|
*
|
|
1278
1208
|
* @beta
|
|
1279
1209
|
*/
|
|
1280
|
-
|
|
1281
|
-
|
|
1210
|
+
class TokenExchangeInvokeResponse {
|
|
1211
|
+
constructor(id, failureDetail) {
|
|
1282
1212
|
this.id = id;
|
|
1283
1213
|
this.failureDetail = failureDetail;
|
|
1284
1214
|
}
|
|
1285
|
-
|
|
1286
|
-
}());
|
|
1215
|
+
}
|
|
1287
1216
|
/**
|
|
1288
1217
|
* Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
|
|
1289
1218
|
* help receive oauth token, asks the user to consent if needed.
|
|
@@ -1335,8 +1264,7 @@ var TokenExchangeInvokeResponse = /** @class */ (function () {
|
|
|
1335
1264
|
*
|
|
1336
1265
|
* @beta
|
|
1337
1266
|
*/
|
|
1338
|
-
|
|
1339
|
-
tslib.__extends(TeamsBotSsoPrompt, _super);
|
|
1267
|
+
class TeamsBotSsoPrompt extends botbuilderDialogs.Dialog {
|
|
1340
1268
|
/**
|
|
1341
1269
|
* Constructor of TeamsBotSsoPrompt.
|
|
1342
1270
|
*
|
|
@@ -1348,12 +1276,11 @@ var TeamsBotSsoPrompt = /** @class */ (function (_super) {
|
|
|
1348
1276
|
*
|
|
1349
1277
|
* @beta
|
|
1350
1278
|
*/
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1279
|
+
constructor(dialogId, settings) {
|
|
1280
|
+
super(dialogId);
|
|
1281
|
+
this.settings = settings;
|
|
1354
1282
|
validateScopesType(settings.scopes);
|
|
1355
1283
|
internalLogger.info("Create a new Teams Bot SSO Prompt");
|
|
1356
|
-
return _this;
|
|
1357
1284
|
}
|
|
1358
1285
|
/**
|
|
1359
1286
|
* Called when a prompt dialog is pushed onto the dialog stack and is being activated.
|
|
@@ -1371,47 +1298,39 @@ var TeamsBotSsoPrompt = /** @class */ (function (_super) {
|
|
|
1371
1298
|
*
|
|
1372
1299
|
* @beta
|
|
1373
1300
|
*/
|
|
1374
|
-
|
|
1301
|
+
beginDialog(dc) {
|
|
1375
1302
|
var _a;
|
|
1376
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
errorMsg = "type of timeout property in teamsBotSsoPromptSettings should be number.";
|
|
1388
|
-
internalLogger.error(errorMsg);
|
|
1389
|
-
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
1390
|
-
}
|
|
1391
|
-
if (this.settings.timeout <= 0) {
|
|
1392
|
-
errorMsg = "value of timeout property in teamsBotSsoPromptSettings should be positive.";
|
|
1393
|
-
internalLogger.error(errorMsg);
|
|
1394
|
-
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
1395
|
-
}
|
|
1396
|
-
timeout = this.settings.timeout;
|
|
1397
|
-
}
|
|
1398
|
-
if (this.settings.endOnInvalidMessage === undefined) {
|
|
1399
|
-
this.settings.endOnInvalidMessage = true;
|
|
1400
|
-
}
|
|
1401
|
-
state = (_a = dc.activeDialog) === null || _a === void 0 ? void 0 : _a.state;
|
|
1402
|
-
state.state = {};
|
|
1403
|
-
state.options = {};
|
|
1404
|
-
state.expires = new Date().getTime() + timeout;
|
|
1405
|
-
// Send OAuth card to get SSO token
|
|
1406
|
-
return [4 /*yield*/, this.sendOAuthCardAsync(dc.context)];
|
|
1407
|
-
case 1:
|
|
1408
|
-
// Send OAuth card to get SSO token
|
|
1409
|
-
_b.sent();
|
|
1410
|
-
return [2 /*return*/, botbuilderDialogs.Dialog.EndOfTurn];
|
|
1303
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1304
|
+
internalLogger.info("Begin Teams Bot SSO Prompt");
|
|
1305
|
+
this.ensureMsTeamsChannel(dc);
|
|
1306
|
+
// Initialize prompt state
|
|
1307
|
+
const default_timeout = 900000;
|
|
1308
|
+
let timeout = default_timeout;
|
|
1309
|
+
if (this.settings.timeout) {
|
|
1310
|
+
if (typeof this.settings.timeout != "number") {
|
|
1311
|
+
const errorMsg = "type of timeout property in teamsBotSsoPromptSettings should be number.";
|
|
1312
|
+
internalLogger.error(errorMsg);
|
|
1313
|
+
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
1411
1314
|
}
|
|
1412
|
-
|
|
1315
|
+
if (this.settings.timeout <= 0) {
|
|
1316
|
+
const errorMsg = "value of timeout property in teamsBotSsoPromptSettings should be positive.";
|
|
1317
|
+
internalLogger.error(errorMsg);
|
|
1318
|
+
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidParameter);
|
|
1319
|
+
}
|
|
1320
|
+
timeout = this.settings.timeout;
|
|
1321
|
+
}
|
|
1322
|
+
if (this.settings.endOnInvalidMessage === undefined) {
|
|
1323
|
+
this.settings.endOnInvalidMessage = true;
|
|
1324
|
+
}
|
|
1325
|
+
const state = (_a = dc.activeDialog) === null || _a === void 0 ? void 0 : _a.state;
|
|
1326
|
+
state.state = {};
|
|
1327
|
+
state.options = {};
|
|
1328
|
+
state.expires = new Date().getTime() + timeout;
|
|
1329
|
+
// Send OAuth card to get SSO token
|
|
1330
|
+
yield this.sendOAuthCardAsync(dc.context);
|
|
1331
|
+
return botbuilderDialogs.Dialog.EndOfTurn;
|
|
1413
1332
|
});
|
|
1414
|
-
}
|
|
1333
|
+
}
|
|
1415
1334
|
/**
|
|
1416
1335
|
* Called when a prompt dialog is the active dialog and the user replied with a new activity.
|
|
1417
1336
|
*
|
|
@@ -1430,90 +1349,74 @@ var TeamsBotSsoPrompt = /** @class */ (function (_super) {
|
|
|
1430
1349
|
*
|
|
1431
1350
|
* @beta
|
|
1432
1351
|
*/
|
|
1433
|
-
|
|
1352
|
+
continueDialog(dc) {
|
|
1434
1353
|
var _a;
|
|
1435
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
return [4 /*yield*/, dc.endDialog(recognized.value)];
|
|
1460
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
1461
|
-
case 5: return [3 /*break*/, 8];
|
|
1462
|
-
case 6:
|
|
1463
|
-
if (!(isMessage && this.settings.endOnInvalidMessage)) return [3 /*break*/, 8];
|
|
1464
|
-
internalLogger.warn("End Teams Bot SSO Prompt due to invalid message");
|
|
1465
|
-
return [4 /*yield*/, dc.endDialog(undefined)];
|
|
1466
|
-
case 7: return [2 /*return*/, _b.sent()];
|
|
1467
|
-
case 8: return [2 /*return*/, botbuilderDialogs.Dialog.EndOfTurn];
|
|
1354
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1355
|
+
internalLogger.info("Continue Teams Bot SSO Prompt");
|
|
1356
|
+
this.ensureMsTeamsChannel(dc);
|
|
1357
|
+
// Check for timeout
|
|
1358
|
+
const state = (_a = dc.activeDialog) === null || _a === void 0 ? void 0 : _a.state;
|
|
1359
|
+
const isMessage = dc.context.activity.type === botbuilder.ActivityTypes.Message;
|
|
1360
|
+
const isTimeoutActivityType = isMessage ||
|
|
1361
|
+
this.isTeamsVerificationInvoke(dc.context) ||
|
|
1362
|
+
this.isTokenExchangeRequestInvoke(dc.context);
|
|
1363
|
+
// If the incoming Activity is a message, or an Activity Type normally handled by TeamsBotSsoPrompt,
|
|
1364
|
+
// check to see if this TeamsBotSsoPrompt Expiration has elapsed, and end the dialog if so.
|
|
1365
|
+
const hasTimedOut = isTimeoutActivityType && new Date().getTime() > state.expires;
|
|
1366
|
+
if (hasTimedOut) {
|
|
1367
|
+
internalLogger.warn("End Teams Bot SSO Prompt due to timeout");
|
|
1368
|
+
return yield dc.endDialog(undefined);
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
if (this.isTeamsVerificationInvoke(dc.context) ||
|
|
1372
|
+
this.isTokenExchangeRequestInvoke(dc.context)) {
|
|
1373
|
+
// Recognize token
|
|
1374
|
+
const recognized = yield this.recognizeToken(dc);
|
|
1375
|
+
if (recognized.succeeded) {
|
|
1376
|
+
return yield dc.endDialog(recognized.value);
|
|
1377
|
+
}
|
|
1468
1378
|
}
|
|
1469
|
-
|
|
1379
|
+
else if (isMessage && this.settings.endOnInvalidMessage) {
|
|
1380
|
+
internalLogger.warn("End Teams Bot SSO Prompt due to invalid message");
|
|
1381
|
+
return yield dc.endDialog(undefined);
|
|
1382
|
+
}
|
|
1383
|
+
return botbuilderDialogs.Dialog.EndOfTurn;
|
|
1384
|
+
}
|
|
1470
1385
|
});
|
|
1471
|
-
}
|
|
1386
|
+
}
|
|
1472
1387
|
/**
|
|
1473
1388
|
* Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
|
|
1474
1389
|
* @param dc dialog context
|
|
1475
1390
|
* @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
|
|
1476
1391
|
* @internal
|
|
1477
1392
|
*/
|
|
1478
|
-
|
|
1393
|
+
ensureMsTeamsChannel(dc) {
|
|
1479
1394
|
if (dc.context.activity.channelId != botbuilder.Channels.Msteams) {
|
|
1480
|
-
|
|
1395
|
+
const errorMsg = formatString(ErrorMessage.OnlyMSTeamsChannelSupported, "Teams Bot SSO Prompt");
|
|
1481
1396
|
internalLogger.error(errorMsg);
|
|
1482
1397
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.ChannelNotSupported);
|
|
1483
1398
|
}
|
|
1484
|
-
}
|
|
1399
|
+
}
|
|
1485
1400
|
/**
|
|
1486
1401
|
* Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
|
|
1487
1402
|
* For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
|
|
1488
1403
|
*
|
|
1489
1404
|
* @internal
|
|
1490
1405
|
*/
|
|
1491
|
-
|
|
1492
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
signInResource = this.getSignInResource(loginHint);
|
|
1504
|
-
card = botbuilder.CardFactory.oauthCard("", "Teams SSO Sign In", "Sign In", signInResource.signInLink, signInResource.tokenExchangeResource);
|
|
1505
|
-
card.content.buttons[0].type = botbuilder.ActionTypes.Signin;
|
|
1506
|
-
msg = botbuilder.MessageFactory.attachment(card);
|
|
1507
|
-
// Send prompt
|
|
1508
|
-
return [4 /*yield*/, context.sendActivity(msg)];
|
|
1509
|
-
case 2:
|
|
1510
|
-
// Send prompt
|
|
1511
|
-
_a.sent();
|
|
1512
|
-
return [2 /*return*/];
|
|
1513
|
-
}
|
|
1514
|
-
});
|
|
1406
|
+
sendOAuthCardAsync(context) {
|
|
1407
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1408
|
+
internalLogger.verbose("Send OAuth card to get SSO token");
|
|
1409
|
+
const account = yield botbuilder.TeamsInfo.getMember(context, context.activity.from.id);
|
|
1410
|
+
internalLogger.verbose("Get Teams member account user principal name: " + account.userPrincipalName);
|
|
1411
|
+
const loginHint = account.userPrincipalName ? account.userPrincipalName : "";
|
|
1412
|
+
const signInResource = this.getSignInResource(loginHint);
|
|
1413
|
+
const card = botbuilder.CardFactory.oauthCard("", "Teams SSO Sign In", "Sign In", signInResource.signInLink, signInResource.tokenExchangeResource);
|
|
1414
|
+
card.content.buttons[0].type = botbuilder.ActionTypes.Signin;
|
|
1415
|
+
const msg = botbuilder.MessageFactory.attachment(card);
|
|
1416
|
+
// Send prompt
|
|
1417
|
+
yield context.sendActivity(msg);
|
|
1515
1418
|
});
|
|
1516
|
-
}
|
|
1419
|
+
}
|
|
1517
1420
|
/**
|
|
1518
1421
|
* Get sign in resource.
|
|
1519
1422
|
*
|
|
@@ -1521,10 +1424,10 @@ var TeamsBotSsoPrompt = /** @class */ (function (_super) {
|
|
|
1521
1424
|
*
|
|
1522
1425
|
* @internal
|
|
1523
1426
|
*/
|
|
1524
|
-
|
|
1427
|
+
getSignInResource(loginHint) {
|
|
1525
1428
|
var _a, _b, _c, _d, _e;
|
|
1526
1429
|
internalLogger.verbose("Get sign in authentication configuration");
|
|
1527
|
-
|
|
1430
|
+
const missingConfigurations = [];
|
|
1528
1431
|
if (!((_a = config === null || config === void 0 ? void 0 : config.authentication) === null || _a === void 0 ? void 0 : _a.initiateLoginEndpoint)) {
|
|
1529
1432
|
missingConfigurations.push("initiateLoginEndpoint");
|
|
1530
1433
|
}
|
|
@@ -1538,13 +1441,13 @@ var TeamsBotSsoPrompt = /** @class */ (function (_super) {
|
|
|
1538
1441
|
missingConfigurations.push("applicationIdUri");
|
|
1539
1442
|
}
|
|
1540
1443
|
if (missingConfigurations.length != 0) {
|
|
1541
|
-
|
|
1444
|
+
const errorMsg = formatString(ErrorMessage.InvalidConfiguration, missingConfigurations.join(", "), "undefined");
|
|
1542
1445
|
internalLogger.error(errorMsg);
|
|
1543
1446
|
throw new ErrorWithCode(errorMsg, exports.ErrorCode.InvalidConfiguration);
|
|
1544
1447
|
}
|
|
1545
|
-
|
|
1448
|
+
const signInLink = `${config.authentication.initiateLoginEndpoint}?scope=${encodeURI(this.settings.scopes.join(" "))}&clientId=${config.authentication.clientId}&tenantId=${config.authentication.tenantId}&loginHint=${loginHint}`;
|
|
1546
1449
|
internalLogger.verbose("Sign in link: " + signInLink);
|
|
1547
|
-
|
|
1450
|
+
const tokenExchangeResource = {
|
|
1548
1451
|
id: uuid.v4(),
|
|
1549
1452
|
uri: ((_e = config.authentication) === null || _e === void 0 ? void 0 : _e.applicationIdUri.replace(/\/$/, "")) + "/access_as_user",
|
|
1550
1453
|
};
|
|
@@ -1553,108 +1456,88 @@ var TeamsBotSsoPrompt = /** @class */ (function (_super) {
|
|
|
1553
1456
|
signInLink: signInLink,
|
|
1554
1457
|
tokenExchangeResource: tokenExchangeResource,
|
|
1555
1458
|
};
|
|
1556
|
-
}
|
|
1459
|
+
}
|
|
1557
1460
|
/**
|
|
1558
1461
|
* @internal
|
|
1559
1462
|
*/
|
|
1560
|
-
|
|
1561
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
ssoToken: ssoToken,
|
|
1593
|
-
ssoTokenExpiration: new Date(ssoTokenExpiration * 1000).toISOString(),
|
|
1594
|
-
connectionName: "",
|
|
1595
|
-
token: exchangedToken.token,
|
|
1596
|
-
expiration: exchangedToken.expiresOnTimestamp.toString(),
|
|
1597
|
-
};
|
|
1598
|
-
_a.label = 6;
|
|
1599
|
-
case 6: return [3 /*break*/, 9];
|
|
1600
|
-
case 7:
|
|
1601
|
-
_a.sent();
|
|
1602
|
-
warningMsg = "The bot is unable to exchange token. Ask for user consent.";
|
|
1463
|
+
recognizeToken(dc) {
|
|
1464
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1465
|
+
const context = dc.context;
|
|
1466
|
+
let tokenResponse;
|
|
1467
|
+
if (this.isTokenExchangeRequestInvoke(context)) {
|
|
1468
|
+
internalLogger.verbose("Receive token exchange request");
|
|
1469
|
+
// Received activity is not a token exchange request
|
|
1470
|
+
if (!(context.activity.value && this.isTokenExchangeRequest(context.activity.value))) {
|
|
1471
|
+
const warningMsg = "The bot received an InvokeActivity that is missing a TokenExchangeInvokeRequest value. This is required to be sent with the InvokeActivity.";
|
|
1472
|
+
internalLogger.warn(warningMsg);
|
|
1473
|
+
yield context.sendActivity(this.getTokenExchangeInvokeResponse(botbuilder.StatusCodes.BAD_REQUEST, warningMsg));
|
|
1474
|
+
}
|
|
1475
|
+
else {
|
|
1476
|
+
const ssoToken = context.activity.value.token;
|
|
1477
|
+
const credential = new OnBehalfOfUserCredential(ssoToken);
|
|
1478
|
+
let exchangedToken;
|
|
1479
|
+
try {
|
|
1480
|
+
exchangedToken = yield credential.getToken(this.settings.scopes);
|
|
1481
|
+
if (exchangedToken) {
|
|
1482
|
+
yield context.sendActivity(this.getTokenExchangeInvokeResponse(botbuilder.StatusCodes.OK, "", context.activity.value.id));
|
|
1483
|
+
const ssoTokenExpiration = parseJwt(ssoToken).exp;
|
|
1484
|
+
tokenResponse = {
|
|
1485
|
+
ssoToken: ssoToken,
|
|
1486
|
+
ssoTokenExpiration: new Date(ssoTokenExpiration * 1000).toISOString(),
|
|
1487
|
+
connectionName: "",
|
|
1488
|
+
token: exchangedToken.token,
|
|
1489
|
+
expiration: exchangedToken.expiresOnTimestamp.toString(),
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
catch (error) {
|
|
1494
|
+
const warningMsg = "The bot is unable to exchange token. Ask for user consent.";
|
|
1603
1495
|
internalLogger.info(warningMsg);
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
_a.sent();
|
|
1607
|
-
return [3 /*break*/, 9];
|
|
1608
|
-
case 9: return [3 /*break*/, 13];
|
|
1609
|
-
case 10:
|
|
1610
|
-
if (!this.isTeamsVerificationInvoke(context)) return [3 /*break*/, 13];
|
|
1611
|
-
internalLogger.verbose("Receive Teams state verification request");
|
|
1612
|
-
return [4 /*yield*/, this.sendOAuthCardAsync(dc.context)];
|
|
1613
|
-
case 11:
|
|
1614
|
-
_a.sent();
|
|
1615
|
-
return [4 /*yield*/, context.sendActivity({ type: invokeResponseType, value: { status: botbuilder.StatusCodes.OK } })];
|
|
1616
|
-
case 12:
|
|
1617
|
-
_a.sent();
|
|
1618
|
-
_a.label = 13;
|
|
1619
|
-
case 13: return [2 /*return*/, tokenResponse !== undefined
|
|
1620
|
-
? { succeeded: true, value: tokenResponse }
|
|
1621
|
-
: { succeeded: false }];
|
|
1496
|
+
yield context.sendActivity(this.getTokenExchangeInvokeResponse(botbuilder.StatusCodes.PRECONDITION_FAILED, warningMsg, context.activity.value.id));
|
|
1497
|
+
}
|
|
1622
1498
|
}
|
|
1623
|
-
}
|
|
1499
|
+
}
|
|
1500
|
+
else if (this.isTeamsVerificationInvoke(context)) {
|
|
1501
|
+
internalLogger.verbose("Receive Teams state verification request");
|
|
1502
|
+
yield this.sendOAuthCardAsync(dc.context);
|
|
1503
|
+
yield context.sendActivity({ type: invokeResponseType, value: { status: botbuilder.StatusCodes.OK } });
|
|
1504
|
+
}
|
|
1505
|
+
return tokenResponse !== undefined
|
|
1506
|
+
? { succeeded: true, value: tokenResponse }
|
|
1507
|
+
: { succeeded: false };
|
|
1624
1508
|
});
|
|
1625
|
-
}
|
|
1509
|
+
}
|
|
1626
1510
|
/**
|
|
1627
1511
|
* @internal
|
|
1628
1512
|
*/
|
|
1629
|
-
|
|
1630
|
-
|
|
1513
|
+
getTokenExchangeInvokeResponse(status, failureDetail, id) {
|
|
1514
|
+
const invokeResponse = {
|
|
1631
1515
|
type: invokeResponseType,
|
|
1632
|
-
value: { status
|
|
1516
|
+
value: { status, body: new TokenExchangeInvokeResponse(id, failureDetail) },
|
|
1633
1517
|
};
|
|
1634
1518
|
return invokeResponse;
|
|
1635
|
-
}
|
|
1519
|
+
}
|
|
1636
1520
|
/**
|
|
1637
1521
|
* @internal
|
|
1638
1522
|
*/
|
|
1639
|
-
|
|
1640
|
-
|
|
1523
|
+
isTeamsVerificationInvoke(context) {
|
|
1524
|
+
const activity = context.activity;
|
|
1641
1525
|
return activity.type === botbuilder.ActivityTypes.Invoke && activity.name === botbuilder.verifyStateOperationName;
|
|
1642
|
-
}
|
|
1526
|
+
}
|
|
1643
1527
|
/**
|
|
1644
1528
|
* @internal
|
|
1645
1529
|
*/
|
|
1646
|
-
|
|
1647
|
-
|
|
1530
|
+
isTokenExchangeRequestInvoke(context) {
|
|
1531
|
+
const activity = context.activity;
|
|
1648
1532
|
return activity.type === botbuilder.ActivityTypes.Invoke && activity.name === botbuilder.tokenExchangeOperationName;
|
|
1649
|
-
}
|
|
1533
|
+
}
|
|
1650
1534
|
/**
|
|
1651
1535
|
* @internal
|
|
1652
1536
|
*/
|
|
1653
|
-
|
|
1537
|
+
isTokenExchangeRequest(obj) {
|
|
1654
1538
|
return obj.hasOwnProperty("token");
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
}(botbuilderDialogs.Dialog));
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1658
1541
|
|
|
1659
1542
|
exports.DefaultTediousConnectionConfiguration = DefaultTediousConnectionConfiguration;
|
|
1660
1543
|
exports.ErrorWithCode = ErrorWithCode;
|