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