@microsoft/vscode-azext-azureauth 4.2.2 → 5.0.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.
Files changed (59) hide show
  1. package/{out → dist/cjs}/src/AzureAuthentication.d.ts +2 -2
  2. package/dist/cjs/src/AzureDevOpsSubscriptionProvider.js +216 -0
  3. package/dist/cjs/src/NotSignedInError.js +63 -0
  4. package/dist/cjs/src/VSCodeAzureSubscriptionProvider.js +342 -0
  5. package/{out → dist/cjs}/src/getSessionFromVSCode.d.ts +3 -3
  6. package/dist/cjs/src/getSessionFromVSCode.js +108 -0
  7. package/dist/cjs/src/index.d.ts +56 -0
  8. package/{out → dist/cjs}/src/index.js +1 -1
  9. package/dist/cjs/src/signInToTenant.js +79 -0
  10. package/dist/cjs/src/utils/configuredAzureEnv.js +128 -0
  11. package/dist/cjs/src/utils/getUnauthenticatedTenants.js +21 -0
  12. package/dist/esm/src/AzureAuthentication.d.ts +21 -0
  13. package/dist/esm/src/AzureAuthentication.js +6 -0
  14. package/dist/esm/src/AzureDevOpsSubscriptionProvider.d.ts +68 -0
  15. package/dist/esm/src/AzureDevOpsSubscriptionProvider.js +211 -0
  16. package/dist/esm/src/AzureSubscription.d.ts +49 -0
  17. package/dist/esm/src/AzureSubscription.js +6 -0
  18. package/dist/esm/src/AzureSubscriptionProvider.d.ts +82 -0
  19. package/dist/esm/src/AzureSubscriptionProvider.js +6 -0
  20. package/dist/esm/src/AzureTenant.d.ts +5 -0
  21. package/dist/esm/src/AzureTenant.js +6 -0
  22. package/dist/esm/src/NotSignedInError.d.ts +15 -0
  23. package/{out → dist/esm}/src/NotSignedInError.js +4 -9
  24. package/dist/esm/src/VSCodeAzureSubscriptionProvider.d.ts +117 -0
  25. package/dist/esm/src/VSCodeAzureSubscriptionProvider.js +305 -0
  26. package/dist/esm/src/getSessionFromVSCode.d.ts +13 -0
  27. package/dist/esm/src/getSessionFromVSCode.js +72 -0
  28. package/dist/esm/src/index.d.ts +56 -0
  29. package/{out/src/index.d.ts → dist/esm/src/index.js} +6 -1
  30. package/dist/esm/src/signInToTenant.d.ts +6 -0
  31. package/dist/esm/src/signInToTenant.js +43 -0
  32. package/dist/esm/src/utils/configuredAzureEnv.d.ts +24 -0
  33. package/dist/esm/src/utils/configuredAzureEnv.js +90 -0
  34. package/dist/esm/src/utils/getUnauthenticatedTenants.d.ts +6 -0
  35. package/dist/esm/src/utils/getUnauthenticatedTenants.js +18 -0
  36. package/dist/esm/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +2 -0
  37. package/dist/esm/src/utils/isAuthenticationWwwAuthenticateRequest.js +12 -0
  38. package/package.json +13 -12
  39. package/out/src/AzureDevOpsSubscriptionProvider.js +0 -252
  40. package/out/src/VSCodeAzureSubscriptionProvider.js +0 -384
  41. package/out/src/getSessionFromVSCode.js +0 -76
  42. package/out/src/signInToTenant.js +0 -64
  43. package/out/src/utils/configuredAzureEnv.js +0 -94
  44. package/out/src/utils/getUnauthenticatedTenants.js +0 -52
  45. /package/{out → dist/cjs}/src/AzureAuthentication.js +0 -0
  46. /package/{out → dist/cjs}/src/AzureDevOpsSubscriptionProvider.d.ts +0 -0
  47. /package/{out → dist/cjs}/src/AzureSubscription.d.ts +0 -0
  48. /package/{out → dist/cjs}/src/AzureSubscription.js +0 -0
  49. /package/{out → dist/cjs}/src/AzureSubscriptionProvider.d.ts +0 -0
  50. /package/{out → dist/cjs}/src/AzureSubscriptionProvider.js +0 -0
  51. /package/{out → dist/cjs}/src/AzureTenant.d.ts +0 -0
  52. /package/{out → dist/cjs}/src/AzureTenant.js +0 -0
  53. /package/{out → dist/cjs}/src/NotSignedInError.d.ts +0 -0
  54. /package/{out → dist/cjs}/src/VSCodeAzureSubscriptionProvider.d.ts +0 -0
  55. /package/{out → dist/cjs}/src/signInToTenant.d.ts +0 -0
  56. /package/{out → dist/cjs}/src/utils/configuredAzureEnv.d.ts +0 -0
  57. /package/{out → dist/cjs}/src/utils/getUnauthenticatedTenants.d.ts +0 -0
  58. /package/{out → dist/cjs}/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +0 -0
  59. /package/{out → dist/cjs}/src/utils/isAuthenticationWwwAuthenticateRequest.js +0 -0
@@ -1,384 +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.VSCodeAzureSubscriptionProvider = void 0;
24
- const vscode = require("vscode");
25
- const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
26
- const NotSignedInError_1 = require("./NotSignedInError");
27
- const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
28
- const isAuthenticationWwwAuthenticateRequest_1 = require("./utils/isAuthenticationWwwAuthenticateRequest");
29
- const EventDebounce = 5 * 1000; // 5 seconds
30
- /**
31
- * A class for obtaining Azure subscription information using VSCode's built-in authentication
32
- * provider.
33
- */
34
- class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
35
- // So that customers can easily share logs, try to only log PII using trace level
36
- constructor(logger) {
37
- const disposable = vscode.authentication.onDidChangeSessions((e) => __awaiter(this, void 0, void 0, function* () {
38
- // Ignore any sign in that isn't for the configured auth provider
39
- if (e.provider.id !== (0, configuredAzureEnv_1.getConfiguredAuthProviderId)()) {
40
- return;
41
- }
42
- if (yield this.isSignedIn()) {
43
- if (!this.suppressSignInEvents && Date.now() > this.lastSignInEventFired + EventDebounce) {
44
- this.lastSignInEventFired = Date.now();
45
- this.onDidSignInEmitter.fire();
46
- }
47
- }
48
- else if (Date.now() > this.lastSignOutEventFired + EventDebounce) {
49
- this.lastSignOutEventFired = Date.now();
50
- this.onDidSignOutEmitter.fire();
51
- }
52
- }));
53
- super(() => {
54
- this.onDidSignInEmitter.dispose();
55
- this.onDidSignOutEmitter.dispose();
56
- disposable.dispose();
57
- });
58
- this.logger = logger;
59
- this.onDidSignInEmitter = new vscode.EventEmitter();
60
- this.lastSignInEventFired = 0;
61
- this.suppressSignInEvents = false;
62
- this.onDidSignOutEmitter = new vscode.EventEmitter();
63
- this.lastSignOutEventFired = 0;
64
- /**
65
- * An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
66
- */
67
- this.onDidSignIn = this.onDidSignInEmitter.event;
68
- /**
69
- * An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
70
- */
71
- this.onDidSignOut = this.onDidSignOutEmitter.event;
72
- }
73
- /**
74
- * Gets a list of tenants available to the user.
75
- * Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
76
- *
77
- * @param account (Optional) A specific account to get tenants for. If not provided, all accounts will be used.
78
- *
79
- * @returns A list of tenants.
80
- */
81
- getTenants(account) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- var _a, e_1, _b, _c, _d, e_2, _e, _f;
84
- var _g;
85
- const startTimeMs = Date.now();
86
- const results = [];
87
- try {
88
- for (var _h = true, _j = __asyncValues(account ? [account] : yield vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)())), _k; _k = yield _j.next(), _a = _k.done, !_a; _h = true) {
89
- _c = _k.value;
90
- _h = false;
91
- account = _c;
92
- // Added check. Without this the getSubscriptionClient function throws the NotSignedInError
93
- if (yield this.isSignedIn(undefined, account)) {
94
- const { client } = yield this.getSubscriptionClient(account, undefined, undefined);
95
- try {
96
- for (var _l = true, _m = (e_2 = void 0, __asyncValues(client.tenants.list())), _o; _o = yield _m.next(), _d = _o.done, !_d; _l = true) {
97
- _f = _o.value;
98
- _l = false;
99
- const tenant = _f;
100
- results.push(Object.assign(Object.assign({}, tenant), { account }));
101
- }
102
- }
103
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
104
- finally {
105
- try {
106
- if (!_l && !_d && (_e = _m.return)) yield _e.call(_m);
107
- }
108
- finally { if (e_2) throw e_2.error; }
109
- }
110
- }
111
- }
112
- }
113
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
114
- finally {
115
- try {
116
- if (!_h && !_a && (_b = _j.return)) yield _b.call(_j);
117
- }
118
- finally { if (e_1) throw e_1.error; }
119
- }
120
- const endTimeMs = Date.now();
121
- (_g = this.logger) === null || _g === void 0 ? void 0 : _g.debug(`auth: Got ${results.length} tenants for account "${account === null || account === void 0 ? void 0 : account.label}" in ${endTimeMs - startTimeMs}ms`);
122
- return results;
123
- });
124
- }
125
- /**
126
- * Gets a list of Azure subscriptions available to the user.
127
- *
128
- * @param filter - Whether to filter the list returned. When:
129
- * - `true`: according to the list returned by `getTenantFilters()` and `getSubscriptionFilters()`.
130
- * - `false`: return all subscriptions.
131
- * - `GetSubscriptionsFilter`: according to the values in the filter.
132
- *
133
- * Optional, default true.
134
- *
135
- * @returns A list of Azure subscriptions. The list is sorted by subscription name.
136
- * The list can contain duplicate subscriptions if they come from different accounts.
137
- *
138
- * @throws A {@link NotSignedInError} If the user is not signed in to Azure.
139
- * Use {@link isSignedIn} and/or {@link signIn} before this method to ensure
140
- * the user is signed in.
141
- */
142
- getSubscriptions() {
143
- return __awaiter(this, arguments, void 0, function* (filter = true) {
144
- var _a, _b;
145
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug('auth: Loading subscriptions...');
146
- const startTime = Date.now();
147
- const configuredTenantFilter = yield this.getTenantFilters();
148
- const tenantIdsToFilterBy =
149
- // Only filter by the tenant ID option if it is provided
150
- (typeof filter === 'object' && filter.tenantId ? [filter.tenantId] :
151
- // Only filter by the configured filter if `filter` is true AND there are tenants in the configured filter
152
- filter === true && configuredTenantFilter.length > 0 ? configuredTenantFilter :
153
- undefined);
154
- const allSubscriptions = [];
155
- let accountCount; // only used for logging
156
- try {
157
- this.suppressSignInEvents = true;
158
- // Get the list of tenants from each account (filtered or all)
159
- const accounts = typeof filter === 'object' && filter.account ? [filter.account] : yield vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)());
160
- accountCount = accounts.length;
161
- for (const account of accounts) {
162
- for (const tenant of yield this.getTenants(account)) {
163
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
164
- const tenantId = tenant.tenantId;
165
- if ((tenantIdsToFilterBy === null || tenantIdsToFilterBy === void 0 ? void 0 : tenantIdsToFilterBy.includes(tenantId)) === false) {
166
- continue;
167
- }
168
- // For each tenant, get the list of subscriptions
169
- allSubscriptions.push(...yield this.getSubscriptionsForTenant(account, tenantId));
170
- }
171
- // list subscriptions for the home tenant
172
- allSubscriptions.push(...yield this.getSubscriptionsForTenant(account));
173
- }
174
- }
175
- finally {
176
- this.suppressSignInEvents = false;
177
- }
178
- // It's possible that by listing subscriptions in all tenants and the "home" tenant there could be duplicate subscriptions
179
- // Thus, we remove duplicate subscriptions. However, if multiple accounts have the same subscription, we keep them.
180
- const subscriptionMap = new Map();
181
- allSubscriptions.forEach(sub => subscriptionMap.set(`${sub.account.id}/${sub.subscriptionId}`, sub));
182
- const uniqueSubscriptions = Array.from(subscriptionMap.values());
183
- const endTime = Date.now();
184
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug(`auth: Got ${uniqueSubscriptions.length} subscriptions from ${accountCount} accounts in ${endTime - startTime}ms`);
185
- const sortSubscriptions = (subscriptions) => subscriptions.sort((a, b) => a.name.localeCompare(b.name));
186
- const subscriptionIds = yield this.getSubscriptionFilters();
187
- if (filter === true && !!subscriptionIds.length) { // If the list is empty it is treated as "no filter"
188
- return sortSubscriptions(uniqueSubscriptions.filter(sub => subscriptionIds.includes(sub.subscriptionId)));
189
- }
190
- return sortSubscriptions(uniqueSubscriptions);
191
- });
192
- }
193
- /**
194
- * Checks to see if a user is signed in.
195
- *
196
- * @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
197
- * @param account (Optional) Provide to check if a user is signed in to a specific account.
198
- *
199
- * @returns True if the user is signed in, false otherwise.
200
- *
201
- * If no tenant or account is provided, then
202
- * checks all accounts for a session.
203
- */
204
- isSignedIn(tenantId, account) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- var _a, _b;
207
- function silentlyCheckForSession(tenantId, account) {
208
- return __awaiter(this, void 0, void 0, function* () {
209
- return !!(yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true, account }));
210
- });
211
- }
212
- const innerIsSignedIn = () => __awaiter(this, void 0, void 0, function* () {
213
- // If no tenant or account is provided, then check all accounts for a session
214
- if (!account && !tenantId) {
215
- const accounts = yield vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)());
216
- if (accounts.length === 0) {
217
- return false;
218
- }
219
- for (const account of accounts) {
220
- if (yield silentlyCheckForSession(tenantId, account)) {
221
- // If any account has a session, then return true because the user is signed in
222
- return true;
223
- }
224
- }
225
- }
226
- return silentlyCheckForSession(tenantId, account);
227
- });
228
- const result = yield innerIsSignedIn();
229
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`auth: isSignedIn returned ${result} (account="${(_b = account === null || account === void 0 ? void 0 : account.label) !== null && _b !== void 0 ? _b : 'none'}") (tenantId="${tenantId !== null && tenantId !== void 0 ? tenantId : 'none'}")`);
230
- return result;
231
- });
232
- }
233
- /**
234
- * Asks the user to sign in or pick an account to use.
235
- *
236
- * @param tenantId (Optional) Provide to sign in to a specific tenant.
237
- * @param account (Optional) Provide to sign in to a specific account.
238
- *
239
- * @returns True if the user is signed in, false otherwise.
240
- */
241
- signIn(tenantId, account) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- var _a, _b;
244
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`auth: Signing in (account="${(_b = account === null || account === void 0 ? void 0 : account.label) !== null && _b !== void 0 ? _b : 'none'}") (tenantId="${tenantId !== null && tenantId !== void 0 ? tenantId : 'none'}")`);
245
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, {
246
- createIfNone: true,
247
- // If no account is provided, then clear the session preference which tells VS Code to show the account picker
248
- clearSessionPreference: !account,
249
- account,
250
- });
251
- return !!session;
252
- });
253
- }
254
- /**
255
- * Signs the user out
256
- *
257
- * @deprecated Not currently supported by VS Code auth providers
258
- */
259
- signOut() {
260
- throw new Error(vscode.l10n.t('Signing out programmatically is not supported. You must sign out by selecting the account in the Accounts menu and choosing Sign Out.'));
261
- }
262
- /**
263
- * Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
264
- * override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
265
- * and/or `getTenantFilters()` overridden.
266
- *
267
- * If no values are returned by `getTenantFilters()`, then all tenants will be scanned for subscriptions.
268
- *
269
- * @returns A list of tenant IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
270
- */
271
- getTenantFilters() {
272
- return __awaiter(this, void 0, void 0, function* () {
273
- const config = vscode.workspace.getConfiguration('azureResourceGroups');
274
- const fullSubscriptionIds = config.get('selectedSubscriptions', []);
275
- return fullSubscriptionIds.map(id => id.split('/')[0]);
276
- });
277
- }
278
- /**
279
- * Gets the subscription filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
280
- * override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
281
- * and/or `getTenantFilters()` overridden.
282
- *
283
- * If no values are returned by `getSubscriptionFilters()`, then all subscriptions will be returned.
284
- *
285
- * @returns A list of subscription IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
286
- */
287
- getSubscriptionFilters() {
288
- return __awaiter(this, void 0, void 0, function* () {
289
- const config = vscode.workspace.getConfiguration('azureResourceGroups');
290
- const fullSubscriptionIds = config.get('selectedSubscriptions', []);
291
- return fullSubscriptionIds.map(id => id.split('/')[1]);
292
- });
293
- }
294
- /**
295
- * Gets the subscriptions for a given tenant.
296
- *
297
- * @param tenantId The tenant ID to get subscriptions for.
298
- * @param account The account to get the subscriptions for.
299
- *
300
- * @returns The list of subscriptions for the tenant.
301
- */
302
- getSubscriptionsForTenant(account, tenantId) {
303
- return __awaiter(this, void 0, void 0, function* () {
304
- var _a, e_3, _b, _c;
305
- // If the user is not signed in to this tenant or account, then return an empty list
306
- // This is to prevent the NotSignedInError from being thrown in getSubscriptionClient
307
- if (!(yield this.isSignedIn(tenantId, account))) {
308
- return [];
309
- }
310
- const { client, credential, authentication } = yield this.getSubscriptionClient(account, tenantId, undefined);
311
- const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
312
- const subscriptions = [];
313
- try {
314
- for (var _d = true, _e = __asyncValues(client.subscriptions.list()), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
315
- _c = _f.value;
316
- _d = false;
317
- const subscription = _c;
318
- subscriptions.push({
319
- authentication: authentication,
320
- environment: environment,
321
- credential: credential,
322
- isCustomCloud: environment.isCustomCloud,
323
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
324
- name: subscription.displayName,
325
- subscriptionId: subscription.subscriptionId,
326
- tenantId: tenantId !== null && tenantId !== void 0 ? tenantId : subscription.tenantId,
327
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
328
- account: account
329
- });
330
- }
331
- }
332
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
333
- finally {
334
- try {
335
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
336
- }
337
- finally { if (e_3) throw e_3.error; }
338
- }
339
- return subscriptions;
340
- });
341
- }
342
- /**
343
- * Gets a fully-configured subscription client for a given tenant ID
344
- *
345
- * @param tenantId (Optional) The tenant ID to get a client for
346
- * @param account The account that you would like to get the session for
347
- *
348
- * @returns A client, the credential used by the client, and the authentication function
349
- */
350
- getSubscriptionClient(account, tenantId, scopes) {
351
- return __awaiter(this, void 0, void 0, function* () {
352
- const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
353
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true, account });
354
- if (!session) {
355
- throw new NotSignedInError_1.NotSignedInError();
356
- }
357
- const credential = {
358
- getToken: () => __awaiter(this, void 0, void 0, function* () {
359
- return {
360
- token: session.accessToken,
361
- expiresOnTimestamp: 0
362
- };
363
- })
364
- };
365
- const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
366
- const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
367
- return {
368
- client: new armSubs.SubscriptionClient(credential, { endpoint }),
369
- credential: credential,
370
- authentication: {
371
- getSession: () => session,
372
- getSessionWithScopes: (scopes) => {
373
- // in order to handle a challenge, we must enable createIfNone so
374
- // that we can prompt the user to step-up their session with MFA
375
- // otherwise, never prompt the user
376
- return (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, Object.assign(Object.assign({}, ((0, isAuthenticationWwwAuthenticateRequest_1.isAuthenticationWwwAuthenticateRequest)(scopes) ? { createIfNone: true } : { silent: true })), { account }));
377
- },
378
- }
379
- };
380
- });
381
- }
382
- }
383
- exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
384
- //# sourceMappingURL=VSCodeAzureSubscriptionProvider.js.map
@@ -1,76 +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.getSessionFromVSCode = getSessionFromVSCode;
17
- const vscode = require("vscode");
18
- const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
19
- const isAuthenticationWwwAuthenticateRequest_1 = require("./utils/isAuthenticationWwwAuthenticateRequest");
20
- function ensureEndingSlash(value) {
21
- return value.endsWith('/') ? value : `${value}/`;
22
- }
23
- function getResourceScopes(scopes) {
24
- if (scopes === undefined || scopes === "" || scopes.length === 0) {
25
- scopes = ensureEndingSlash((0, configuredAzureEnv_1.getConfiguredAzureEnv)().managementEndpointUrl);
26
- }
27
- const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
28
- .map((scope) => {
29
- if (scope.endsWith('.default')) {
30
- return scope;
31
- }
32
- else {
33
- return `${scope}.default`;
34
- }
35
- });
36
- return Array.from(new Set(arrScopes));
37
- }
38
- function addTenantIdScope(scopes, tenantId) {
39
- const scopeSet = new Set(scopes);
40
- scopeSet.add(`VSCODE_TENANT:${tenantId}`);
41
- return Array.from(scopeSet);
42
- }
43
- function getScopes(scopes, tenantId) {
44
- let scopeArr = getResourceScopes(scopes);
45
- if (tenantId) {
46
- scopeArr = addTenantIdScope(scopeArr, tenantId);
47
- }
48
- return scopeArr;
49
- }
50
- /**
51
- * Deconstructs and rebuilds the scopes arg in order to use the above utils to modify the scopes array.
52
- * And then returns the proper type to pass directly to vscode.authentication.getSession
53
- */
54
- function formScopesArg(scopes, tenantId) {
55
- var _a, _b, _c, _d;
56
- const initialScopeList = typeof scopes === 'string' ? [scopes] : Array.isArray(scopes) ? scopes : Array.from((_b = (_a = scopes === null || scopes === void 0 ? void 0 : scopes.fallbackScopes) !== null && _a !== void 0 ? _a : scopes === null || scopes === void 0 ? void 0 : scopes.scopes) !== null && _b !== void 0 ? _b : []);
57
- const scopeList = getScopes(initialScopeList, tenantId);
58
- return (0, isAuthenticationWwwAuthenticateRequest_1.isAuthenticationWwwAuthenticateRequest)(scopes) ? { scopes: scopeList, fallbackScopes: scopeList, challenge: (_c = scopes.wwwAuthenticate) !== null && _c !== void 0 ? _c : scopes.challenge, wwwAuthenticate: (_d = scopes.wwwAuthenticate) !== null && _d !== void 0 ? _d : scopes.challenge } : scopeList;
59
- }
60
- /**
61
- * Wraps {@link vscode.authentication.getSession} and handles:
62
- * * Passing the configured auth provider id
63
- * * Getting the list of scopes, adding the tenant id to the scope list if needed
64
- *
65
- * @param scopes - top-level resource scopes (e.g. http://management.azure.com, http://storage.azure.com) or .default scopes. All resources/scopes will be normalized to the `.default` scope for each resource.
66
- * Use `vscode.AuthenticationWwwAuthenticateRequest` if you need to pass in a challenge (WWW-Authenticate header). Note: Use of `vscode.AuthenticationWwwAuthenticateRequest` requires VS Code 1.104 or newer.
67
- * @param tenantId - (Optional) The tenant ID, will be added to the scopes
68
- * @param options - see {@link vscode.AuthenticationGetSessionOptions}
69
- * @returns An authentication session if available, or undefined if there are no sessions
70
- */
71
- function getSessionFromVSCode(scopes, tenantId, options) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- return yield vscode.authentication.getSession((0, configuredAzureEnv_1.getConfiguredAuthProviderId)(), formScopesArg(scopes, tenantId), options);
74
- });
75
- }
76
- //# sourceMappingURL=getSessionFromVSCode.js.map
@@ -1,64 +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 = signInToTenant;
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
- function pickTenant(subscriptionProvider) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const pick = yield vscode.window.showQuickPick(getPicks(subscriptionProvider), {
34
- placeHolder: 'Select a Tenant (Directory) to Sign In To', // TODO: localize
35
- matchOnDescription: true, // allow searching by tenantId
36
- ignoreFocusOut: true,
37
- });
38
- return pick === null || pick === void 0 ? void 0 : pick.tenant.tenantId;
39
- });
40
- }
41
- function getPicks(subscriptionProvider) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const unauthenticatedTenants = yield (0, getUnauthenticatedTenants_1.getUnauthenticatedTenants)(subscriptionProvider);
44
- const duplicateTenants = new Set(unauthenticatedTenants
45
- .filter((tenant, index, self) => index !== self.findIndex(t => t.tenantId === tenant.tenantId))
46
- .map(tenant => tenant.tenantId));
47
- const isDuplicate = (tenantId) => duplicateTenants.has(tenantId);
48
- const picks = unauthenticatedTenants
49
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
50
- .sort((a, b) => (a.displayName).localeCompare(b.displayName))
51
- .map(tenant => {
52
- var _a, _b;
53
- return ({
54
- label: (_a = tenant.displayName) !== null && _a !== void 0 ? _a : '',
55
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
56
- description: `${tenant.tenantId}${isDuplicate(tenant.tenantId) ? ` (${tenant.account.label})` : ''}`,
57
- detail: (_b = tenant.defaultDomain) !== null && _b !== void 0 ? _b : '',
58
- tenant,
59
- });
60
- });
61
- return picks;
62
- });
63
- }
64
- //# sourceMappingURL=signInToTenant.js.map
@@ -1,94 +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.getConfiguredAzureEnv = getConfiguredAzureEnv;
17
- exports.setConfiguredAzureEnv = setConfiguredAzureEnv;
18
- exports.getConfiguredAuthProviderId = getConfiguredAuthProviderId;
19
- const azureEnv = require("@azure/ms-rest-azure-env"); // This package is so small that it's not worth lazy loading
20
- const vscode = require("vscode");
21
- // These strings come from https://github.com/microsoft/vscode/blob/eac16e9b63a11885b538db3e0b533a02a2fb8143/extensions/microsoft-authentication/package.json#L40-L99
22
- const CustomCloudConfigurationSection = 'microsoft-sovereign-cloud';
23
- const CloudEnvironmentSettingName = 'environment';
24
- const CustomEnvironmentSettingName = 'customEnvironment';
25
- var CloudEnvironmentSettingValue;
26
- (function (CloudEnvironmentSettingValue) {
27
- CloudEnvironmentSettingValue["ChinaCloud"] = "ChinaCloud";
28
- CloudEnvironmentSettingValue["USGovernment"] = "USGovernment";
29
- CloudEnvironmentSettingValue["Custom"] = "custom";
30
- })(CloudEnvironmentSettingValue || (CloudEnvironmentSettingValue = {}));
31
- /**
32
- * Gets the configured Azure environment.
33
- *
34
- * @returns The configured Azure environment from the settings in the built-in authentication provider extension
35
- */
36
- function getConfiguredAzureEnv() {
37
- const authProviderConfig = vscode.workspace.getConfiguration(CustomCloudConfigurationSection);
38
- const environmentSettingValue = authProviderConfig.get(CloudEnvironmentSettingName);
39
- if (environmentSettingValue === CloudEnvironmentSettingValue.ChinaCloud) {
40
- return Object.assign(Object.assign({}, azureEnv.Environment.ChinaCloud), { isCustomCloud: false });
41
- }
42
- else if (environmentSettingValue === CloudEnvironmentSettingValue.USGovernment) {
43
- return Object.assign(Object.assign({}, azureEnv.Environment.USGovernment), { isCustomCloud: false });
44
- }
45
- else if (environmentSettingValue === CloudEnvironmentSettingValue.Custom) {
46
- const customCloud = authProviderConfig.get(CustomEnvironmentSettingName);
47
- if (customCloud) {
48
- return Object.assign(Object.assign({}, new azureEnv.Environment(customCloud)), { isCustomCloud: true });
49
- }
50
- throw new Error(vscode.l10n.t('The custom cloud choice is not configured. Please configure the setting `{0}.{1}`.', CustomCloudConfigurationSection, CustomEnvironmentSettingName));
51
- }
52
- return Object.assign(Object.assign({}, azureEnv.Environment.get(azureEnv.Environment.AzureCloud.name)), { isCustomCloud: false });
53
- }
54
- /**
55
- * Sets the configured Azure cloud.
56
- *
57
- * @param cloud Use `'AzureCloud'` or `undefined` for public Azure cloud, `'ChinaCloud'` for Azure China, or `'USGovernment'` for Azure US Government.
58
- * These are the same values as the cloud names in `@azure/ms-rest-azure-env`. For a custom cloud, use an instance of the `@azure/ms-rest-azure-env` {@link azureEnv.EnvironmentParameters}.
59
- *
60
- * @param target (Optional) The configuration target to use, by default {@link vscode.ConfigurationTarget.Global}.
61
- */
62
- function setConfiguredAzureEnv(cloud_1) {
63
- return __awaiter(this, arguments, void 0, function* (cloud, target = vscode.ConfigurationTarget.Global) {
64
- const authProviderConfig = vscode.workspace.getConfiguration(CustomCloudConfigurationSection);
65
- if (typeof cloud === 'undefined' || !cloud) {
66
- // Use public cloud implicitly--set `environment` setting to `undefined`
67
- yield authProviderConfig.update(CloudEnvironmentSettingName, undefined, target);
68
- }
69
- else if (typeof cloud === 'string' && cloud === 'AzureCloud') {
70
- // Use public cloud explicitly--set `environment` setting to `undefined`
71
- yield authProviderConfig.update(CloudEnvironmentSettingName, undefined, target);
72
- }
73
- else if (typeof cloud === 'string') {
74
- // Use a sovereign cloud--set the `environment` setting to the specified value
75
- yield authProviderConfig.update(CloudEnvironmentSettingName, cloud, target);
76
- }
77
- else if (typeof cloud === 'object') {
78
- // use a custom cloud--set the `environment` setting to `custom` and the `customEnvironment` setting to the specified value
79
- yield authProviderConfig.update(CloudEnvironmentSettingName, CloudEnvironmentSettingValue.Custom, target);
80
- yield authProviderConfig.update(CustomEnvironmentSettingName, cloud, target);
81
- }
82
- else {
83
- throw new Error(`Invalid cloud value: ${JSON.stringify(cloud)}`);
84
- }
85
- });
86
- }
87
- /**
88
- * Gets the ID of the authentication provider configured to be used
89
- * @returns The provider ID to use, either `'microsoft'` or `'microsoft-sovereign-cloud'`
90
- */
91
- function getConfiguredAuthProviderId() {
92
- return getConfiguredAzureEnv().name === azureEnv.Environment.AzureCloud.name ? 'microsoft' : 'microsoft-sovereign-cloud';
93
- }
94
- //# sourceMappingURL=configuredAzureEnv.js.map