@microsoft/vscode-azext-azureauth 1.2.1 → 1.2.2
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.
|
@@ -100,22 +100,4 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
|
|
|
100
100
|
*/
|
|
101
101
|
private getSubscriptionClient;
|
|
102
102
|
private getToken;
|
|
103
|
-
/**
|
|
104
|
-
* Gets a normalized list of scopes. If no scopes are provided, the return value of {@link getDefaultScope} is used.
|
|
105
|
-
*
|
|
106
|
-
* Only supports top-level resource scopes (e.g. http://management.azure.com, http://storage.azure.com) or .default scopes.
|
|
107
|
-
*
|
|
108
|
-
* All resources/scopes will be normalized to the `.default` scope for each resource.
|
|
109
|
-
*
|
|
110
|
-
* @param scopes An input scope string, list, or undefined
|
|
111
|
-
* @param tenantId (Optional) The tenant ID, will be added to the scopes
|
|
112
|
-
*/
|
|
113
|
-
private getScopes;
|
|
114
|
-
/**
|
|
115
|
-
* Gets the default Azure scopes required for resource management,
|
|
116
|
-
* depending on the configured endpoint
|
|
117
|
-
*
|
|
118
|
-
* @returns The default Azure scopes required
|
|
119
|
-
*/
|
|
120
|
-
private getDefaultScope;
|
|
121
103
|
}
|
|
@@ -24,6 +24,7 @@ exports.VSCodeAzureSubscriptionProvider = void 0;
|
|
|
24
24
|
const cross_fetch_1 = require("cross-fetch");
|
|
25
25
|
const vscode = require("vscode");
|
|
26
26
|
const NotSignedInError_1 = require("./NotSignedInError");
|
|
27
|
+
const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
|
|
27
28
|
const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
|
|
28
29
|
const EventDebounce = 5 * 1000; // 5 seconds
|
|
29
30
|
/**
|
|
@@ -141,7 +142,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
141
142
|
*/
|
|
142
143
|
isSignedIn(tenantId) {
|
|
143
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const session = yield
|
|
145
|
+
const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
|
|
145
146
|
return !!session;
|
|
146
147
|
});
|
|
147
148
|
}
|
|
@@ -154,7 +155,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
154
155
|
*/
|
|
155
156
|
signIn(tenantId) {
|
|
156
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
const session = yield
|
|
158
|
+
const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: true, clearSessionPreference: true });
|
|
158
159
|
return !!session;
|
|
159
160
|
});
|
|
160
161
|
}
|
|
@@ -255,7 +256,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
255
256
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
257
|
const armSubs = yield Promise.resolve().then(() => require('@azure/arm-subscriptions'));
|
|
257
258
|
const getSession = (scopes) => __awaiter(this, void 0, void 0, function* () {
|
|
258
|
-
const session = yield
|
|
259
|
+
const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
|
|
259
260
|
if (!session) {
|
|
260
261
|
throw new NotSignedInError_1.NotSignedInError();
|
|
261
262
|
}
|
|
@@ -264,7 +265,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
264
265
|
const credential = {
|
|
265
266
|
getToken: (scopes) => __awaiter(this, void 0, void 0, function* () {
|
|
266
267
|
return {
|
|
267
|
-
token: (yield getSession(
|
|
268
|
+
token: (yield getSession(scopes)).accessToken,
|
|
268
269
|
expiresOnTimestamp: 0
|
|
269
270
|
};
|
|
270
271
|
})
|
|
@@ -273,58 +274,20 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
273
274
|
client: new armSubs.SubscriptionClient(credential),
|
|
274
275
|
credential: credential,
|
|
275
276
|
authentication: {
|
|
276
|
-
getSession
|
|
277
|
+
getSession,
|
|
277
278
|
}
|
|
278
279
|
};
|
|
279
280
|
});
|
|
280
281
|
}
|
|
281
282
|
getToken(tenantId) {
|
|
282
283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
const session = yield
|
|
284
|
+
const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
|
|
284
285
|
if (!session) {
|
|
285
286
|
throw new NotSignedInError_1.NotSignedInError();
|
|
286
287
|
}
|
|
287
288
|
return session.accessToken;
|
|
288
289
|
});
|
|
289
290
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Gets a normalized list of scopes. If no scopes are provided, the return value of {@link getDefaultScope} is used.
|
|
292
|
-
*
|
|
293
|
-
* Only supports top-level resource scopes (e.g. http://management.azure.com, http://storage.azure.com) or .default scopes.
|
|
294
|
-
*
|
|
295
|
-
* All resources/scopes will be normalized to the `.default` scope for each resource.
|
|
296
|
-
*
|
|
297
|
-
* @param scopes An input scope string, list, or undefined
|
|
298
|
-
* @param tenantId (Optional) The tenant ID, will be added to the scopes
|
|
299
|
-
*/
|
|
300
|
-
getScopes(scopes, tenantId) {
|
|
301
|
-
if (scopes === undefined || scopes === "" || scopes.length === 0) {
|
|
302
|
-
scopes = this.getDefaultScope();
|
|
303
|
-
}
|
|
304
|
-
const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
|
|
305
|
-
.map((scope) => {
|
|
306
|
-
if (scope.endsWith('.default')) {
|
|
307
|
-
return scope;
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
return `${scope}.default`;
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
const scopeSet = new Set(arrScopes);
|
|
314
|
-
if (tenantId) {
|
|
315
|
-
scopeSet.add(`VSCODE_TENANT:${tenantId}`);
|
|
316
|
-
}
|
|
317
|
-
return Array.from(scopeSet);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Gets the default Azure scopes required for resource management,
|
|
321
|
-
* depending on the configured endpoint
|
|
322
|
-
*
|
|
323
|
-
* @returns The default Azure scopes required
|
|
324
|
-
*/
|
|
325
|
-
getDefaultScope() {
|
|
326
|
-
return `${(0, configuredAzureEnv_1.getConfiguredAzureEnv)().resourceManagerEndpointUrl}.default`;
|
|
327
|
-
}
|
|
328
291
|
}
|
|
329
292
|
exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
|
|
330
293
|
//# sourceMappingURL=VSCodeAzureSubscriptionProvider.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as vscode from "vscode";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps {@link vscode.authentication.getSession} and handles:
|
|
4
|
+
* * Passing the configured auth provider id
|
|
5
|
+
* * Getting the list of scopes, adding the tenant id to the scope list if needed
|
|
6
|
+
*
|
|
7
|
+
* @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.
|
|
8
|
+
* @param tenantId - (Optional) The tenant ID, will be added to the scopes
|
|
9
|
+
* @param options - see {@link vscode.AuthenticationGetSessionOptions}
|
|
10
|
+
* @returns An authentication session if available, or undefined if there are no sessions
|
|
11
|
+
*/
|
|
12
|
+
export declare function getSessionFromVSCode(scopes?: string | string[], tenantId?: string, options?: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 = void 0;
|
|
17
|
+
const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
|
|
18
|
+
const vscode = require("vscode");
|
|
19
|
+
function getResourceScopes(scopes) {
|
|
20
|
+
if (scopes === undefined || scopes === "" || scopes.length === 0) {
|
|
21
|
+
scopes = `${(0, configuredAzureEnv_1.getConfiguredAzureEnv)().resourceManagerEndpointUrl}.default`;
|
|
22
|
+
}
|
|
23
|
+
const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
|
|
24
|
+
.map((scope) => {
|
|
25
|
+
if (scope.endsWith('.default')) {
|
|
26
|
+
return scope;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return `${scope}.default`;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return Array.from(new Set(arrScopes));
|
|
33
|
+
}
|
|
34
|
+
function addTenantIdScope(scopes, tenantId) {
|
|
35
|
+
const scopeSet = new Set(scopes);
|
|
36
|
+
scopeSet.add(`VSCODE_TENANT:${tenantId}`);
|
|
37
|
+
return Array.from(scopeSet);
|
|
38
|
+
}
|
|
39
|
+
function getScopes(scopes, tenantId) {
|
|
40
|
+
let scopeArr = getResourceScopes(scopes);
|
|
41
|
+
if (tenantId) {
|
|
42
|
+
scopeArr = addTenantIdScope(scopeArr, tenantId);
|
|
43
|
+
}
|
|
44
|
+
return scopeArr;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Wraps {@link vscode.authentication.getSession} and handles:
|
|
48
|
+
* * Passing the configured auth provider id
|
|
49
|
+
* * Getting the list of scopes, adding the tenant id to the scope list if needed
|
|
50
|
+
*
|
|
51
|
+
* @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.
|
|
52
|
+
* @param tenantId - (Optional) The tenant ID, will be added to the scopes
|
|
53
|
+
* @param options - see {@link vscode.AuthenticationGetSessionOptions}
|
|
54
|
+
* @returns An authentication session if available, or undefined if there are no sessions
|
|
55
|
+
*/
|
|
56
|
+
function getSessionFromVSCode(scopes, tenantId, options) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return yield vscode.authentication.getSession((0, configuredAzureEnv_1.getConfiguredAuthProviderId)(), getScopes(scopes, tenantId), options);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.getSessionFromVSCode = getSessionFromVSCode;
|
|
62
|
+
//# sourceMappingURL=getSessionFromVSCode.js.map
|