teamsfx-extension
Version:
Create, debug, and deploy Teams apps with Teams Toolkit
77 lines • 4.27 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TeamsfxDebugProvider = void 0;
const appStudioLogin_1 = require("../commonlib/appStudioLogin");
const commonUtils = require("./commonUtils");
class TeamsfxDebugProvider {
resolveDebugConfiguration(folder, debugConfiguration, token) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
if (folder) {
if (!(yield commonUtils.isFxProject(folder.uri.fsPath))) {
return debugConfiguration;
}
if (debugConfiguration.url === undefined) {
return debugConfiguration;
}
const localTeamsAppIdPlaceholder = "${localTeamsAppId}";
const isLocalSideloadingConfiguration = debugConfiguration.url.includes(localTeamsAppIdPlaceholder);
const teamsAppIdPlaceholder = "${teamsAppId}";
const isSideloadingConfiguration = debugConfiguration.url.includes(teamsAppIdPlaceholder);
if (!isLocalSideloadingConfiguration && !isSideloadingConfiguration) {
return debugConfiguration;
}
const teamsAppId = yield commonUtils.getLocalDebugTeamsAppId(isLocalSideloadingConfiguration);
debugConfiguration.url = debugConfiguration.url.replace(isLocalSideloadingConfiguration ? localTeamsAppIdPlaceholder : teamsAppIdPlaceholder, teamsAppId);
const accountHintPlaceholder = "${account-hint}";
const isaccountHintConfiguration = debugConfiguration.url.includes(accountHintPlaceholder);
if (isaccountHintConfiguration) {
let tenantId = undefined, loginHint = undefined;
try {
const tokenObject = (_a = (yield appStudioLogin_1.default.getStatus())) === null || _a === void 0 ? void 0 : _a.accountInfo;
if (tokenObject) {
// user signed in
tenantId = tokenObject.tid;
loginHint = tokenObject.upn;
}
else {
// no signed user
tenantId = commonUtils.getTeamsAppTenantId();
loginHint = "login_your_m365_account"; // a workaround that user has the chance to login
}
}
catch (_b) {
// ignore error
}
if (tenantId && loginHint) {
debugConfiguration.url = debugConfiguration.url.replace(accountHintPlaceholder, `appTenantId=${tenantId}&login_hint=${loginHint}`);
}
else {
debugConfiguration.url = debugConfiguration.url.replace(accountHintPlaceholder, "");
}
}
}
}
catch (err) {
// TODO(kuojianlu): add log and telemetry
}
finally {
return debugConfiguration;
}
});
}
}
exports.TeamsfxDebugProvider = TeamsfxDebugProvider;
//# sourceMappingURL=teamsfxDebugProvider.js.map