@microsoft/vscode-azext-azureauth 1.4.0 → 2.1.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.
- package/CHANGELOG.md +3 -0
- package/out/src/AzureSubscriptionProvider.d.ts +1 -1
- package/out/src/Tenant.d.ts +4 -0
- package/out/src/Tenant.js +7 -0
- package/out/src/VSCodeAzureSubscriptionProvider.d.ts +1 -2
- package/out/src/VSCodeAzureSubscriptionProvider.js +54 -38
- package/out/src/getSessionFromVSCode.js +4 -1
- package/out/src/utils/configuredAzureEnv.js +2 -2
- package/out/src/utils/getUnauthenticatedTenants.d.ts +1 -1
- package/out/src/utils/signInToTenant.d.ts +2 -0
- package/out/src/utils/signInToTenant.js +89 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 1.4.0 - 2023-11-03
|
|
4
|
+
* [#1619](https://github.com/microsoft/vscode-azuretools/pull/1619) Make `getSession` synchronous to fix an issue that broke app service deployments
|
|
5
|
+
|
|
3
6
|
## 1.3.0 - 2023-10-23
|
|
4
7
|
|
|
5
8
|
* [#1610](https://github.com/microsoft/vscode-azuretools/pull/1610) Add `signInToTenant` command which facilitates signing in to a specific tenant.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as vscode from 'vscode';
|
|
2
2
|
import type { AzureSubscription } from './AzureSubscription';
|
|
3
|
-
import { TenantIdDescription } from '@azure/arm-subscriptions';
|
|
3
|
+
import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
|
|
4
4
|
/**
|
|
5
5
|
* An interface for obtaining Azure subscription information
|
|
6
6
|
*/
|
|
@@ -0,0 +1,7 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import type { TenantIdDescription } from '@azure/arm-subscriptions';
|
|
1
|
+
import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
|
|
2
2
|
import * as vscode from 'vscode';
|
|
3
3
|
import type { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
|
|
4
4
|
import type { AzureSubscriptionProvider } from './AzureSubscriptionProvider';
|
|
@@ -99,5 +99,4 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
|
|
|
99
99
|
* @returns A client, the credential used by the client, and the authentication function
|
|
100
100
|
*/
|
|
101
101
|
private getSubscriptionClient;
|
|
102
|
-
private getToken;
|
|
103
102
|
}
|
|
@@ -74,13 +74,31 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
74
74
|
* @returns A list of tenants.
|
|
75
75
|
*/
|
|
76
76
|
getTenants() {
|
|
77
|
+
var _a, e_1, _b, _c;
|
|
77
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const { client } = yield this.getSubscriptionClient();
|
|
80
|
+
const results = [];
|
|
81
|
+
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;
|
|
85
|
+
try {
|
|
86
|
+
const tenant = _c;
|
|
87
|
+
results.push(tenant);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
_d = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
95
|
+
finally {
|
|
96
|
+
try {
|
|
97
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
81
98
|
}
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
finally { if (e_1) throw e_1.error; }
|
|
100
|
+
}
|
|
101
|
+
return results;
|
|
84
102
|
});
|
|
85
103
|
}
|
|
86
104
|
/**
|
|
@@ -99,8 +117,6 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
99
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
118
|
const tenantIds = yield this.getTenantFilters();
|
|
101
119
|
const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"
|
|
102
|
-
const subscriptionIds = yield this.getSubscriptionFilters();
|
|
103
|
-
const shouldFilterSubscriptions = filter && !!subscriptionIds.length; // If the list is empty it is treated as "no filter"
|
|
104
120
|
const results = [];
|
|
105
121
|
try {
|
|
106
122
|
this.suppressSignInEvents = true;
|
|
@@ -117,19 +133,18 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
117
133
|
continue;
|
|
118
134
|
}
|
|
119
135
|
// For each tenant, get the list of subscriptions
|
|
120
|
-
|
|
121
|
-
// If filtering is enabled, and the current subscription is not in that list, then skip it
|
|
122
|
-
if (shouldFilterSubscriptions && !subscriptionIds.includes(subscription.subscriptionId)) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
results.push(subscription);
|
|
126
|
-
}
|
|
136
|
+
results.push(...yield this.getSubscriptionsForTenant(tenantId));
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
139
|
finally {
|
|
130
140
|
this.suppressSignInEvents = false;
|
|
131
141
|
}
|
|
132
|
-
|
|
142
|
+
const sortSubscriptions = (subscriptions) => subscriptions.sort((a, b) => a.name.localeCompare(b.name));
|
|
143
|
+
const subscriptionIds = yield this.getSubscriptionFilters();
|
|
144
|
+
if (filter && !!subscriptionIds.length) { // If the list is empty it is treated as "no filter"
|
|
145
|
+
return sortSubscriptions(results.filter(sub => subscriptionIds.includes(sub.subscriptionId)));
|
|
146
|
+
}
|
|
147
|
+
return sortSubscriptions(results);
|
|
133
148
|
});
|
|
134
149
|
}
|
|
135
150
|
/**
|
|
@@ -206,7 +221,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
206
221
|
* @returns The list of subscriptions for the tenant.
|
|
207
222
|
*/
|
|
208
223
|
getSubscriptionsForTenant(tenantId) {
|
|
209
|
-
var _a,
|
|
224
|
+
var _a, e_2, _b, _c;
|
|
210
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
211
226
|
const { client, credential, authentication } = yield this.getSubscriptionClient(tenantId);
|
|
212
227
|
const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
|
|
@@ -234,12 +249,12 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
234
249
|
}
|
|
235
250
|
}
|
|
236
251
|
}
|
|
237
|
-
catch (
|
|
252
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
238
253
|
finally {
|
|
239
254
|
try {
|
|
240
255
|
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
241
256
|
}
|
|
242
|
-
finally { if (
|
|
257
|
+
finally { if (e_2) throw e_2.error; }
|
|
243
258
|
}
|
|
244
259
|
return subscriptions;
|
|
245
260
|
});
|
|
@@ -251,39 +266,40 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
251
266
|
*
|
|
252
267
|
* @returns A client, the credential used by the client, and the authentication function
|
|
253
268
|
*/
|
|
254
|
-
getSubscriptionClient(tenantId
|
|
269
|
+
getSubscriptionClient(tenantId) {
|
|
255
270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
if (!session) {
|
|
271
|
+
const initialSession = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(undefined, tenantId, { createIfNone: false, silent: true });
|
|
272
|
+
if (!initialSession) {
|
|
259
273
|
throw new NotSignedInError_1.NotSignedInError();
|
|
260
274
|
}
|
|
261
275
|
const credential = {
|
|
262
|
-
getToken: () => __awaiter(this, void 0, void 0, function* () {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
+
}
|
|
267
287
|
})
|
|
268
288
|
};
|
|
289
|
+
const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
|
|
290
|
+
const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
|
|
291
|
+
const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
|
|
269
292
|
return {
|
|
270
|
-
client: new armSubs.SubscriptionClient(credential),
|
|
293
|
+
client: new armSubs.SubscriptionClient(credential, { endpoint }),
|
|
271
294
|
credential: credential,
|
|
272
295
|
authentication: {
|
|
273
|
-
getSession: () =>
|
|
296
|
+
getSession: (scopes) => __awaiter(this, void 0, void 0, function* () {
|
|
297
|
+
return yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
|
|
298
|
+
})
|
|
274
299
|
}
|
|
275
300
|
};
|
|
276
301
|
});
|
|
277
302
|
}
|
|
278
|
-
getToken(tenantId) {
|
|
279
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
-
const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
|
|
281
|
-
if (!session) {
|
|
282
|
-
throw new NotSignedInError_1.NotSignedInError();
|
|
283
|
-
}
|
|
284
|
-
return session.accessToken;
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
303
|
}
|
|
288
304
|
exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
|
|
289
305
|
//# sourceMappingURL=VSCodeAzureSubscriptionProvider.js.map
|
|
@@ -16,9 +16,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.getSessionFromVSCode = void 0;
|
|
17
17
|
const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
|
|
18
18
|
const vscode = require("vscode");
|
|
19
|
+
function ensureEndingSlash(value) {
|
|
20
|
+
return value.endsWith('/') ? value : `${value}/`;
|
|
21
|
+
}
|
|
19
22
|
function getResourceScopes(scopes) {
|
|
20
23
|
if (scopes === undefined || scopes === "" || scopes.length === 0) {
|
|
21
|
-
scopes =
|
|
24
|
+
scopes = ensureEndingSlash((0, configuredAzureEnv_1.getConfiguredAzureEnv)().resourceManagerEndpointUrl);
|
|
22
25
|
}
|
|
23
26
|
const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
|
|
24
27
|
.map((scope) => {
|
|
@@ -35,10 +35,10 @@ function getConfiguredAzureEnv() {
|
|
|
35
35
|
const authProviderConfig = vscode.workspace.getConfiguration(CustomCloudConfigurationSection);
|
|
36
36
|
const environmentSettingValue = authProviderConfig.get(CloudEnvironmentSettingName);
|
|
37
37
|
if (environmentSettingValue === CloudEnvironmentSettingValue.ChinaCloud) {
|
|
38
|
-
return Object.assign(Object.assign({}, azureEnv.Environment.
|
|
38
|
+
return Object.assign(Object.assign({}, azureEnv.Environment.ChinaCloud), { isCustomCloud: false });
|
|
39
39
|
}
|
|
40
40
|
else if (environmentSettingValue === CloudEnvironmentSettingValue.USGovernment) {
|
|
41
|
-
return Object.assign(Object.assign({}, azureEnv.Environment.
|
|
41
|
+
return Object.assign(Object.assign({}, azureEnv.Environment.USGovernment), { isCustomCloud: false });
|
|
42
42
|
}
|
|
43
43
|
else if (environmentSettingValue === CloudEnvironmentSettingValue.Custom) {
|
|
44
44
|
const customCloud = authProviderConfig.get(CustomEnvironmentSettingName);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TenantIdDescription } from "@azure/arm-subscriptions";
|
|
1
|
+
import type { TenantIdDescription } from "@azure/arm-resources-subscriptions";
|
|
2
2
|
import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
|
|
3
3
|
/**
|
|
4
4
|
* @returns list of tenants that VS Code doesn't have sessions for
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/vscode-azext-azureauth",
|
|
3
3
|
"author": "Microsoft Corporation",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Azure authentication helpers for Visual Studio Code",
|
|
6
6
|
"tags": [
|
|
7
7
|
"azure",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"typescript": "^4.9.4"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@azure/arm-subscriptions": "^
|
|
55
|
+
"@azure/arm-resources-subscriptions": "^2.1.0",
|
|
56
56
|
"@azure/ms-rest-azure-env": "^2.0.0"
|
|
57
57
|
}
|
|
58
58
|
}
|