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

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.
@@ -38,6 +38,7 @@ var __importStar = (this && this.__importStar) || (function () {
38
38
  })();
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.AzureSubscriptionProviderBase = void 0;
41
+ const util_1 = require("util");
41
42
  const vscode = __importStar(require("vscode"));
42
43
  const AzureSubscriptionProviderRequestOptions_1 = require("../contracts/AzureSubscriptionProviderRequestOptions");
43
44
  const configuredAzureEnv_1 = require("../utils/configuredAzureEnv");
@@ -114,12 +115,18 @@ class AzureSubscriptionProviderBase {
114
115
  // If silent, suppress with normal timeout
115
116
  this.silenceRefreshEvents();
116
117
  }
117
- const session = await (0, getSessionFromVSCode_1.getSessionFromVSCode)(undefined, tenant?.tenantId, {
118
- account: tenant?.account,
119
- clearSessionPreference: options.clearSessionPreference ?? AzureSubscriptionProviderRequestOptions_1.DefaultSignInOptions.clearSessionPreference,
120
- createIfNone: prompt,
121
- silent: !prompt,
122
- });
118
+ let session;
119
+ try {
120
+ session = await (0, getSessionFromVSCode_1.getSessionFromVSCode)(undefined, tenant?.tenantId, {
121
+ account: tenant?.account,
122
+ clearSessionPreference: options.clearSessionPreference ?? AzureSubscriptionProviderRequestOptions_1.DefaultSignInOptions.clearSessionPreference,
123
+ createIfNone: prompt,
124
+ silent: !prompt,
125
+ });
126
+ }
127
+ catch (err) {
128
+ throw maybeImproveSignInError(err, tenant?.tenantId);
129
+ }
123
130
  if (prompt) {
124
131
  // Interactive sign in can take a while, so silence events for a bit longer
125
132
  this.silenceRefreshEvents();
@@ -165,7 +172,9 @@ class AzureSubscriptionProviderBase {
165
172
  this.logForTenant(tenant, 'Skipping account+tenant because it is not signed in');
166
173
  return;
167
174
  }
168
- throw err;
175
+ // Don't rethrow--skip tenants that fail for other reasons
176
+ // (e.g., locked account) so remaining tenants can still be listed
177
+ this.errorForTenant(tenant, 'Skipping account+tenant due to error', err);
169
178
  }
170
179
  }));
171
180
  }
@@ -175,6 +184,8 @@ class AzureSubscriptionProviderBase {
175
184
  this.logForAccount(account, 'Skipping account because it is not signed in');
176
185
  return;
177
186
  }
187
+ // Log and skip accounts that fail for other reasons (e.g., locked account)
188
+ this.errorForAccount(account, 'Skipping account due to error', err);
178
189
  }
179
190
  }));
180
191
  }
@@ -363,13 +374,37 @@ class AzureSubscriptionProviderBase {
363
374
  };
364
375
  }
365
376
  log(message) {
366
- this.logger?.debug(`[auth] ${message}`);
377
+ this.logger?.info(`[auth] ${message}`);
367
378
  }
368
379
  logForAccount(account, message) {
369
- this.logger?.debug(`[auth] [account: ${(0, screen_1.screen)(account)}] ${message}`);
380
+ this.logger?.info(`[auth] [account: ${(0, screen_1.screen)(account)}] ${message}`);
370
381
  }
371
382
  logForTenant(tenant, message) {
372
- this.logger?.debug(`[auth] [account: ${(0, screen_1.screen)(tenant.account)}] [tenant: ${(0, screen_1.screen)(tenant)}] ${message}`);
383
+ this.logger?.info(`[auth] [account: ${(0, screen_1.screen)(tenant.account)}] [tenant: ${(0, screen_1.screen)(tenant)}] ${message}`);
384
+ }
385
+ warnForAccount(account, message) {
386
+ this.logger?.warn(`[auth] [account: ${(0, screen_1.screen)(account)}] ${message}`);
387
+ }
388
+ warnForTenant(tenant, message) {
389
+ this.logger?.warn(`[auth] [account: ${(0, screen_1.screen)(tenant.account)}] [tenant: ${(0, screen_1.screen)(tenant)}] ${message}`);
390
+ }
391
+ errorForAccount(account, message, err) {
392
+ this.logger?.error(`[auth] [account: ${(0, screen_1.screen)(account)}] ${message}`);
393
+ if (err instanceof Error) {
394
+ this.logger?.error(err);
395
+ }
396
+ else {
397
+ this.logger?.error(`[auth] [account: ${(0, screen_1.screen)(account)}] ${(0, util_1.inspect)(err)}`);
398
+ }
399
+ }
400
+ errorForTenant(tenant, message, err) {
401
+ this.logger?.error(`[auth] [account: ${(0, screen_1.screen)(tenant.account)}] [tenant: ${(0, screen_1.screen)(tenant)}] ${message}`);
402
+ if (err instanceof Error) {
403
+ this.logger?.error(err);
404
+ }
405
+ else {
406
+ this.logger?.error(`[auth] [account: ${(0, screen_1.screen)(tenant.account)}] [tenant: ${(0, screen_1.screen)(tenant)}] ${(0, util_1.inspect)(err)}`);
407
+ }
373
408
  }
374
409
  throwIfCancelled(token) {
375
410
  if (token?.isCancellationRequested) {
@@ -397,4 +432,28 @@ class AzureSubscriptionProviderBase {
397
432
  }
398
433
  }
399
434
  exports.AzureSubscriptionProviderBase = AzureSubscriptionProviderBase;
435
+ /**
436
+ * Inspects an error thrown during sign-in and returns a more user-friendly
437
+ * error when possible (e.g. native broker errors), otherwise returns the
438
+ * original error unchanged.
439
+ */
440
+ function maybeImproveSignInError(err, tenantId) {
441
+ if (!(err instanceof Error)) {
442
+ return err;
443
+ }
444
+ const message = err.message;
445
+ // The native MSAL broker surfaces opaque "platform_broker_error" messages
446
+ // that don't tell the user what went wrong. Re-wrap with actionable text.
447
+ if (message.includes('platform_broker_error')) {
448
+ const tenantHint = tenantId
449
+ ? vscode.l10n.t(' for tenant "{0}"', tenantId)
450
+ : '';
451
+ const improved = new Error(vscode.l10n.t('Sign-in failed{0}. The tenant may have expired or is no longer valid. Please verify the tenant is still active and try again.', tenantHint), { cause: err });
452
+ if (err.stack && improved.stack) {
453
+ improved.stack += `\nCaused by: ${err.stack}`;
454
+ }
455
+ return improved;
456
+ }
457
+ return err;
458
+ }
400
459
  //# sourceMappingURL=AzureSubscriptionProviderBase.js.map
@@ -67,6 +67,10 @@ export declare abstract class AzureSubscriptionProviderBase implements AzureSubs
67
67
  protected log(message: string): void;
68
68
  protected logForAccount(account: AzureAccount, message: string): void;
69
69
  protected logForTenant(tenant: TenantIdAndAccount, message: string): void;
70
+ protected warnForAccount(account: AzureAccount, message: string): void;
71
+ protected warnForTenant(tenant: TenantIdAndAccount, message: string): void;
72
+ protected errorForAccount(account: AzureAccount, message: string, err: unknown): void;
73
+ protected errorForTenant(tenant: TenantIdAndAccount, message: string, err: unknown): void;
70
74
  protected throwIfCancelled(token: vscode.CancellationToken | undefined): void;
71
75
  private timeout;
72
76
  private silenceRefreshEvents;
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ import { inspect } from 'util';
5
6
  import * as vscode from 'vscode';
6
7
  import { DefaultOptions, DefaultSignInOptions } from '../contracts/AzureSubscriptionProviderRequestOptions';
7
8
  import { getConfiguredAuthProviderId, getConfiguredAzureEnv } from '../utils/configuredAzureEnv';
@@ -78,12 +79,18 @@ export class AzureSubscriptionProviderBase {
78
79
  // If silent, suppress with normal timeout
79
80
  this.silenceRefreshEvents();
80
81
  }
81
- const session = await getSessionFromVSCode(undefined, tenant?.tenantId, {
82
- account: tenant?.account,
83
- clearSessionPreference: options.clearSessionPreference ?? DefaultSignInOptions.clearSessionPreference,
84
- createIfNone: prompt,
85
- silent: !prompt,
86
- });
82
+ let session;
83
+ try {
84
+ session = await getSessionFromVSCode(undefined, tenant?.tenantId, {
85
+ account: tenant?.account,
86
+ clearSessionPreference: options.clearSessionPreference ?? DefaultSignInOptions.clearSessionPreference,
87
+ createIfNone: prompt,
88
+ silent: !prompt,
89
+ });
90
+ }
91
+ catch (err) {
92
+ throw maybeImproveSignInError(err, tenant?.tenantId);
93
+ }
87
94
  if (prompt) {
88
95
  // Interactive sign in can take a while, so silence events for a bit longer
89
96
  this.silenceRefreshEvents();
@@ -129,7 +136,9 @@ export class AzureSubscriptionProviderBase {
129
136
  this.logForTenant(tenant, 'Skipping account+tenant because it is not signed in');
130
137
  return;
131
138
  }
132
- throw err;
139
+ // Don't rethrow--skip tenants that fail for other reasons
140
+ // (e.g., locked account) so remaining tenants can still be listed
141
+ this.errorForTenant(tenant, 'Skipping account+tenant due to error', err);
133
142
  }
134
143
  }));
135
144
  }
@@ -139,6 +148,8 @@ export class AzureSubscriptionProviderBase {
139
148
  this.logForAccount(account, 'Skipping account because it is not signed in');
140
149
  return;
141
150
  }
151
+ // Log and skip accounts that fail for other reasons (e.g., locked account)
152
+ this.errorForAccount(account, 'Skipping account due to error', err);
142
153
  }
143
154
  }));
144
155
  }
@@ -327,13 +338,37 @@ export class AzureSubscriptionProviderBase {
327
338
  };
328
339
  }
329
340
  log(message) {
330
- this.logger?.debug(`[auth] ${message}`);
341
+ this.logger?.info(`[auth] ${message}`);
331
342
  }
332
343
  logForAccount(account, message) {
333
- this.logger?.debug(`[auth] [account: ${screen(account)}] ${message}`);
344
+ this.logger?.info(`[auth] [account: ${screen(account)}] ${message}`);
334
345
  }
335
346
  logForTenant(tenant, message) {
336
- this.logger?.debug(`[auth] [account: ${screen(tenant.account)}] [tenant: ${screen(tenant)}] ${message}`);
347
+ this.logger?.info(`[auth] [account: ${screen(tenant.account)}] [tenant: ${screen(tenant)}] ${message}`);
348
+ }
349
+ warnForAccount(account, message) {
350
+ this.logger?.warn(`[auth] [account: ${screen(account)}] ${message}`);
351
+ }
352
+ warnForTenant(tenant, message) {
353
+ this.logger?.warn(`[auth] [account: ${screen(tenant.account)}] [tenant: ${screen(tenant)}] ${message}`);
354
+ }
355
+ errorForAccount(account, message, err) {
356
+ this.logger?.error(`[auth] [account: ${screen(account)}] ${message}`);
357
+ if (err instanceof Error) {
358
+ this.logger?.error(err);
359
+ }
360
+ else {
361
+ this.logger?.error(`[auth] [account: ${screen(account)}] ${inspect(err)}`);
362
+ }
363
+ }
364
+ errorForTenant(tenant, message, err) {
365
+ this.logger?.error(`[auth] [account: ${screen(tenant.account)}] [tenant: ${screen(tenant)}] ${message}`);
366
+ if (err instanceof Error) {
367
+ this.logger?.error(err);
368
+ }
369
+ else {
370
+ this.logger?.error(`[auth] [account: ${screen(tenant.account)}] [tenant: ${screen(tenant)}] ${inspect(err)}`);
371
+ }
337
372
  }
338
373
  throwIfCancelled(token) {
339
374
  if (token?.isCancellationRequested) {
@@ -360,4 +395,28 @@ export class AzureSubscriptionProviderBase {
360
395
  throw err;
361
396
  }
362
397
  }
398
+ /**
399
+ * Inspects an error thrown during sign-in and returns a more user-friendly
400
+ * error when possible (e.g. native broker errors), otherwise returns the
401
+ * original error unchanged.
402
+ */
403
+ function maybeImproveSignInError(err, tenantId) {
404
+ if (!(err instanceof Error)) {
405
+ return err;
406
+ }
407
+ const message = err.message;
408
+ // The native MSAL broker surfaces opaque "platform_broker_error" messages
409
+ // that don't tell the user what went wrong. Re-wrap with actionable text.
410
+ if (message.includes('platform_broker_error')) {
411
+ const tenantHint = tenantId
412
+ ? vscode.l10n.t(' for tenant "{0}"', tenantId)
413
+ : '';
414
+ const improved = new Error(vscode.l10n.t('Sign-in failed{0}. The tenant may have expired or is no longer valid. Please verify the tenant is still active and try again.', tenantHint), { cause: err });
415
+ if (err.stack && improved.stack) {
416
+ improved.stack += `\nCaused by: ${err.stack}`;
417
+ }
418
+ return improved;
419
+ }
420
+ return err;
421
+ }
363
422
  //# sourceMappingURL=AzureSubscriptionProviderBase.js.map
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.3",
4
+ "version": "6.0.0-alpha.5",
5
5
  "description": "Azure authentication helpers for Visual Studio Code",
6
6
  "tags": [
7
7
  "azure",