@microsoft/vscode-azext-azureauth 6.0.0-alpha.2 → 6.0.0-alpha.3

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.
@@ -41,6 +41,7 @@ exports.AzureDevOpsSubscriptionProvider = void 0;
41
41
  exports.createAzureDevOpsSubscriptionProviderFactory = createAzureDevOpsSubscriptionProviderFactory;
42
42
  const azureEnv = __importStar(require("@azure/ms-rest-azure-env")); // This package is so small that it's not worth lazy loading
43
43
  const crypto = __importStar(require("crypto"));
44
+ const configuredAzureEnv_1 = require("../utils/configuredAzureEnv");
44
45
  const isAuthenticationWwwAuthenticateRequest_1 = require("../utils/isAuthenticationWwwAuthenticateRequest");
45
46
  const NotSignedInError_1 = require("../utils/NotSignedInError");
46
47
  const AzureSubscriptionProviderBase_1 = require("./AzureSubscriptionProviderBase");
@@ -90,6 +91,7 @@ class AzureDevOpsSubscriptionProvider extends AzureSubscriptionProviderBase_1.Az
90
91
  {
91
92
  id: 'test-account-id',
92
93
  label: 'test-account',
94
+ environment: new configuredAzureEnv_1.ExtendedEnvironment(azureEnv.Environment.AzureCloud, false),
93
95
  }
94
96
  ]);
95
97
  }
@@ -198,7 +198,13 @@ class AzureSubscriptionProviderBase {
198
198
  const startTime = Date.now();
199
199
  this.log('Fetching accounts...');
200
200
  this.silenceRefreshEvents();
201
- const results = await vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)());
201
+ const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
202
+ const results = (await vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)())).map(account => {
203
+ return {
204
+ ...account,
205
+ environment,
206
+ };
207
+ });
202
208
  if (results.length === 0) {
203
209
  this.log('No accounts found');
204
210
  throw new NotSignedInError_1.NotSignedInError();
@@ -292,7 +298,6 @@ class AzureSubscriptionProviderBase {
292
298
  name: subscription.displayName,
293
299
  subscriptionId: subscription.subscriptionId,
294
300
  /* eslint-enable @typescript-eslint/no-non-null-assertion */
295
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
296
301
  tenantId: subscription.tenantId || tenant.tenantId, // In rare cases, a subscription may be listed but come from a different tenant
297
302
  account: tenant.account,
298
303
  });
@@ -314,11 +319,13 @@ class AzureSubscriptionProviderBase {
314
319
  * @returns A {@link SubscriptionClient}, {@link TokenCredential}, and {@link AzureAuthentication} for the given account+tenant.
315
320
  */
316
321
  async getSubscriptionClient(tenant) {
322
+ // Credential ignores requested scopes and always uses default scopes (managementEndpointUrl),
323
+ // matching the scope used during signIn(). This avoids a refresh token round-trip that can
324
+ // fail when MSAL has stale cache entries for a different scope.
317
325
  const credential = {
318
- getToken: async (scopes, options) => {
326
+ getToken: async (_scopes, options) => {
319
327
  this.silenceRefreshEvents();
320
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
321
- const session = await (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, options?.tenantId || tenant.tenantId, { createIfNone: false, silent: true, account: tenant.account });
328
+ const session = await (0, getSessionFromVSCode_1.getSessionFromVSCode)(undefined, options?.tenantId || tenant.tenantId, { createIfNone: false, silent: true, account: tenant.account });
322
329
  if (!session) {
323
330
  throw new NotSignedInError_1.NotSignedInError();
324
331
  }
@@ -37,6 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  };
38
38
  })();
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.ExtendedEnvironment = void 0;
40
41
  exports.getConfiguredAzureEnv = getConfiguredAzureEnv;
41
42
  exports.setConfiguredAzureEnv = setConfiguredAzureEnv;
42
43
  exports.getConfiguredAuthProviderId = getConfiguredAuthProviderId;
@@ -62,6 +63,7 @@ class ExtendedEnvironment extends azureEnv.Environment {
62
63
  Object.assign(this, parameters);
63
64
  }
64
65
  }
66
+ exports.ExtendedEnvironment = ExtendedEnvironment;
65
67
  /**
66
68
  * Gets the configured Azure environment.
67
69
  *
@@ -1,5 +1,8 @@
1
1
  import type * as vscode from 'vscode';
2
+ import type { ExtendedEnvironment } from '../utils/configuredAzureEnv';
2
3
  /**
3
4
  * A shortcut type for {@link vscode.AuthenticationSessionAccountInformation}
4
5
  */
5
- export type AzureAccount = Readonly<vscode.AuthenticationSessionAccountInformation>;
6
+ export type AzureAccount = Readonly<vscode.AuthenticationSessionAccountInformation> & {
7
+ readonly environment: ExtendedEnvironment;
8
+ };
@@ -4,6 +4,7 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import * as azureEnv from '@azure/ms-rest-azure-env'; // This package is so small that it's not worth lazy loading
6
6
  import * as crypto from 'crypto';
7
+ import { ExtendedEnvironment } from '../utils/configuredAzureEnv';
7
8
  import { isAuthenticationWwwAuthenticateRequest } from '../utils/isAuthenticationWwwAuthenticateRequest';
8
9
  import { NotSignedInError } from '../utils/NotSignedInError';
9
10
  import { AzureSubscriptionProviderBase } from './AzureSubscriptionProviderBase';
@@ -53,6 +54,7 @@ export class AzureDevOpsSubscriptionProvider extends AzureSubscriptionProviderBa
53
54
  {
54
55
  id: 'test-account-id',
55
56
  label: 'test-account',
57
+ environment: new ExtendedEnvironment(azureEnv.Environment.AzureCloud, false),
56
58
  }
57
59
  ]);
58
60
  }
@@ -162,7 +162,13 @@ export class AzureSubscriptionProviderBase {
162
162
  const startTime = Date.now();
163
163
  this.log('Fetching accounts...');
164
164
  this.silenceRefreshEvents();
165
- const results = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
165
+ const environment = getConfiguredAzureEnv();
166
+ const results = (await vscode.authentication.getAccounts(getConfiguredAuthProviderId())).map(account => {
167
+ return {
168
+ ...account,
169
+ environment,
170
+ };
171
+ });
166
172
  if (results.length === 0) {
167
173
  this.log('No accounts found');
168
174
  throw new NotSignedInError();
@@ -256,7 +262,6 @@ export class AzureSubscriptionProviderBase {
256
262
  name: subscription.displayName,
257
263
  subscriptionId: subscription.subscriptionId,
258
264
  /* eslint-enable @typescript-eslint/no-non-null-assertion */
259
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
260
265
  tenantId: subscription.tenantId || tenant.tenantId, // In rare cases, a subscription may be listed but come from a different tenant
261
266
  account: tenant.account,
262
267
  });
@@ -278,11 +283,13 @@ export class AzureSubscriptionProviderBase {
278
283
  * @returns A {@link SubscriptionClient}, {@link TokenCredential}, and {@link AzureAuthentication} for the given account+tenant.
279
284
  */
280
285
  async getSubscriptionClient(tenant) {
286
+ // Credential ignores requested scopes and always uses default scopes (managementEndpointUrl),
287
+ // matching the scope used during signIn(). This avoids a refresh token round-trip that can
288
+ // fail when MSAL has stale cache entries for a different scope.
281
289
  const credential = {
282
- getToken: async (scopes, options) => {
290
+ getToken: async (_scopes, options) => {
283
291
  this.silenceRefreshEvents();
284
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
285
- const session = await getSessionFromVSCode(scopes, options?.tenantId || tenant.tenantId, { createIfNone: false, silent: true, account: tenant.account });
292
+ const session = await getSessionFromVSCode(undefined, options?.tenantId || tenant.tenantId, { createIfNone: false, silent: true, account: tenant.account });
286
293
  if (!session) {
287
294
  throw new NotSignedInError();
288
295
  }
@@ -1,6 +1,6 @@
1
1
  import * as azureEnv from '@azure/ms-rest-azure-env';
2
2
  import * as vscode from 'vscode';
3
- declare class ExtendedEnvironment extends azureEnv.Environment {
3
+ export declare class ExtendedEnvironment extends azureEnv.Environment {
4
4
  readonly isCustomCloud: boolean;
5
5
  constructor(parameters: azureEnv.EnvironmentParameters, isCustomCloud: boolean);
6
6
  }
@@ -24,4 +24,3 @@ export declare function setConfiguredAzureEnv(cloud: 'AzureCloud' | 'ChinaCloud'
24
24
  * @returns The provider ID to use, either `'microsoft'` or `'microsoft-sovereign-cloud'`
25
25
  */
26
26
  export declare function getConfiguredAuthProviderId(): string;
27
- export {};
@@ -14,7 +14,7 @@ var CloudEnvironmentSettingValue;
14
14
  CloudEnvironmentSettingValue["USGovernment"] = "USGovernment";
15
15
  CloudEnvironmentSettingValue["Custom"] = "custom";
16
16
  })(CloudEnvironmentSettingValue || (CloudEnvironmentSettingValue = {}));
17
- class ExtendedEnvironment extends azureEnv.Environment {
17
+ export class ExtendedEnvironment extends azureEnv.Environment {
18
18
  isCustomCloud;
19
19
  constructor(parameters, isCustomCloud) {
20
20
  super(parameters);
@@ -6,4 +6,4 @@ import type { AzureTenant } from '../contracts/AzureTenant';
6
6
  * @param accountOrTenant The account or tenant to screen the label / display name of
7
7
  * @returns The screened label / display name
8
8
  */
9
- export declare function screen(accountOrTenant: AzureAccount | AzureTenant): string;
9
+ export declare function screen(accountOrTenant: Pick<AzureAccount, 'id' | 'label'> | Pick<AzureTenant, 'tenantId' | 'displayName'>): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@microsoft/vscode-azext-azureauth",
3
3
  "author": "Microsoft Corporation",
4
- "version": "6.0.0-alpha.2",
4
+ "version": "6.0.0-alpha.3",
5
5
  "description": "Azure authentication helpers for Visual Studio Code",
6
6
  "tags": [
7
7
  "azure",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@azure/core-auth": "^1.10.1",
52
- "@microsoft/vscode-azext-eng": "1.0.0-alpha.4",
52
+ "@microsoft/vscode-azext-eng": "1.0.0-alpha.13",
53
53
  "@types/node": "22.x",
54
54
  "@types/vscode": "1.106.0"
55
55
  },