@microsoft/vscode-azext-azureauth 2.5.0 → 3.0.1

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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.0.1 - 2024-11-19
4
+ * [#1819](https://github.com/microsoft/vscode-azuretools/pull/1819) Add account parameter to `AzureSubscriptionProvider.isSignedIn()` function to fix a multi-account issue [#1809](https://github.com/microsoft/vscode-azuretools/issues/1809)
5
+ * [#1822](https://github.com/microsoft/vscode-azuretools/pull/1822) Add check in `VSCodeAzureSubscriptionProvider.getTenants()` to fix a multi-account issue [#1809](https://github.com/microsoft/vscode-azuretools/issues/1809)
6
+
7
+ ## 3.0.0 - 2024-09-19
8
+ * [#1789](https://github.com/microsoft/vscode-azuretools/pull/1789) Change `getTenants` to be compatible with the new Azure Resources tenants view. This also includes a possible breaking change where an optional parameter `account` which when passed in `getTenants` will return the tenants associated with that single account. Otherwise `getTenants` will return the tenants for all authenticated accounts.
9
+
10
+ ## 2.5.0 - 2024-08-06
11
+
12
+ * Add `getSessionWithScopes` to get a session that has the proper scoping instead of always the default management plane
13
+
14
+ ## 2.4.1 - 2024-05-15
15
+
16
+ * [#1729](https://github.com/microsoft/vscode-azuretools/pull/1729) Change AzureDevOpsSubscriptionProvider so that it accepts values as arguments
17
+
18
+ ## 2.4.0 - 2024-05-07
19
+
20
+ * [#1723](https://github.com/microsoft/vscode-azuretools/pull/1723) Implementation fo AzureSub provider that leverages federated credentials
21
+
22
+ ## 2.1.0 - 2023-12-13
23
+
24
+ * Use management endpoint for scope by default to fix deploying app service projects with sovereign clouds
25
+
26
+ ## 2.0.0 - 2023-11-20
27
+
28
+ * Switches to use `@azure/arm-resources-subscriptions` instead of `@azure/arm-subscriptions`. Potentially a breaking change so I revved the major version.
29
+ * Fixes an issue where the `endpoint` wasn't set for the subscription client, breaking sovereign clouds
30
+
3
31
  ## 1.4.0 - 2023-11-03
4
32
  * [#1619](https://github.com/microsoft/vscode-azuretools/pull/1619) Make `getSession` synchronous to fix an issue that broke app service deployments
5
33
 
@@ -5,7 +5,7 @@ import type * as vscode from 'vscode';
5
5
  export interface AzureAuthentication {
6
6
  /**
7
7
  * Gets a VS Code authentication session for an Azure subscription.
8
- * Always uses the default scope, `https://management.azure.com/.default/.default.`
8
+ * Always uses the default scope, `https://management.azure.com/.default/` and respects `microsoft-sovereign-cloud.environment` setting.
9
9
  *
10
10
  * @returns A VS Code authentication session or undefined, if none could be obtained.
11
11
  */
@@ -119,6 +119,10 @@ class AzureDevOpsSubscriptionProvider {
119
119
  subscriptionId: subscription.subscriptionId,
120
120
  /* eslint-enable @typescript-eslint/no-non-null-assertion */
121
121
  tenantId,
122
+ account: {
123
+ id: "test-account-id",
124
+ label: "test-account",
125
+ },
122
126
  });
123
127
  }
124
128
  finally {
@@ -1,6 +1,7 @@
1
1
  import type { TokenCredential } from '@azure/core-auth';
2
2
  import type { Environment } from '@azure/ms-rest-azure-env';
3
- import type { AzureAuthentication } from './AzureAuthentication';
3
+ import * as vscode from "vscode";
4
+ import { AzureAuthentication } from './AzureAuthentication';
4
5
  /**
5
6
  * A type representing an Azure subscription ID, not including the tenant ID.
6
7
  */
@@ -41,4 +42,8 @@ export interface AzureSubscription {
41
42
  * The credential for authentication to this subscription. Compatible with Azure track 2 SDKs.
42
43
  */
43
44
  readonly credential: TokenCredential;
45
+ /**
46
+ * The account associated with this subscription.
47
+ */
48
+ readonly account: vscode.AuthenticationSessionAccountInformation;
44
49
  }
@@ -1,6 +1,6 @@
1
+ import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
1
2
  import type * as vscode from 'vscode';
2
3
  import type { AzureSubscription } from './AzureSubscription';
3
- import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
4
4
  /**
5
5
  * An interface for obtaining Azure subscription information
6
6
  */
@@ -9,9 +9,11 @@ export interface AzureSubscriptionProvider {
9
9
  * Gets a list of tenants available to the user.
10
10
  * Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
11
11
  *
12
+ * @param account - Optionally pass in a specific account to get tenants for.
13
+ *
12
14
  * @returns A list of tenants.
13
15
  */
14
- getTenants(): Promise<TenantIdDescription[]>;
16
+ getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<TenantIdDescription[]>;
15
17
  /**
16
18
  * Gets a list of Azure subscriptions available to the user.
17
19
  *
@@ -32,7 +34,7 @@ export interface AzureSubscriptionProvider {
32
34
  *
33
35
  * @returns True if the user is signed in, false otherwise.
34
36
  */
35
- isSignedIn(tenantId?: string): Promise<boolean>;
37
+ isSignedIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
36
38
  /**
37
39
  * Asks the user to sign in or pick an account to use.
38
40
  *
@@ -1,7 +1,7 @@
1
1
  import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
2
2
  import * as vscode from 'vscode';
3
- import type { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
4
- import type { AzureSubscriptionProvider } from './AzureSubscriptionProvider';
3
+ import { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
4
+ import { AzureSubscriptionProvider } from './AzureSubscriptionProvider';
5
5
  /**
6
6
  * A class for obtaining Azure subscription information using VSCode's built-in authentication
7
7
  * provider.
@@ -17,9 +17,11 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
17
17
  * Gets a list of tenants available to the user.
18
18
  * Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
19
19
  *
20
+ * @param account (Optional) A specific account to get tenants for. If not provided, all accounts will be used.
21
+ *
20
22
  * @returns A list of tenants.
21
23
  */
22
- getTenants(): Promise<TenantIdDescription[]>;
24
+ getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<TenantIdDescription[]>;
23
25
  /**
24
26
  * Gets a list of Azure subscriptions available to the user.
25
27
  *
@@ -40,7 +42,7 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
40
42
  *
41
43
  * @returns True if the user is signed in, false otherwise.
42
44
  */
43
- isSignedIn(tenantId?: string): Promise<boolean>;
45
+ isSignedIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
44
46
  /**
45
47
  * Asks the user to sign in or pick an account to use.
46
48
  *
@@ -87,6 +89,7 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
87
89
  * Gets the subscriptions for a given tenant.
88
90
  *
89
91
  * @param tenantId The tenant ID to get subscriptions for.
92
+ * @param account The account to get the subscriptions for.
90
93
  *
91
94
  * @returns The list of subscriptions for the tenant.
92
95
  */
@@ -95,6 +98,7 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
95
98
  * Gets a fully-configured subscription client for a given tenant ID
96
99
  *
97
100
  * @param tenantId (Optional) The tenant ID to get a client for
101
+ * @param account The account that you would like to get the session for
98
102
  *
99
103
  * @returns A client, the credential used by the client, and the authentication function
100
104
  */
@@ -22,8 +22,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.VSCodeAzureSubscriptionProvider = void 0;
24
24
  const vscode = require("vscode");
25
- const NotSignedInError_1 = require("./NotSignedInError");
26
25
  const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
26
+ const NotSignedInError_1 = require("./NotSignedInError");
27
27
  const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
28
28
  const EventDebounce = 5 * 1000; // 5 seconds
29
29
  /**
@@ -71,30 +71,54 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
71
71
  * Gets a list of tenants available to the user.
72
72
  * Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
73
73
  *
74
+ * @param account (Optional) A specific account to get tenants for. If not provided, all accounts will be used.
75
+ *
74
76
  * @returns A list of tenants.
75
77
  */
76
- getTenants() {
77
- var _a, e_1, _b, _c;
78
+ getTenants(account) {
79
+ var _a, e_1, _b, _c, _d, e_2, _e, _f;
78
80
  return __awaiter(this, void 0, void 0, function* () {
79
- const { client } = yield this.getSubscriptionClient();
80
81
  const results = [];
81
82
  try {
82
- for (var _d = true, _e = __asyncValues(client.tenants.list()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
83
- _c = _f.value;
84
- _d = false;
83
+ for (var _g = true, _h = __asyncValues(account ? [account] : yield vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)())), _j; _j = yield _h.next(), _a = _j.done, !_a;) {
84
+ _c = _j.value;
85
+ _g = false;
85
86
  try {
86
- const tenant = _c;
87
- results.push(tenant);
87
+ account = _c;
88
+ // Added check. Without this the getSubscriptionClient function throws the NotSignedInError
89
+ if (yield this.isSignedIn(undefined, account)) {
90
+ const { client } = yield this.getSubscriptionClient(account, undefined, undefined);
91
+ try {
92
+ for (var _k = true, _l = (e_2 = void 0, __asyncValues(client.tenants.list())), _m; _m = yield _l.next(), _d = _m.done, !_d;) {
93
+ _f = _m.value;
94
+ _k = false;
95
+ try {
96
+ const tenant = _f;
97
+ results.push(tenant);
98
+ }
99
+ finally {
100
+ _k = true;
101
+ }
102
+ }
103
+ }
104
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
105
+ finally {
106
+ try {
107
+ if (!_k && !_d && (_e = _l.return)) yield _e.call(_l);
108
+ }
109
+ finally { if (e_2) throw e_2.error; }
110
+ }
111
+ }
88
112
  }
89
113
  finally {
90
- _d = true;
114
+ _g = true;
91
115
  }
92
116
  }
93
117
  }
94
118
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
95
119
  finally {
96
120
  try {
97
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
121
+ if (!_g && !_a && (_b = _h.return)) yield _b.call(_h);
98
122
  }
99
123
  finally { if (e_1) throw e_1.error; }
100
124
  }
@@ -120,20 +144,23 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
120
144
  const results = [];
121
145
  try {
122
146
  this.suppressSignInEvents = true;
123
- // Get the list of tenants
124
- for (const tenant of yield this.getTenants()) {
125
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
- const tenantId = tenant.tenantId;
127
- // If filtering is enabled, and the current tenant is not in that list, then skip it
128
- if (shouldFilterTenants && !tenantIds.includes(tenantId)) {
129
- continue;
130
- }
131
- // If the user is not signed in to this tenant, then skip it
132
- if (!(yield this.isSignedIn(tenantId))) {
133
- continue;
147
+ // Get the list of tenants from each account
148
+ const accounts = yield vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)());
149
+ for (const account of accounts) {
150
+ for (const tenant of yield this.getTenants(account)) {
151
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
152
+ const tenantId = tenant.tenantId;
153
+ // If filtering is enabled, and the current tenant is not in that list, then skip it
154
+ if (shouldFilterTenants && !tenantIds.includes(tenantId)) {
155
+ continue;
156
+ }
157
+ // If the user is not signed in to this tenant, then skip it
158
+ if (!(yield this.isSignedIn(tenantId, account))) {
159
+ continue;
160
+ }
161
+ // For each tenant, get the list of subscriptions
162
+ results.push(...yield this.getSubscriptionsForTenant(tenantId, account));
134
163
  }
135
- // For each tenant, get the list of subscriptions
136
- results.push(...yield this.getSubscriptionsForTenant(tenantId));
137
164
  }
138
165
  }
139
166
  finally {
@@ -154,9 +181,9 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
154
181
  *
155
182
  * @returns True if the user is signed in, false otherwise.
156
183
  */
157
- isSignedIn(tenantId) {
184
+ isSignedIn(tenantId, account) {
158
185
  return __awaiter(this, void 0, void 0, function* () {
159
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
186
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true, account });
160
187
  return !!session;
161
188
  });
162
189
  }
@@ -217,13 +244,14 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
217
244
  * Gets the subscriptions for a given tenant.
218
245
  *
219
246
  * @param tenantId The tenant ID to get subscriptions for.
247
+ * @param account The account to get the subscriptions for.
220
248
  *
221
249
  * @returns The list of subscriptions for the tenant.
222
250
  */
223
- getSubscriptionsForTenant(tenantId) {
224
- var _a, e_2, _b, _c;
251
+ getSubscriptionsForTenant(tenantId, account) {
252
+ var _a, e_3, _b, _c;
225
253
  return __awaiter(this, void 0, void 0, function* () {
226
- const { client, credential, authentication } = yield this.getSubscriptionClient(tenantId);
254
+ const { client, credential, authentication } = yield this.getSubscriptionClient(account, tenantId, undefined);
227
255
  const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
228
256
  const subscriptions = [];
229
257
  try {
@@ -242,6 +270,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
242
270
  subscriptionId: subscription.subscriptionId,
243
271
  /* eslint-enable @typescript-eslint/no-non-null-assertion */
244
272
  tenantId: tenantId,
273
+ account: account
245
274
  });
246
275
  }
247
276
  finally {
@@ -249,12 +278,12 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
249
278
  }
250
279
  }
251
280
  }
252
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
281
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
253
282
  finally {
254
283
  try {
255
284
  if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
256
285
  }
257
- finally { if (e_2) throw e_2.error; }
286
+ finally { if (e_3) throw e_3.error; }
258
287
  }
259
288
  return subscriptions;
260
289
  });
@@ -263,13 +292,14 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
263
292
  * Gets a fully-configured subscription client for a given tenant ID
264
293
  *
265
294
  * @param tenantId (Optional) The tenant ID to get a client for
295
+ * @param account The account that you would like to get the session for
266
296
  *
267
297
  * @returns A client, the credential used by the client, and the authentication function
268
298
  */
269
- getSubscriptionClient(tenantId, scopes) {
299
+ getSubscriptionClient(account, tenantId, scopes) {
270
300
  return __awaiter(this, void 0, void 0, function* () {
271
301
  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 });
302
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true, account });
273
303
  if (!session) {
274
304
  throw new NotSignedInError_1.NotSignedInError();
275
305
  }
@@ -289,7 +319,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
289
319
  authentication: {
290
320
  getSession: () => session,
291
321
  getSessionWithScopes: (scopes) => {
292
- return (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
322
+ return (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true, account });
293
323
  },
294
324
  }
295
325
  };
@@ -14,8 +14,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.getSessionFromVSCode = void 0;
17
- const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
18
17
  const vscode = require("vscode");
18
+ const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
19
19
  function ensureEndingSlash(value) {
20
20
  return value.endsWith('/') ? value : `${value}/`;
21
21
  }
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.5.0",
4
+ "version": "3.0.1",
5
5
  "description": "Azure authentication helpers for Visual Studio Code",
6
6
  "tags": [
7
7
  "azure",
@@ -41,7 +41,7 @@
41
41
  "@types/node-fetch": "2.6.7",
42
42
  "@types/semver": "^7.3.9",
43
43
  "@types/uuid": "^9.0.1",
44
- "@types/vscode": "1.76.0",
44
+ "@types/vscode": "1.93.0",
45
45
  "@typescript-eslint/eslint-plugin": "^5.53.0",
46
46
  "@vscode/test-electron": "^2.3.8",
47
47
  "eslint": "^8.34.0",
@@ -1,6 +0,0 @@
1
- import type { AzureSubscriptionProvider } from "./AzureSubscriptionProvider";
2
- /**
3
- * Prompts user to select from a list of unauthenticated tenants.
4
- * Once selected, requests a new session from VS Code specifially for this tenant.
5
- */
6
- export declare function signInToTenant(subscriptionProvider: AzureSubscriptionProvider): Promise<void>;
@@ -1,57 +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
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.signInToTenant = void 0;
17
- const vscode = require("vscode");
18
- const getUnauthenticatedTenants_1 = require("./utils/getUnauthenticatedTenants");
19
- /**
20
- * Prompts user to select from a list of unauthenticated tenants.
21
- * Once selected, requests a new session from VS Code specifially for this tenant.
22
- */
23
- function signInToTenant(subscriptionProvider) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const tenantId = yield pickTenant(subscriptionProvider);
26
- if (tenantId) {
27
- yield subscriptionProvider.signIn(tenantId);
28
- }
29
- });
30
- }
31
- exports.signInToTenant = signInToTenant;
32
- function pickTenant(subscriptionProvider) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const pick = yield vscode.window.showQuickPick(getPicks(subscriptionProvider), {
35
- placeHolder: 'Select Directory to Sign In To',
36
- matchOnDescription: true,
37
- ignoreFocusOut: true,
38
- });
39
- return pick === null || pick === void 0 ? void 0 : pick.tenant.tenantId;
40
- });
41
- }
42
- function getPicks(subscriptionProvider) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const unauthenticatedTenants = yield (0, getUnauthenticatedTenants_1.getUnauthenticatedTenants)(subscriptionProvider);
45
- const picks = unauthenticatedTenants.map(tenant => {
46
- var _a, _b, _c;
47
- return ({
48
- label: (_a = tenant.displayName) !== null && _a !== void 0 ? _a : '',
49
- description: (_b = tenant.tenantId) !== null && _b !== void 0 ? _b : '',
50
- detail: (_c = tenant.defaultDomain) !== null && _c !== void 0 ? _c : '',
51
- tenant,
52
- });
53
- });
54
- return picks;
55
- });
56
- }
57
- //# sourceMappingURL=signInToTenants.js.map