@microsoft/vscode-azext-azureauth 2.1.0 → 2.3.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.
@@ -266,36 +266,28 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
266
266
  *
267
267
  * @returns A client, the credential used by the client, and the authentication function
268
268
  */
269
- getSubscriptionClient(tenantId) {
269
+ getSubscriptionClient(tenantId, scopes) {
270
270
  return __awaiter(this, void 0, void 0, function* () {
271
- const initialSession = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(undefined, tenantId, { createIfNone: false, silent: true });
272
- if (!initialSession) {
271
+ const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
272
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
273
+ if (!session) {
273
274
  throw new NotSignedInError_1.NotSignedInError();
274
275
  }
275
276
  const credential = {
276
- getToken: (scopes, _options) => __awaiter(this, void 0, void 0, function* () {
277
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
278
- if (session === null || session === void 0 ? void 0 : session.accessToken) {
279
- return {
280
- token: session.accessToken,
281
- expiresOnTimestamp: 0
282
- };
283
- }
284
- else {
285
- return null;
286
- }
277
+ getToken: () => __awaiter(this, void 0, void 0, function* () {
278
+ return {
279
+ token: session.accessToken,
280
+ expiresOnTimestamp: 0
281
+ };
287
282
  })
288
283
  };
289
284
  const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
290
285
  const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
291
- const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
292
286
  return {
293
287
  client: new armSubs.SubscriptionClient(credential, { endpoint }),
294
288
  credential: credential,
295
289
  authentication: {
296
- getSession: (scopes) => __awaiter(this, void 0, void 0, function* () {
297
- return yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
298
- })
290
+ getSession: () => session
299
291
  }
300
292
  };
301
293
  });
@@ -21,7 +21,7 @@ function ensureEndingSlash(value) {
21
21
  }
22
22
  function getResourceScopes(scopes) {
23
23
  if (scopes === undefined || scopes === "" || scopes.length === 0) {
24
- scopes = ensureEndingSlash((0, configuredAzureEnv_1.getConfiguredAzureEnv)().resourceManagerEndpointUrl);
24
+ scopes = ensureEndingSlash((0, configuredAzureEnv_1.getConfiguredAzureEnv)().managementEndpointUrl);
25
25
  }
26
26
  const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
27
27
  .map((scope) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@microsoft/vscode-azext-azureauth",
3
3
  "author": "Microsoft Corporation",
4
- "version": "2.1.0",
4
+ "version": "2.3.0",
5
5
  "description": "Azure authentication helpers for Visual Studio Code",
6
6
  "tags": [
7
7
  "azure",
@@ -1,4 +0,0 @@
1
- import type { TenantIdDescription } from '@azure/arm-subscriptions';
2
- export interface Tenant extends TenantIdDescription {
3
- isAuthenticated: boolean;
4
- }
package/out/src/Tenant.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=Tenant.js.map
@@ -1,2 +0,0 @@
1
- import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
2
- export declare function signInToTenant(subscriptionProvider: AzureSubscriptionProvider): Promise<void>;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- var __asyncValues = (this && this.__asyncValues) || function (o) {
16
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
- var m = o[Symbol.asyncIterator], i;
18
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
19
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
20
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.signInToTenant = void 0;
24
- const vscode = require("vscode");
25
- function signInToTenant(subscriptionProvider) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const tenantId = yield pickTenant(subscriptionProvider);
28
- if (tenantId) {
29
- yield subscriptionProvider.signIn(tenantId);
30
- }
31
- });
32
- }
33
- exports.signInToTenant = signInToTenant;
34
- function pickTenant(subscriptionProvider) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const pick = yield vscode.window.showQuickPick(getPicks(subscriptionProvider), {
37
- placeHolder: 'Select Directory to Sign In To',
38
- matchOnDescription: true,
39
- ignoreFocusOut: true,
40
- });
41
- return pick === null || pick === void 0 ? void 0 : pick.tenant.tenantId;
42
- });
43
- }
44
- function getPicks(subscriptionProvider) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const unauthenticatedTenants = yield getUnauthenticatedTenants(subscriptionProvider);
47
- const picks = unauthenticatedTenants.map(tenant => {
48
- var _a, _b, _c;
49
- return ({
50
- label: (_a = tenant.displayName) !== null && _a !== void 0 ? _a : '',
51
- description: (_b = tenant.tenantId) !== null && _b !== void 0 ? _b : '',
52
- detail: (_c = tenant.defaultDomain) !== null && _c !== void 0 ? _c : '',
53
- tenant,
54
- });
55
- });
56
- return picks;
57
- });
58
- }
59
- function getUnauthenticatedTenants(subscriptionProvider) {
60
- var _a, e_1, _b, _c;
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const tenants = yield subscriptionProvider.getTenants();
63
- const unauthenticatedTenants = [];
64
- try {
65
- for (var _d = true, tenants_1 = __asyncValues(tenants), tenants_1_1; tenants_1_1 = yield tenants_1.next(), _a = tenants_1_1.done, !_a;) {
66
- _c = tenants_1_1.value;
67
- _d = false;
68
- try {
69
- const tenant = _c;
70
- if (!(yield subscriptionProvider.isSignedIn(tenant.tenantId))) {
71
- unauthenticatedTenants.push(tenant);
72
- }
73
- }
74
- finally {
75
- _d = true;
76
- }
77
- }
78
- }
79
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
80
- finally {
81
- try {
82
- if (!_d && !_a && (_b = tenants_1.return)) yield _b.call(tenants_1);
83
- }
84
- finally { if (e_1) throw e_1.error; }
85
- }
86
- return unauthenticatedTenants;
87
- });
88
- }
89
- //# sourceMappingURL=signInToTenant.js.map