@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.esm5.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { __extends, __awaiter, __generator } from 'tslib';
|
|
2
1
|
import jwt_decode from 'jwt-decode';
|
|
2
|
+
import { __awaiter } from 'tslib';
|
|
3
3
|
import * as microsoftTeams from '@microsoft/teams-js';
|
|
4
4
|
import { PublicClientApplication } from '@azure/msal-browser';
|
|
5
5
|
import { Client } from '@microsoft/microsoft-graph-client';
|
|
6
6
|
|
|
7
7
|
// Copyright (c) Microsoft Corporation.
|
|
8
|
+
// Licensed under the MIT license.
|
|
8
9
|
/**
|
|
9
10
|
* Error code to trace the error types.
|
|
10
11
|
* @beta
|
|
@@ -56,38 +57,34 @@ var ErrorCode;
|
|
|
56
57
|
*/
|
|
57
58
|
ErrorCode["FailedOperation"] = "FailedOperation";
|
|
58
59
|
/**
|
|
59
|
-
*
|
|
60
|
+
* Invalid response error.
|
|
60
61
|
*/
|
|
61
|
-
ErrorCode["
|
|
62
|
+
ErrorCode["InvalidResponse"] = "InvalidResponse";
|
|
62
63
|
})(ErrorCode || (ErrorCode = {}));
|
|
63
64
|
/**
|
|
64
65
|
* @internal
|
|
65
66
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
|
|
82
|
-
return ErrorMessage;
|
|
83
|
-
}());
|
|
67
|
+
class ErrorMessage {
|
|
68
|
+
}
|
|
69
|
+
// InvalidConfiguration Error
|
|
70
|
+
ErrorMessage.InvalidConfiguration = "{0} in configuration is invalid: {1}.";
|
|
71
|
+
ErrorMessage.ConfigurationNotExists = "Configuration does not exist. {0}";
|
|
72
|
+
ErrorMessage.ResourceConfigurationNotExists = "{0} resource configuration does not exist.";
|
|
73
|
+
ErrorMessage.MissingResourceConfiguration = "Missing resource configuration with type: {0}, name: {1}.";
|
|
74
|
+
ErrorMessage.AuthenticationConfigurationNotExists = "Authentication configuration does not exist.";
|
|
75
|
+
// RuntimeNotSupported Error
|
|
76
|
+
ErrorMessage.BrowserRuntimeNotSupported = "{0} is not supported in browser.";
|
|
77
|
+
ErrorMessage.NodejsRuntimeNotSupported = "{0} is not supported in Node.";
|
|
78
|
+
// Internal Error
|
|
79
|
+
ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token on behalf of user: {0}";
|
|
80
|
+
// ChannelNotSupported Error
|
|
81
|
+
ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
|
|
84
82
|
/**
|
|
85
83
|
* Error class with code and message thrown by the SDK.
|
|
86
84
|
*
|
|
87
85
|
* @beta
|
|
88
86
|
*/
|
|
89
|
-
|
|
90
|
-
__extends(ErrorWithCode, _super);
|
|
87
|
+
class ErrorWithCode extends Error {
|
|
91
88
|
/**
|
|
92
89
|
* Constructor of ErrorWithCode.
|
|
93
90
|
*
|
|
@@ -96,21 +93,17 @@ var ErrorWithCode = /** @class */ (function (_super) {
|
|
|
96
93
|
*
|
|
97
94
|
* @beta
|
|
98
95
|
*/
|
|
99
|
-
|
|
100
|
-
var _newTarget = this.constructor;
|
|
101
|
-
var _this = this;
|
|
96
|
+
constructor(message, code) {
|
|
102
97
|
if (!code) {
|
|
103
|
-
|
|
104
|
-
return
|
|
98
|
+
super(message);
|
|
99
|
+
return this;
|
|
105
100
|
}
|
|
106
|
-
|
|
107
|
-
Object.setPrototypeOf(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return _this;
|
|
101
|
+
super(message);
|
|
102
|
+
Object.setPrototypeOf(this, ErrorWithCode.prototype);
|
|
103
|
+
this.name = `${new.target.name}.${code}`;
|
|
104
|
+
this.code = code;
|
|
111
105
|
}
|
|
112
|
-
|
|
113
|
-
}(Error));
|
|
106
|
+
}
|
|
114
107
|
|
|
115
108
|
// Copyright (c) Microsoft Corporation.
|
|
116
109
|
// Licensed under the MIT license.
|
|
@@ -178,8 +171,8 @@ function setLogLevel(level) {
|
|
|
178
171
|
function getLogLevel() {
|
|
179
172
|
return internalLogger.level;
|
|
180
173
|
}
|
|
181
|
-
|
|
182
|
-
|
|
174
|
+
class InternalLogger {
|
|
175
|
+
constructor(name, logLevel) {
|
|
183
176
|
this.level = undefined;
|
|
184
177
|
this.defaultLogger = {
|
|
185
178
|
verbose: console.debug,
|
|
@@ -190,31 +183,31 @@ var InternalLogger = /** @class */ (function () {
|
|
|
190
183
|
this.name = name;
|
|
191
184
|
this.level = logLevel;
|
|
192
185
|
}
|
|
193
|
-
|
|
194
|
-
this.log(LogLevel.Error,
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
this.log(LogLevel.Warn,
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.log(LogLevel.Info,
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
this.log(LogLevel.Verbose,
|
|
204
|
-
}
|
|
205
|
-
|
|
186
|
+
error(message) {
|
|
187
|
+
this.log(LogLevel.Error, (x) => x.error, message);
|
|
188
|
+
}
|
|
189
|
+
warn(message) {
|
|
190
|
+
this.log(LogLevel.Warn, (x) => x.warn, message);
|
|
191
|
+
}
|
|
192
|
+
info(message) {
|
|
193
|
+
this.log(LogLevel.Info, (x) => x.info, message);
|
|
194
|
+
}
|
|
195
|
+
verbose(message) {
|
|
196
|
+
this.log(LogLevel.Verbose, (x) => x.verbose, message);
|
|
197
|
+
}
|
|
198
|
+
log(logLevel, logFunction, message) {
|
|
206
199
|
if (message.trim() === "") {
|
|
207
200
|
return;
|
|
208
201
|
}
|
|
209
|
-
|
|
210
|
-
|
|
202
|
+
const timestamp = new Date().toUTCString();
|
|
203
|
+
let logHeader;
|
|
211
204
|
if (this.name) {
|
|
212
|
-
logHeader =
|
|
205
|
+
logHeader = `[${timestamp}] : @microsoft/teamsfx - ${this.name} : ${LogLevel[logLevel]} - `;
|
|
213
206
|
}
|
|
214
207
|
else {
|
|
215
|
-
logHeader =
|
|
208
|
+
logHeader = `[${timestamp}] : @microsoft/teamsfx : ${LogLevel[logLevel]} - `;
|
|
216
209
|
}
|
|
217
|
-
|
|
210
|
+
const logMessage = `${logHeader}${message}`;
|
|
218
211
|
if (this.level !== undefined && this.level <= logLevel) {
|
|
219
212
|
if (this.customLogger) {
|
|
220
213
|
logFunction(this.customLogger)(logMessage);
|
|
@@ -226,15 +219,14 @@ var InternalLogger = /** @class */ (function () {
|
|
|
226
219
|
logFunction(this.defaultLogger)(logMessage);
|
|
227
220
|
}
|
|
228
221
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
}());
|
|
222
|
+
}
|
|
223
|
+
}
|
|
232
224
|
/**
|
|
233
225
|
* Logger instance used internally
|
|
234
226
|
*
|
|
235
227
|
* @internal
|
|
236
228
|
*/
|
|
237
|
-
|
|
229
|
+
const internalLogger = new InternalLogger();
|
|
238
230
|
/**
|
|
239
231
|
* Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
|
|
240
232
|
*
|
|
@@ -287,14 +279,14 @@ function setLogFunction(logFunction) {
|
|
|
287
279
|
*/
|
|
288
280
|
function parseJwt(token) {
|
|
289
281
|
try {
|
|
290
|
-
|
|
282
|
+
const tokenObj = jwt_decode(token);
|
|
291
283
|
if (!tokenObj || !tokenObj.exp) {
|
|
292
284
|
throw new ErrorWithCode("Decoded token is null or exp claim does not exists.", ErrorCode.InternalError);
|
|
293
285
|
}
|
|
294
286
|
return tokenObj;
|
|
295
287
|
}
|
|
296
288
|
catch (err) {
|
|
297
|
-
|
|
289
|
+
const errorMsg = "Parse jwt token failed in node env with error: " + err.message;
|
|
298
290
|
internalLogger.error(errorMsg);
|
|
299
291
|
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
300
292
|
}
|
|
@@ -304,12 +296,12 @@ function parseJwt(token) {
|
|
|
304
296
|
*/
|
|
305
297
|
function getUserInfoFromSsoToken(ssoToken) {
|
|
306
298
|
if (!ssoToken) {
|
|
307
|
-
|
|
299
|
+
const errorMsg = "SSO token is undefined.";
|
|
308
300
|
internalLogger.error(errorMsg);
|
|
309
301
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);
|
|
310
302
|
}
|
|
311
|
-
|
|
312
|
-
|
|
303
|
+
const tokenObject = parseJwt(ssoToken);
|
|
304
|
+
const userInfo = {
|
|
313
305
|
displayName: tokenObject.name,
|
|
314
306
|
objectId: tokenObject.oid,
|
|
315
307
|
preferredUserName: "",
|
|
@@ -327,12 +319,12 @@ function getUserInfoFromSsoToken(ssoToken) {
|
|
|
327
319
|
*/
|
|
328
320
|
function getTenantIdAndLoginHintFromSsoToken(ssoToken) {
|
|
329
321
|
if (!ssoToken) {
|
|
330
|
-
|
|
322
|
+
const errorMsg = "SSO token is undefined.";
|
|
331
323
|
internalLogger.error(errorMsg);
|
|
332
324
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);
|
|
333
325
|
}
|
|
334
|
-
|
|
335
|
-
|
|
326
|
+
const tokenObject = parseJwt(ssoToken);
|
|
327
|
+
const userInfo = {
|
|
336
328
|
tid: tokenObject.tid,
|
|
337
329
|
loginHint: tokenObject.ver === "2.0"
|
|
338
330
|
? tokenObject.preferred_username
|
|
@@ -345,29 +337,29 @@ function getTenantIdAndLoginHintFromSsoToken(ssoToken) {
|
|
|
345
337
|
*/
|
|
346
338
|
function parseAccessTokenFromAuthCodeTokenResponse(tokenResponse) {
|
|
347
339
|
try {
|
|
348
|
-
|
|
340
|
+
const tokenResponseObject = typeof tokenResponse == "string"
|
|
349
341
|
? JSON.parse(tokenResponse)
|
|
350
342
|
: tokenResponse;
|
|
351
343
|
if (!tokenResponseObject || !tokenResponseObject.accessToken) {
|
|
352
|
-
|
|
344
|
+
const errorMsg = "Get empty access token from Auth Code token response.";
|
|
353
345
|
internalLogger.error(errorMsg);
|
|
354
346
|
throw new Error(errorMsg);
|
|
355
347
|
}
|
|
356
|
-
|
|
357
|
-
|
|
348
|
+
const token = tokenResponseObject.accessToken;
|
|
349
|
+
const tokenObject = parseJwt(token);
|
|
358
350
|
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
359
|
-
|
|
351
|
+
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
360
352
|
internalLogger.error(errorMsg);
|
|
361
353
|
throw new Error(errorMsg);
|
|
362
354
|
}
|
|
363
|
-
|
|
355
|
+
const accessToken = {
|
|
364
356
|
token: token,
|
|
365
357
|
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
366
358
|
};
|
|
367
359
|
return accessToken;
|
|
368
360
|
}
|
|
369
361
|
catch (error) {
|
|
370
|
-
|
|
362
|
+
const errorMsg = "Parse access token failed from Auth Code token response in node env with error: " +
|
|
371
363
|
error.message;
|
|
372
364
|
internalLogger.error(errorMsg);
|
|
373
365
|
throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
|
|
@@ -387,12 +379,8 @@ function parseAccessTokenFromAuthCodeTokenResponse(tokenResponse) {
|
|
|
387
379
|
*
|
|
388
380
|
* @internal
|
|
389
381
|
*/
|
|
390
|
-
function formatString(str) {
|
|
391
|
-
|
|
392
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
393
|
-
replacements[_i - 1] = arguments[_i];
|
|
394
|
-
}
|
|
395
|
-
var args = replacements;
|
|
382
|
+
function formatString(str, ...replacements) {
|
|
383
|
+
const args = replacements;
|
|
396
384
|
return str.replace(/{(\d+)}/g, function (match, number) {
|
|
397
385
|
return typeof args[number] != "undefined" ? args[number] : match;
|
|
398
386
|
});
|
|
@@ -410,17 +398,17 @@ function validateScopesType(value) {
|
|
|
410
398
|
return;
|
|
411
399
|
}
|
|
412
400
|
// string array
|
|
413
|
-
if (Array.isArray(value) && value.length > 0 && value.every(
|
|
401
|
+
if (Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string")) {
|
|
414
402
|
return;
|
|
415
403
|
}
|
|
416
|
-
|
|
404
|
+
const errorMsg = "The type of scopes is not valid, it must be string or string array";
|
|
417
405
|
internalLogger.error(errorMsg);
|
|
418
406
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);
|
|
419
407
|
}
|
|
420
408
|
/**
|
|
421
409
|
* @internal
|
|
422
410
|
*/
|
|
423
|
-
|
|
411
|
+
const isNode = typeof process !== "undefined" &&
|
|
424
412
|
!!process.version &&
|
|
425
413
|
!!process.versions &&
|
|
426
414
|
!!process.versions.node;
|
|
@@ -430,7 +418,7 @@ var isNode = typeof process !== "undefined" &&
|
|
|
430
418
|
* Global configuration instance
|
|
431
419
|
*
|
|
432
420
|
*/
|
|
433
|
-
|
|
421
|
+
let config;
|
|
434
422
|
/**
|
|
435
423
|
* Initialize configuration from environment variables or configuration object and set the global instance
|
|
436
424
|
*
|
|
@@ -445,7 +433,7 @@ function loadConfiguration(configuration) {
|
|
|
445
433
|
// browser environment
|
|
446
434
|
if (!isNode) {
|
|
447
435
|
if (!configuration) {
|
|
448
|
-
|
|
436
|
+
const errorMsg = "You are running the code in browser. Configuration must be passed in.";
|
|
449
437
|
internalLogger.error(errorMsg);
|
|
450
438
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);
|
|
451
439
|
}
|
|
@@ -453,9 +441,9 @@ function loadConfiguration(configuration) {
|
|
|
453
441
|
return;
|
|
454
442
|
}
|
|
455
443
|
// node environment
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
444
|
+
let newAuthentication;
|
|
445
|
+
let newResources = [];
|
|
446
|
+
const defaultResourceName = "default";
|
|
459
447
|
if (configuration === null || configuration === void 0 ? void 0 : configuration.authentication) {
|
|
460
448
|
newAuthentication = configuration.authentication;
|
|
461
449
|
}
|
|
@@ -513,15 +501,14 @@ function loadConfiguration(configuration) {
|
|
|
513
501
|
*
|
|
514
502
|
* @beta
|
|
515
503
|
*/
|
|
516
|
-
function getResourceConfiguration(resourceType, resourceName) {
|
|
504
|
+
function getResourceConfiguration(resourceType, resourceName = "default") {
|
|
517
505
|
var _a;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
var result = (_a = config.resources) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.type === resourceType && item.name === resourceName; });
|
|
506
|
+
internalLogger.info(`Get resource configuration of ${ResourceType[resourceType]} from ${resourceName}`);
|
|
507
|
+
const result = (_a = config.resources) === null || _a === void 0 ? void 0 : _a.find((item) => item.type === resourceType && item.name === resourceName);
|
|
521
508
|
if (result) {
|
|
522
509
|
return result.properties;
|
|
523
510
|
}
|
|
524
|
-
|
|
511
|
+
const errorMsg = formatString(ErrorMessage.MissingResourceConfiguration, ResourceType[resourceType], resourceName);
|
|
525
512
|
internalLogger.error(errorMsg);
|
|
526
513
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidConfiguration);
|
|
527
514
|
}
|
|
@@ -539,7 +526,7 @@ function getAuthenticationConfiguration() {
|
|
|
539
526
|
if (config) {
|
|
540
527
|
return config.authentication;
|
|
541
528
|
}
|
|
542
|
-
|
|
529
|
+
const errorMsg = "Please call loadConfiguration() first before calling getAuthenticationConfiguration().";
|
|
543
530
|
internalLogger.error(errorMsg);
|
|
544
531
|
throw new ErrorWithCode(formatString(ErrorMessage.ConfigurationNotExists, errorMsg), ErrorCode.InvalidConfiguration);
|
|
545
532
|
}
|
|
@@ -553,7 +540,7 @@ function getAuthenticationConfiguration() {
|
|
|
553
540
|
*
|
|
554
541
|
* @beta
|
|
555
542
|
*/
|
|
556
|
-
|
|
543
|
+
class M365TenantCredential {
|
|
557
544
|
/**
|
|
558
545
|
* Constructor of M365TenantCredential.
|
|
559
546
|
*
|
|
@@ -561,7 +548,7 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
561
548
|
* Only works in in server side.
|
|
562
549
|
* @beta
|
|
563
550
|
*/
|
|
564
|
-
|
|
551
|
+
constructor() {
|
|
565
552
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "M365TenantCredential"), ErrorCode.RuntimeNotSupported);
|
|
566
553
|
}
|
|
567
554
|
/**
|
|
@@ -571,15 +558,12 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
571
558
|
* Only works in in server side.
|
|
572
559
|
* @beta
|
|
573
560
|
*/
|
|
574
|
-
|
|
575
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
576
|
-
|
|
577
|
-
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "M365TenantCredential"), ErrorCode.RuntimeNotSupported);
|
|
578
|
-
});
|
|
561
|
+
getToken(scopes, options) {
|
|
562
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
563
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "M365TenantCredential"), ErrorCode.RuntimeNotSupported);
|
|
579
564
|
});
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
}());
|
|
565
|
+
}
|
|
566
|
+
}
|
|
583
567
|
|
|
584
568
|
// Copyright (c) Microsoft Corporation.
|
|
585
569
|
/**
|
|
@@ -590,7 +574,7 @@ var M365TenantCredential = /** @class */ (function () {
|
|
|
590
574
|
*
|
|
591
575
|
* @beta
|
|
592
576
|
*/
|
|
593
|
-
|
|
577
|
+
class OnBehalfOfUserCredential {
|
|
594
578
|
/**
|
|
595
579
|
* Constructor of OnBehalfOfUserCredential
|
|
596
580
|
*
|
|
@@ -598,7 +582,7 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
598
582
|
* Can Only works in in server side.
|
|
599
583
|
* @beta
|
|
600
584
|
*/
|
|
601
|
-
|
|
585
|
+
constructor(ssoToken) {
|
|
602
586
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "OnBehalfOfUserCredential"), ErrorCode.RuntimeNotSupported);
|
|
603
587
|
}
|
|
604
588
|
/**
|
|
@@ -607,30 +591,27 @@ var OnBehalfOfUserCredential = /** @class */ (function () {
|
|
|
607
591
|
* Can only be used in server side.
|
|
608
592
|
* @beta
|
|
609
593
|
*/
|
|
610
|
-
|
|
611
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
612
|
-
|
|
613
|
-
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "OnBehalfOfUserCredential"), ErrorCode.RuntimeNotSupported);
|
|
614
|
-
});
|
|
594
|
+
getToken(scopes, options) {
|
|
595
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
596
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "OnBehalfOfUserCredential"), ErrorCode.RuntimeNotSupported);
|
|
615
597
|
});
|
|
616
|
-
}
|
|
598
|
+
}
|
|
617
599
|
/**
|
|
618
600
|
* Get basic user info from SSO token.
|
|
619
601
|
* @remarks
|
|
620
602
|
* Can only be used in server side.
|
|
621
603
|
* @beta
|
|
622
604
|
*/
|
|
623
|
-
|
|
605
|
+
getUserInfo() {
|
|
624
606
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "OnBehalfOfUserCredential"), ErrorCode.RuntimeNotSupported);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
}());
|
|
607
|
+
}
|
|
608
|
+
}
|
|
628
609
|
|
|
629
610
|
// Copyright (c) Microsoft Corporation.
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
611
|
+
const tokenRefreshTimeSpanInMillisecond = 5 * 60 * 1000;
|
|
612
|
+
const initializeTeamsSdkTimeoutInMillisecond = 5000;
|
|
613
|
+
const loginPageWidth = 600;
|
|
614
|
+
const loginPageHeight = 535;
|
|
634
615
|
/**
|
|
635
616
|
* Represent Teams current user's identity, and it is used within Teams tab application.
|
|
636
617
|
*
|
|
@@ -639,7 +620,7 @@ var loginPageHeight = 535;
|
|
|
639
620
|
*
|
|
640
621
|
* @beta
|
|
641
622
|
*/
|
|
642
|
-
|
|
623
|
+
class TeamsUserCredential {
|
|
643
624
|
/**
|
|
644
625
|
* Constructor of TeamsUserCredential.
|
|
645
626
|
* Developer need to call loadConfiguration(config) before using this class.
|
|
@@ -661,7 +642,7 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
661
642
|
*
|
|
662
643
|
* @beta
|
|
663
644
|
*/
|
|
664
|
-
|
|
645
|
+
constructor() {
|
|
665
646
|
internalLogger.info("Create teams user credential");
|
|
666
647
|
this.config = this.loadAndValidateConfig();
|
|
667
648
|
this.ssoToken = null;
|
|
@@ -689,73 +670,61 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
689
670
|
*
|
|
690
671
|
* @beta
|
|
691
672
|
*/
|
|
692
|
-
|
|
693
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
return [2 /*return*/];
|
|
745
|
-
});
|
|
746
|
-
}); },
|
|
747
|
-
failureCallback: function (reason) {
|
|
748
|
-
var errorMsg = "Consent failed for the scope " + scopesStr + " with error: " + reason;
|
|
749
|
-
internalLogger.error(errorMsg);
|
|
750
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.ConsentFailed));
|
|
751
|
-
},
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
})];
|
|
755
|
-
}
|
|
673
|
+
login(scopes) {
|
|
674
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
675
|
+
validateScopesType(scopes);
|
|
676
|
+
const scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
|
|
677
|
+
internalLogger.info(`Popup login page to get user's access token with scopes: ${scopesStr}`);
|
|
678
|
+
if (!this.initialized) {
|
|
679
|
+
yield this.init();
|
|
680
|
+
}
|
|
681
|
+
return new Promise((resolve, reject) => {
|
|
682
|
+
microsoftTeams.initialize(() => {
|
|
683
|
+
microsoftTeams.authentication.authenticate({
|
|
684
|
+
url: `${this.config.initiateLoginEndpoint}?clientId=${this.config.clientId}&scope=${encodeURI(scopesStr)}&loginHint=${this.loginHint}`,
|
|
685
|
+
width: loginPageWidth,
|
|
686
|
+
height: loginPageHeight,
|
|
687
|
+
successCallback: (result) => __awaiter(this, void 0, void 0, function* () {
|
|
688
|
+
if (!result) {
|
|
689
|
+
const errorMsg = "Get empty authentication result from MSAL";
|
|
690
|
+
internalLogger.error(errorMsg);
|
|
691
|
+
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
let resultJson = {};
|
|
695
|
+
try {
|
|
696
|
+
resultJson = JSON.parse(result);
|
|
697
|
+
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
// If can not parse result as Json, will throw error.
|
|
700
|
+
const failedToParseResult = "Failed to parse response to Json.";
|
|
701
|
+
internalLogger.error(failedToParseResult);
|
|
702
|
+
reject(new ErrorWithCode(failedToParseResult, ErrorCode.InvalidResponse));
|
|
703
|
+
}
|
|
704
|
+
// If code exists in result, user may using previous auth-start and auth-end page.
|
|
705
|
+
if (resultJson.code) {
|
|
706
|
+
const helpLink = "https://aka.ms/teamsfx-auth-code-flow";
|
|
707
|
+
const usingPreviousAuthPage = "Found auth code in response. Auth code is not support for current version of SDK. " +
|
|
708
|
+
`Please refer to the help link for how to fix the issue: ${helpLink}.`;
|
|
709
|
+
internalLogger.error(usingPreviousAuthPage);
|
|
710
|
+
reject(new ErrorWithCode(usingPreviousAuthPage, ErrorCode.InvalidResponse));
|
|
711
|
+
}
|
|
712
|
+
// If sessionStorage exists in result, set the values in current session storage.
|
|
713
|
+
if (resultJson.sessionStorage) {
|
|
714
|
+
this.setSessionStorage(resultJson.sessionStorage);
|
|
715
|
+
}
|
|
716
|
+
resolve();
|
|
717
|
+
}),
|
|
718
|
+
failureCallback: (reason) => {
|
|
719
|
+
const errorMsg = `Consent failed for the scope ${scopesStr} with error: ${reason}`;
|
|
720
|
+
internalLogger.error(errorMsg);
|
|
721
|
+
reject(new ErrorWithCode(errorMsg, ErrorCode.ConsentFailed));
|
|
722
|
+
},
|
|
723
|
+
});
|
|
724
|
+
});
|
|
756
725
|
});
|
|
757
726
|
});
|
|
758
|
-
}
|
|
727
|
+
}
|
|
759
728
|
/**
|
|
760
729
|
* Get access token from credential.
|
|
761
730
|
*
|
|
@@ -790,80 +759,62 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
790
759
|
*
|
|
791
760
|
* @beta
|
|
792
761
|
*/
|
|
793
|
-
|
|
794
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
case 6:
|
|
829
|
-
tokenResponse = _a.sent();
|
|
830
|
-
return [3 /*break*/, 8];
|
|
831
|
-
case 7:
|
|
832
|
-
error_1 = _a.sent();
|
|
833
|
-
acquireTokenSilentFailedMessage = "Failed to call acquireTokenSilent. Reason: " + (error_1 === null || error_1 === void 0 ? void 0 : error_1.message) + ". ";
|
|
834
|
-
internalLogger.verbose(acquireTokenSilentFailedMessage);
|
|
835
|
-
return [3 /*break*/, 8];
|
|
836
|
-
case 8:
|
|
837
|
-
if (!!tokenResponse) return [3 /*break*/, 12];
|
|
838
|
-
_a.label = 9;
|
|
839
|
-
case 9:
|
|
840
|
-
_a.trys.push([9, 11, , 12]);
|
|
841
|
-
scopesRequestForSsoSilent = {
|
|
762
|
+
getToken(scopes, options) {
|
|
763
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
764
|
+
validateScopesType(scopes);
|
|
765
|
+
const ssoToken = yield this.getSSOToken();
|
|
766
|
+
const scopeStr = typeof scopes === "string" ? scopes : scopes.join(" ");
|
|
767
|
+
if (scopeStr === "") {
|
|
768
|
+
internalLogger.info("Get SSO token");
|
|
769
|
+
return ssoToken;
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
internalLogger.info("Get access token with scopes: " + scopeStr);
|
|
773
|
+
if (!this.initialized) {
|
|
774
|
+
yield this.init();
|
|
775
|
+
}
|
|
776
|
+
let tokenResponse;
|
|
777
|
+
const scopesArray = typeof scopes === "string" ? scopes.split(" ") : scopes;
|
|
778
|
+
const domain = window.location.origin;
|
|
779
|
+
// First try to get Access Token from cache.
|
|
780
|
+
try {
|
|
781
|
+
const account = this.msalInstance.getAccountByUsername(this.loginHint);
|
|
782
|
+
const scopesRequestForAcquireTokenSilent = {
|
|
783
|
+
scopes: scopesArray,
|
|
784
|
+
account: account !== null && account !== void 0 ? account : undefined,
|
|
785
|
+
redirectUri: `${domain}/blank-auth-end.html`,
|
|
786
|
+
};
|
|
787
|
+
tokenResponse = yield this.msalInstance.acquireTokenSilent(scopesRequestForAcquireTokenSilent);
|
|
788
|
+
}
|
|
789
|
+
catch (error) {
|
|
790
|
+
const acquireTokenSilentFailedMessage = `Failed to call acquireTokenSilent. Reason: ${error === null || error === void 0 ? void 0 : error.message}. `;
|
|
791
|
+
internalLogger.verbose(acquireTokenSilentFailedMessage);
|
|
792
|
+
}
|
|
793
|
+
if (!tokenResponse) {
|
|
794
|
+
// If fail to get Access Token from cache, try to get Access token by silent login.
|
|
795
|
+
try {
|
|
796
|
+
const scopesRequestForSsoSilent = {
|
|
842
797
|
scopes: scopesArray,
|
|
843
798
|
loginHint: this.loginHint,
|
|
844
|
-
redirectUri: domain
|
|
799
|
+
redirectUri: `${domain}/blank-auth-end.html`,
|
|
845
800
|
};
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
case 11:
|
|
851
|
-
error_2 = _a.sent();
|
|
852
|
-
ssoSilentFailedMessage = "Failed to call ssoSilent. Reason: " + (error_2 === null || error_2 === void 0 ? void 0 : error_2.message) + ". ";
|
|
801
|
+
tokenResponse = yield this.msalInstance.ssoSilent(scopesRequestForSsoSilent);
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
const ssoSilentFailedMessage = `Failed to call ssoSilent. Reason: ${error === null || error === void 0 ? void 0 : error.message}. `;
|
|
853
805
|
internalLogger.verbose(ssoSilentFailedMessage);
|
|
854
|
-
|
|
855
|
-
case 12:
|
|
856
|
-
if (!tokenResponse) {
|
|
857
|
-
errorMsg = "Failed to get access token cache silently, please login first: you need login first before get access token.";
|
|
858
|
-
internalLogger.error(errorMsg);
|
|
859
|
-
throw new ErrorWithCode(errorMsg, ErrorCode.UiRequiredError);
|
|
860
|
-
}
|
|
861
|
-
accessToken = parseAccessTokenFromAuthCodeTokenResponse(tokenResponse);
|
|
862
|
-
return [2 /*return*/, accessToken];
|
|
806
|
+
}
|
|
863
807
|
}
|
|
864
|
-
|
|
808
|
+
if (!tokenResponse) {
|
|
809
|
+
const errorMsg = `Failed to get access token cache silently, please login first: you need login first before get access token.`;
|
|
810
|
+
internalLogger.error(errorMsg);
|
|
811
|
+
throw new ErrorWithCode(errorMsg, ErrorCode.UiRequiredError);
|
|
812
|
+
}
|
|
813
|
+
const accessToken = parseAccessTokenFromAuthCodeTokenResponse(tokenResponse);
|
|
814
|
+
return accessToken;
|
|
815
|
+
}
|
|
865
816
|
});
|
|
866
|
-
}
|
|
817
|
+
}
|
|
867
818
|
/**
|
|
868
819
|
* Get basic user info from SSO token
|
|
869
820
|
*
|
|
@@ -880,90 +831,73 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
880
831
|
*
|
|
881
832
|
* @beta
|
|
882
833
|
*/
|
|
883
|
-
|
|
884
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
case 0:
|
|
889
|
-
internalLogger.info("Get basic user info from SSO token");
|
|
890
|
-
return [4 /*yield*/, this.getSSOToken()];
|
|
891
|
-
case 1:
|
|
892
|
-
ssoToken = _a.sent();
|
|
893
|
-
return [2 /*return*/, getUserInfoFromSsoToken(ssoToken.token)];
|
|
894
|
-
}
|
|
895
|
-
});
|
|
834
|
+
getUserInfo() {
|
|
835
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
836
|
+
internalLogger.info("Get basic user info from SSO token");
|
|
837
|
+
const ssoToken = yield this.getSSOToken();
|
|
838
|
+
return getUserInfoFromSsoToken(ssoToken.token);
|
|
896
839
|
});
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
cacheLocation: "sessionStorage",
|
|
916
|
-
},
|
|
917
|
-
};
|
|
918
|
-
this.msalInstance = new PublicClientApplication(msalConfig);
|
|
919
|
-
this.initialized = true;
|
|
920
|
-
return [2 /*return*/];
|
|
921
|
-
}
|
|
922
|
-
});
|
|
840
|
+
}
|
|
841
|
+
init() {
|
|
842
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
843
|
+
const ssoToken = yield this.getSSOToken();
|
|
844
|
+
const info = getTenantIdAndLoginHintFromSsoToken(ssoToken.token);
|
|
845
|
+
this.loginHint = info.loginHint;
|
|
846
|
+
this.tid = info.tid;
|
|
847
|
+
const msalConfig = {
|
|
848
|
+
auth: {
|
|
849
|
+
clientId: this.config.clientId,
|
|
850
|
+
authority: `https://login.microsoftonline.com/${this.tid}`,
|
|
851
|
+
},
|
|
852
|
+
cache: {
|
|
853
|
+
cacheLocation: "sessionStorage",
|
|
854
|
+
},
|
|
855
|
+
};
|
|
856
|
+
this.msalInstance = new PublicClientApplication(msalConfig);
|
|
857
|
+
this.initialized = true;
|
|
923
858
|
});
|
|
924
|
-
}
|
|
859
|
+
}
|
|
925
860
|
/**
|
|
926
861
|
* Get SSO token using teams SDK
|
|
927
862
|
* It will try to get SSO token from memory first, if SSO token doesn't exist or about to expired, then it will using teams SDK to get SSO token
|
|
928
863
|
* @returns SSO token
|
|
929
864
|
*/
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if (_this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
|
|
865
|
+
getSSOToken() {
|
|
866
|
+
return new Promise((resolve, reject) => {
|
|
867
|
+
if (this.ssoToken) {
|
|
868
|
+
if (this.ssoToken.expiresOnTimestamp - Date.now() > tokenRefreshTimeSpanInMillisecond) {
|
|
935
869
|
internalLogger.verbose("Get SSO token from memory cache");
|
|
936
|
-
resolve(
|
|
870
|
+
resolve(this.ssoToken);
|
|
937
871
|
return;
|
|
938
872
|
}
|
|
939
873
|
}
|
|
940
|
-
|
|
941
|
-
microsoftTeams.initialize(
|
|
874
|
+
let initialized = false;
|
|
875
|
+
microsoftTeams.initialize(() => {
|
|
942
876
|
initialized = true;
|
|
943
877
|
microsoftTeams.authentication.getAuthToken({
|
|
944
|
-
successCallback:
|
|
878
|
+
successCallback: (token) => {
|
|
945
879
|
if (!token) {
|
|
946
|
-
|
|
880
|
+
const errorMsg = "Get empty SSO token from Teams";
|
|
947
881
|
internalLogger.error(errorMsg);
|
|
948
882
|
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
949
883
|
return;
|
|
950
884
|
}
|
|
951
|
-
|
|
885
|
+
const tokenObject = parseJwt(token);
|
|
952
886
|
if (tokenObject.ver !== "1.0" && tokenObject.ver !== "2.0") {
|
|
953
|
-
|
|
887
|
+
const errorMsg = "SSO token is not valid with an unknown version: " + tokenObject.ver;
|
|
954
888
|
internalLogger.error(errorMsg);
|
|
955
889
|
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
956
890
|
return;
|
|
957
891
|
}
|
|
958
|
-
|
|
959
|
-
token
|
|
892
|
+
const ssoToken = {
|
|
893
|
+
token,
|
|
960
894
|
expiresOnTimestamp: tokenObject.exp * 1000,
|
|
961
895
|
};
|
|
962
|
-
|
|
896
|
+
this.ssoToken = ssoToken;
|
|
963
897
|
resolve(ssoToken);
|
|
964
898
|
},
|
|
965
|
-
failureCallback:
|
|
966
|
-
|
|
899
|
+
failureCallback: (errMessage) => {
|
|
900
|
+
const errorMsg = "Get SSO token failed with error: " + errMessage;
|
|
967
901
|
internalLogger.error(errorMsg);
|
|
968
902
|
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
969
903
|
},
|
|
@@ -971,22 +905,22 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
971
905
|
});
|
|
972
906
|
});
|
|
973
907
|
// If the code not running in Teams, the initialize callback function would never trigger
|
|
974
|
-
setTimeout(
|
|
908
|
+
setTimeout(() => {
|
|
975
909
|
if (!initialized) {
|
|
976
|
-
|
|
910
|
+
const errorMsg = "Initialize teams sdk timeout, maybe the code is not running inside Teams";
|
|
977
911
|
internalLogger.error(errorMsg);
|
|
978
912
|
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
979
913
|
}
|
|
980
914
|
}, initializeTeamsSdkTimeoutInMillisecond);
|
|
981
915
|
});
|
|
982
|
-
}
|
|
916
|
+
}
|
|
983
917
|
/**
|
|
984
918
|
* Load and validate authentication configuration
|
|
985
919
|
* @returns Authentication configuration
|
|
986
920
|
*/
|
|
987
|
-
|
|
921
|
+
loadAndValidateConfig() {
|
|
988
922
|
internalLogger.verbose("Validate authentication configuration");
|
|
989
|
-
|
|
923
|
+
const config = getAuthenticationConfiguration();
|
|
990
924
|
if (!config) {
|
|
991
925
|
internalLogger.error(ErrorMessage.AuthenticationConfigurationNotExists);
|
|
992
926
|
throw new ErrorWithCode(ErrorMessage.AuthenticationConfigurationNotExists, ErrorCode.InvalidConfiguration);
|
|
@@ -994,43 +928,42 @@ var TeamsUserCredential = /** @class */ (function () {
|
|
|
994
928
|
if (config.initiateLoginEndpoint && config.clientId) {
|
|
995
929
|
return config;
|
|
996
930
|
}
|
|
997
|
-
|
|
931
|
+
const missingValues = [];
|
|
998
932
|
if (!config.initiateLoginEndpoint) {
|
|
999
933
|
missingValues.push("initiateLoginEndpoint");
|
|
1000
934
|
}
|
|
1001
935
|
if (!config.clientId) {
|
|
1002
936
|
missingValues.push("clientId");
|
|
1003
937
|
}
|
|
1004
|
-
|
|
938
|
+
const errorMsg = formatString(ErrorMessage.InvalidConfiguration, missingValues.join(", "), "undefined");
|
|
1005
939
|
internalLogger.error(errorMsg);
|
|
1006
940
|
throw new ErrorWithCode(errorMsg, ErrorCode.InvalidConfiguration);
|
|
1007
|
-
}
|
|
1008
|
-
|
|
941
|
+
}
|
|
942
|
+
setSessionStorage(sessonStorageValues) {
|
|
1009
943
|
try {
|
|
1010
|
-
|
|
1011
|
-
sessionStorageKeys.forEach(
|
|
944
|
+
const sessionStorageKeys = Object.keys(sessonStorageValues);
|
|
945
|
+
sessionStorageKeys.forEach((key) => {
|
|
1012
946
|
sessionStorage.setItem(key, sessonStorageValues[key]);
|
|
1013
947
|
});
|
|
1014
948
|
}
|
|
1015
949
|
catch (error) {
|
|
1016
950
|
// Values in result.sessionStorage can not be set into session storage.
|
|
1017
951
|
// Throw error since this may block user.
|
|
1018
|
-
|
|
952
|
+
const errorMessage = `Failed to set values in session storage. Error: ${error.message}`;
|
|
1019
953
|
internalLogger.error(errorMessage);
|
|
1020
954
|
throw new ErrorWithCode(errorMessage, ErrorCode.InternalError);
|
|
1021
955
|
}
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
}());
|
|
956
|
+
}
|
|
957
|
+
}
|
|
1025
958
|
|
|
1026
959
|
// Copyright (c) Microsoft Corporation.
|
|
1027
|
-
|
|
960
|
+
const defaultScope = "https://graph.microsoft.com/.default";
|
|
1028
961
|
/**
|
|
1029
962
|
* Microsoft Graph auth provider for Teams Framework
|
|
1030
963
|
*
|
|
1031
964
|
* @beta
|
|
1032
965
|
*/
|
|
1033
|
-
|
|
966
|
+
class MsGraphAuthProvider {
|
|
1034
967
|
/**
|
|
1035
968
|
* Constructor of MsGraphAuthProvider.
|
|
1036
969
|
*
|
|
@@ -1043,9 +976,9 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
1043
976
|
*
|
|
1044
977
|
* @beta
|
|
1045
978
|
*/
|
|
1046
|
-
|
|
979
|
+
constructor(credential, scopes) {
|
|
1047
980
|
this.credential = credential;
|
|
1048
|
-
|
|
981
|
+
let scopesStr = defaultScope;
|
|
1049
982
|
if (scopes) {
|
|
1050
983
|
validateScopesType(scopes);
|
|
1051
984
|
scopesStr = typeof scopes === "string" ? scopes : scopes.join(" ");
|
|
@@ -1053,7 +986,7 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
1053
986
|
scopesStr = defaultScope;
|
|
1054
987
|
}
|
|
1055
988
|
}
|
|
1056
|
-
internalLogger.info(
|
|
989
|
+
internalLogger.info(`Create Microsoft Graph Authentication Provider with scopes: '${scopesStr}'`);
|
|
1057
990
|
this.scopes = scopesStr;
|
|
1058
991
|
}
|
|
1059
992
|
/**
|
|
@@ -1068,32 +1001,23 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
1068
1001
|
* @returns Access token from the credential.
|
|
1069
1002
|
*
|
|
1070
1003
|
*/
|
|
1071
|
-
|
|
1072
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
resolve(accessToken.token);
|
|
1084
|
-
}
|
|
1085
|
-
else {
|
|
1086
|
-
var errorMsg = "Graph access token is undefined or empty";
|
|
1087
|
-
internalLogger.error(errorMsg);
|
|
1088
|
-
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
1089
|
-
}
|
|
1090
|
-
})];
|
|
1004
|
+
getAccessToken() {
|
|
1005
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1006
|
+
internalLogger.info(`Get Graph Access token with scopes: '${this.scopes}'`);
|
|
1007
|
+
const accessToken = yield this.credential.getToken(this.scopes);
|
|
1008
|
+
return new Promise((resolve, reject) => {
|
|
1009
|
+
if (accessToken) {
|
|
1010
|
+
resolve(accessToken.token);
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
const errorMsg = "Graph access token is undefined or empty";
|
|
1014
|
+
internalLogger.error(errorMsg);
|
|
1015
|
+
reject(new ErrorWithCode(errorMsg, ErrorCode.InternalError));
|
|
1091
1016
|
}
|
|
1092
1017
|
});
|
|
1093
1018
|
});
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
}());
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1097
1021
|
|
|
1098
1022
|
// Copyright (c) Microsoft Corporation.
|
|
1099
1023
|
/**
|
|
@@ -1149,9 +1073,9 @@ var MsGraphAuthProvider = /** @class */ (function () {
|
|
|
1149
1073
|
*/
|
|
1150
1074
|
function createMicrosoftGraphClient(credential, scopes) {
|
|
1151
1075
|
internalLogger.info("Create Microsoft Graph Client");
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
authProvider
|
|
1076
|
+
const authProvider = new MsGraphAuthProvider(credential, scopes);
|
|
1077
|
+
const graphClient = Client.initWithMiddleware({
|
|
1078
|
+
authProvider,
|
|
1155
1079
|
});
|
|
1156
1080
|
return graphClient;
|
|
1157
1081
|
}
|
|
@@ -1162,8 +1086,8 @@ function createMicrosoftGraphClient(credential, scopes) {
|
|
|
1162
1086
|
* Only works in in server side.
|
|
1163
1087
|
* @beta
|
|
1164
1088
|
*/
|
|
1165
|
-
|
|
1166
|
-
|
|
1089
|
+
class DefaultTediousConnectionConfiguration {
|
|
1090
|
+
constructor() {
|
|
1167
1091
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1168
1092
|
}
|
|
1169
1093
|
/**
|
|
@@ -1172,15 +1096,12 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1172
1096
|
* Only works in in server side.
|
|
1173
1097
|
* @beta
|
|
1174
1098
|
*/
|
|
1175
|
-
|
|
1176
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1177
|
-
|
|
1178
|
-
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1179
|
-
});
|
|
1099
|
+
getConfig(databaseName) {
|
|
1100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1101
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "DefaultTediousConnectionConfiguration"), ErrorCode.RuntimeNotSupported);
|
|
1180
1102
|
});
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
}());
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1184
1105
|
|
|
1185
1106
|
// Copyright (c) Microsoft Corporation.
|
|
1186
1107
|
/**
|
|
@@ -1234,7 +1155,7 @@ var DefaultTediousConnectionConfiguration = /** @class */ (function () {
|
|
|
1234
1155
|
*
|
|
1235
1156
|
* @beta
|
|
1236
1157
|
*/
|
|
1237
|
-
|
|
1158
|
+
class TeamsBotSsoPrompt {
|
|
1238
1159
|
/**
|
|
1239
1160
|
* Constructor of TeamsBotSsoPrompt.
|
|
1240
1161
|
*
|
|
@@ -1246,7 +1167,7 @@ var TeamsBotSsoPrompt = /** @class */ (function () {
|
|
|
1246
1167
|
*
|
|
1247
1168
|
* @beta
|
|
1248
1169
|
*/
|
|
1249
|
-
|
|
1170
|
+
constructor(dialogId, settings) {
|
|
1250
1171
|
this.settings = settings;
|
|
1251
1172
|
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotSsoPrompt"), ErrorCode.RuntimeNotSupported);
|
|
1252
1173
|
}
|
|
@@ -1266,13 +1187,11 @@ var TeamsBotSsoPrompt = /** @class */ (function () {
|
|
|
1266
1187
|
*
|
|
1267
1188
|
* @beta
|
|
1268
1189
|
*/
|
|
1269
|
-
|
|
1270
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1271
|
-
|
|
1272
|
-
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotSsoPrompt"), ErrorCode.RuntimeNotSupported);
|
|
1273
|
-
});
|
|
1190
|
+
beginDialog(dc) {
|
|
1191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1192
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotSsoPrompt"), ErrorCode.RuntimeNotSupported);
|
|
1274
1193
|
});
|
|
1275
|
-
}
|
|
1194
|
+
}
|
|
1276
1195
|
/**
|
|
1277
1196
|
* Called when a prompt dialog is the active dialog and the user replied with a new activity.
|
|
1278
1197
|
*
|
|
@@ -1291,15 +1210,12 @@ var TeamsBotSsoPrompt = /** @class */ (function () {
|
|
|
1291
1210
|
*
|
|
1292
1211
|
* @beta
|
|
1293
1212
|
*/
|
|
1294
|
-
|
|
1295
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1296
|
-
|
|
1297
|
-
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotSsoPrompt"), ErrorCode.RuntimeNotSupported);
|
|
1298
|
-
});
|
|
1213
|
+
continueDialog(dc) {
|
|
1214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1215
|
+
throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotSsoPrompt"), ErrorCode.RuntimeNotSupported);
|
|
1299
1216
|
});
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
}());
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1303
1219
|
|
|
1304
1220
|
export { DefaultTediousConnectionConfiguration, ErrorCode, ErrorWithCode, LogLevel, M365TenantCredential, MsGraphAuthProvider, OnBehalfOfUserCredential, ResourceType, TeamsBotSsoPrompt, TeamsUserCredential, createMicrosoftGraphClient, getAuthenticationConfiguration, getLogLevel, getResourceConfiguration, loadConfiguration, setLogFunction, setLogLevel, setLogger };
|
|
1305
1221
|
//# sourceMappingURL=index.esm5.js.map
|