@microsoft/vscode-azext-azureauth 5.0.0 → 5.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 +10 -0
- package/dist/cjs/src/AzureDevOpsSubscriptionProvider.js +2 -3
- package/dist/cjs/src/VSCodeAzureSubscriptionProvider.js +85 -42
- package/dist/cjs/src/index.js +1 -0
- package/dist/cjs/src/utils/getUnauthenticatedTenants.js +4 -2
- package/dist/cjs/src/utils/isGetSubscriptionsFilter.js +27 -0
- package/dist/esm/src/AzureDevOpsSubscriptionProvider.d.ts +6 -6
- package/dist/esm/src/AzureDevOpsSubscriptionProvider.js +2 -3
- package/dist/esm/src/AzureSubscription.d.ts +2 -2
- package/dist/esm/src/AzureTenant.d.ts +2 -2
- package/dist/esm/src/VSCodeAzureSubscriptionProvider.d.ts +8 -13
- package/dist/esm/src/VSCodeAzureSubscriptionProvider.js +85 -42
- package/dist/esm/src/index.d.ts +1 -46
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/utils/getUnauthenticatedTenants.d.ts +4 -1
- package/dist/esm/src/utils/getUnauthenticatedTenants.js +4 -2
- package/dist/esm/src/utils/isGetSubscriptionsFilter.d.ts +14 -0
- package/dist/esm/src/utils/isGetSubscriptionsFilter.js +23 -0
- package/package.json +3 -3
- package/dist/cjs/src/AzureAuthentication.d.ts +0 -21
- package/dist/cjs/src/AzureDevOpsSubscriptionProvider.d.ts +0 -68
- package/dist/cjs/src/AzureSubscription.d.ts +0 -49
- package/dist/cjs/src/AzureSubscriptionProvider.d.ts +0 -82
- package/dist/cjs/src/AzureTenant.d.ts +0 -5
- package/dist/cjs/src/NotSignedInError.d.ts +0 -15
- package/dist/cjs/src/VSCodeAzureSubscriptionProvider.d.ts +0 -117
- package/dist/cjs/src/getSessionFromVSCode.d.ts +0 -13
- package/dist/cjs/src/index.d.ts +0 -56
- package/dist/cjs/src/signInToTenant.d.ts +0 -6
- package/dist/cjs/src/utils/configuredAzureEnv.d.ts +0 -24
- package/dist/cjs/src/utils/getUnauthenticatedTenants.d.ts +0 -6
- package/dist/cjs/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 5.1.0 - 2025-10-27
|
|
4
|
+
|
|
5
|
+
* [#2102](https://github.com/microsoft/vscode-azuretools/pull/2102) Fixes an issue causing infinite event loops especially in https://vscode.dev/azure
|
|
6
|
+
* [#2110](https://github.com/microsoft/vscode-azuretools/pull/2110) `vscode.authentication.onDidChangeSessions()` is no longer subscribed to unless the caller calls `AzureSubscriptionProvider.onDidSignIn()` or `AzureSubscriptionProvider.onDidSignOut()`.
|
|
7
|
+
|
|
8
|
+
## 5.0.0 - 2025-10-07
|
|
9
|
+
|
|
10
|
+
* [#2092](https://github.com/microsoft/vscode-azuretools/pull/2092) Converts from CJS only to CJS+ESM
|
|
11
|
+
* Adopts finalized auth challenges API
|
|
12
|
+
|
|
3
13
|
## 4.2.2 - 2025-09-10
|
|
4
14
|
|
|
5
15
|
* [#2073](https://github.com/microsoft/vscode-azuretools/pull/2073) Changes to adjust to proposed API changes
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.AzureDevOpsSubscriptionProvider = void 0;
|
|
8
8
|
exports.createAzureDevOpsSubscriptionProviderFactory = createAzureDevOpsSubscriptionProviderFactory;
|
|
9
|
-
const vscode_1 = require("vscode");
|
|
10
9
|
const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
|
|
11
10
|
let azureDevOpsSubscriptionProvider;
|
|
12
11
|
function createAzureDevOpsSubscriptionProviderFactory(initializer) {
|
|
@@ -144,8 +143,8 @@ class AzureDevOpsSubscriptionProvider {
|
|
|
144
143
|
}
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
|
-
onDidSignIn = () => { return
|
|
148
|
-
onDidSignOut = () => { return
|
|
146
|
+
onDidSignIn = () => { return { dispose() { } }; };
|
|
147
|
+
onDidSignOut = () => { return { dispose() { } }; };
|
|
149
148
|
}
|
|
150
149
|
exports.AzureDevOpsSubscriptionProvider = AzureDevOpsSubscriptionProvider;
|
|
151
150
|
/*
|
|
@@ -43,42 +43,82 @@ const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
|
|
|
43
43
|
const NotSignedInError_1 = require("./NotSignedInError");
|
|
44
44
|
const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
|
|
45
45
|
const isAuthenticationWwwAuthenticateRequest_1 = require("./utils/isAuthenticationWwwAuthenticateRequest");
|
|
46
|
+
const isGetSubscriptionsFilter_1 = require("./utils/isGetSubscriptionsFilter");
|
|
46
47
|
const EventDebounce = 5 * 1000; // 5 seconds
|
|
48
|
+
let armSubs;
|
|
47
49
|
/**
|
|
48
50
|
* A class for obtaining Azure subscription information using VSCode's built-in authentication
|
|
49
51
|
* provider.
|
|
50
52
|
*/
|
|
51
|
-
class VSCodeAzureSubscriptionProvider
|
|
53
|
+
class VSCodeAzureSubscriptionProvider {
|
|
52
54
|
logger;
|
|
53
|
-
onDidSignInEmitter = new vscode.EventEmitter();
|
|
54
55
|
lastSignInEventFired = 0;
|
|
55
56
|
suppressSignInEvents = false;
|
|
56
|
-
onDidSignOutEmitter = new vscode.EventEmitter();
|
|
57
57
|
lastSignOutEventFired = 0;
|
|
58
|
+
priorAccounts;
|
|
58
59
|
// So that customers can easily share logs, try to only log PII using trace level
|
|
59
60
|
constructor(logger) {
|
|
61
|
+
this.logger = logger;
|
|
62
|
+
// Load accounts initially, then onDidChangeSessions can compare against them
|
|
63
|
+
void vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)()).then(accounts => {
|
|
64
|
+
this.priorAccounts = Array.from(accounts); // The Array.from is to get rid of the readonly marker on the array returned by the API
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
onDidSignIn(callback, thisArg, disposables) {
|
|
69
|
+
return this.onDidChangeSessions(true, callback, thisArg, disposables);
|
|
70
|
+
}
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
+
onDidSignOut(callback, thisArg, disposables) {
|
|
73
|
+
return this.onDidChangeSessions(false, callback, thisArg, disposables);
|
|
74
|
+
}
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
onDidChangeSessions(signIn, callback, thisArg, disposables) {
|
|
77
|
+
const isASignInEvent = async () => {
|
|
78
|
+
const currentAccounts = Array.from(await vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)())); // The Array.from is to get rid of the readonly marker on the array returned by the API
|
|
79
|
+
const priorAccountCount = this.priorAccounts?.length ?? 0;
|
|
80
|
+
this.priorAccounts = currentAccounts;
|
|
81
|
+
// The only way a sign out happens is if an account is removed entirely from the list of accounts
|
|
82
|
+
if (currentAccounts.length === 0 || currentAccounts.length < priorAccountCount) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
};
|
|
87
|
+
const wrappedCallback = () => {
|
|
88
|
+
const immediate = setImmediate(() => {
|
|
89
|
+
clearImmediate(immediate);
|
|
90
|
+
void callback.call(thisArg);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
60
93
|
const disposable = vscode.authentication.onDidChangeSessions(async (e) => {
|
|
61
94
|
// Ignore any sign in that isn't for the configured auth provider
|
|
62
95
|
if (e.provider.id !== (0, configuredAzureEnv_1.getConfiguredAuthProviderId)()) {
|
|
63
96
|
return;
|
|
64
97
|
}
|
|
65
|
-
if (
|
|
66
|
-
if (
|
|
98
|
+
if (signIn) {
|
|
99
|
+
if (this.suppressSignInEvents || Date.now() < this.lastSignInEventFired + EventDebounce) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
else if (await isASignInEvent()) {
|
|
67
103
|
this.lastSignInEventFired = Date.now();
|
|
68
|
-
|
|
104
|
+
wrappedCallback();
|
|
69
105
|
}
|
|
70
106
|
}
|
|
71
|
-
else
|
|
72
|
-
|
|
73
|
-
|
|
107
|
+
else {
|
|
108
|
+
if (Date.now() < this.lastSignOutEventFired + EventDebounce) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
else if (!await isASignInEvent()) {
|
|
112
|
+
this.lastSignOutEventFired = Date.now();
|
|
113
|
+
wrappedCallback();
|
|
114
|
+
}
|
|
74
115
|
}
|
|
75
116
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.logger = logger;
|
|
117
|
+
disposables?.push(disposable);
|
|
118
|
+
return disposable;
|
|
119
|
+
}
|
|
120
|
+
dispose() {
|
|
121
|
+
// No-op, this class no longer has disposables
|
|
82
122
|
}
|
|
83
123
|
/**
|
|
84
124
|
* Gets a list of tenants available to the user.
|
|
@@ -124,24 +164,28 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
124
164
|
async getSubscriptions(filter = true) {
|
|
125
165
|
this.logger?.debug('auth: Loading subscriptions...');
|
|
126
166
|
const startTime = Date.now();
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
167
|
+
let tenantIdsToFilterBy;
|
|
168
|
+
if ((0, isGetSubscriptionsFilter_1.isGetSubscriptionsTenantFilter)(filter)) {
|
|
169
|
+
// Only filter by the tenant ID option if it is provided
|
|
170
|
+
tenantIdsToFilterBy = [filter.tenantId];
|
|
171
|
+
}
|
|
172
|
+
else if (filter === true) {
|
|
131
173
|
// Only filter by the configured filter if `filter` is true AND there are tenants in the configured filter
|
|
132
|
-
|
|
133
|
-
|
|
174
|
+
const configuredTenantFilter = await this.getTenantFilters();
|
|
175
|
+
if (configuredTenantFilter.length > 0) {
|
|
176
|
+
tenantIdsToFilterBy = configuredTenantFilter;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
134
179
|
const allSubscriptions = [];
|
|
135
180
|
let accountCount; // only used for logging
|
|
136
181
|
try {
|
|
137
182
|
this.suppressSignInEvents = true;
|
|
138
183
|
// Get the list of tenants from each account (filtered or all)
|
|
139
|
-
const accounts =
|
|
184
|
+
const accounts = (0, isGetSubscriptionsFilter_1.isGetSubscriptionsAccountFilter)(filter) ? [filter.account] : await vscode.authentication.getAccounts((0, configuredAzureEnv_1.getConfiguredAuthProviderId)());
|
|
140
185
|
accountCount = accounts.length;
|
|
141
186
|
for (const account of accounts) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const tenantId = tenant.tenantId;
|
|
187
|
+
const tenantIds = (0, isGetSubscriptionsFilter_1.isGetSubscriptionsTenantFilter)(filter) ? [filter.tenantId] : (await this.getTenants(account)).map(t => t.tenantId);
|
|
188
|
+
for (const tenantId of tenantIds) {
|
|
145
189
|
if (tenantIdsToFilterBy?.includes(tenantId) === false) {
|
|
146
190
|
continue;
|
|
147
191
|
}
|
|
@@ -157,8 +201,9 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
157
201
|
}
|
|
158
202
|
// It's possible that by listing subscriptions in all tenants and the "home" tenant there could be duplicate subscriptions
|
|
159
203
|
// Thus, we remove duplicate subscriptions. However, if multiple accounts have the same subscription, we keep them.
|
|
204
|
+
// There are also cases where the same subscription could appear in different tenants under the same account so we also need to keep those
|
|
160
205
|
const subscriptionMap = new Map();
|
|
161
|
-
allSubscriptions.forEach(sub => subscriptionMap.set(`${sub.account.id}/${sub.subscriptionId}`, sub));
|
|
206
|
+
allSubscriptions.forEach(sub => subscriptionMap.set(`${sub.account.id}/${sub.tenantId}/${sub.subscriptionId}`, sub));
|
|
162
207
|
const uniqueSubscriptions = Array.from(subscriptionMap.values());
|
|
163
208
|
const endTime = Date.now();
|
|
164
209
|
this.logger?.debug(`auth: Got ${uniqueSubscriptions.length} subscriptions from ${accountCount} accounts in ${endTime - startTime}ms`);
|
|
@@ -214,18 +259,20 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
214
259
|
*/
|
|
215
260
|
async signIn(tenantId, account) {
|
|
216
261
|
this.logger?.debug(`auth: Signing in (account="${account?.label ?? 'none'}") (tenantId="${tenantId ?? 'none'}")`);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
262
|
+
try {
|
|
263
|
+
this.suppressSignInEvents = true;
|
|
264
|
+
const session = await (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, {
|
|
265
|
+
createIfNone: true,
|
|
266
|
+
// If no account is provided, then clear the session preference which tells VS Code to show the account picker
|
|
267
|
+
clearSessionPreference: !account,
|
|
268
|
+
account,
|
|
269
|
+
});
|
|
270
|
+
return !!session;
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
this.suppressSignInEvents = false;
|
|
274
|
+
}
|
|
224
275
|
}
|
|
225
|
-
/**
|
|
226
|
-
* An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
|
|
227
|
-
*/
|
|
228
|
-
onDidSignIn = this.onDidSignInEmitter.event;
|
|
229
276
|
/**
|
|
230
277
|
* Signs the user out
|
|
231
278
|
*
|
|
@@ -234,10 +281,6 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
234
281
|
signOut() {
|
|
235
282
|
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.'));
|
|
236
283
|
}
|
|
237
|
-
/**
|
|
238
|
-
* An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
|
|
239
|
-
*/
|
|
240
|
-
onDidSignOut = this.onDidSignOutEmitter.event;
|
|
241
284
|
/**
|
|
242
285
|
* Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
|
|
243
286
|
* override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
|
|
@@ -308,7 +351,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
308
351
|
* @returns A client, the credential used by the client, and the authentication function
|
|
309
352
|
*/
|
|
310
353
|
async getSubscriptionClient(account, tenantId, scopes) {
|
|
311
|
-
|
|
354
|
+
armSubs ||= await import('@azure/arm-resources-subscriptions');
|
|
312
355
|
const session = await (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true, account });
|
|
313
356
|
if (!session) {
|
|
314
357
|
throw new NotSignedInError_1.NotSignedInError();
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./AzureDevOpsSubscriptionProvider"), exports);
|
|
|
23
23
|
__exportStar(require("./AzureSubscription"), exports);
|
|
24
24
|
__exportStar(require("./AzureSubscriptionProvider"), exports);
|
|
25
25
|
__exportStar(require("./AzureTenant"), exports);
|
|
26
|
+
__exportStar(require("./getSessionFromVSCode"), exports);
|
|
26
27
|
__exportStar(require("./NotSignedInError"), exports);
|
|
27
28
|
__exportStar(require("./signInToTenant"), exports);
|
|
28
29
|
__exportStar(require("./utils/configuredAzureEnv"), exports);
|
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.getUnauthenticatedTenants = getUnauthenticatedTenants;
|
|
8
8
|
/**
|
|
9
|
+
* @param subscriptionProvider The {@link AzureSubscriptionProvider} to use
|
|
10
|
+
* @param account (Optional) The account to get unauthenticated tenants for
|
|
9
11
|
* @returns list of tenants that VS Code doesn't have sessions for
|
|
10
12
|
*/
|
|
11
|
-
async function getUnauthenticatedTenants(subscriptionProvider) {
|
|
12
|
-
const tenants = await subscriptionProvider.getTenants();
|
|
13
|
+
async function getUnauthenticatedTenants(subscriptionProvider, account) {
|
|
14
|
+
const tenants = await subscriptionProvider.getTenants(account);
|
|
13
15
|
const unauthenticatedTenants = [];
|
|
14
16
|
for await (const tenant of tenants) {
|
|
15
17
|
if (!await subscriptionProvider.isSignedIn(tenant.tenantId, tenant.account)) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.md in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isGetSubscriptionsTenantFilter = isGetSubscriptionsTenantFilter;
|
|
8
|
+
exports.isGetSubscriptionsAccountFilter = isGetSubscriptionsAccountFilter;
|
|
9
|
+
/**
|
|
10
|
+
* Check if an object is a {@link GetSubscriptionsFilter} with a tenantId.
|
|
11
|
+
*/
|
|
12
|
+
function isGetSubscriptionsTenantFilter(obj) {
|
|
13
|
+
if (typeof obj === 'object' && !!obj && 'tenantId' in obj && typeof obj.tenantId === 'string' && !!obj.tenantId) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check if an object is a {@link GetSubscriptionsFilter} with an account.
|
|
20
|
+
*/
|
|
21
|
+
function isGetSubscriptionsAccountFilter(obj) {
|
|
22
|
+
if (typeof obj === 'object' && !!obj && 'account' in obj && typeof obj.account === 'object' && !!obj.account) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=isGetSubscriptionsFilter.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AzureSubscription } from './AzureSubscription';
|
|
3
|
-
import { AzureSubscriptionProvider, GetSubscriptionsFilter } from './AzureSubscriptionProvider';
|
|
4
|
-
import { AzureTenant } from './AzureTenant';
|
|
1
|
+
import type * as vscode from 'vscode';
|
|
2
|
+
import type { AzureSubscription } from './AzureSubscription';
|
|
3
|
+
import type { AzureSubscriptionProvider, GetSubscriptionsFilter } from './AzureSubscriptionProvider';
|
|
4
|
+
import type { AzureTenant } from './AzureTenant';
|
|
5
5
|
export interface AzureDevOpsSubscriptionProviderInitializer {
|
|
6
6
|
/**
|
|
7
7
|
* The resource ID of the Azure DevOps federated service connection,
|
|
@@ -63,6 +63,6 @@ export declare class AzureDevOpsSubscriptionProvider implements AzureSubscriptio
|
|
|
63
63
|
* @returns A client, the credential used by the client, and the authentication function
|
|
64
64
|
*/
|
|
65
65
|
private getSubscriptionClient;
|
|
66
|
-
onDidSignIn: Event<void>;
|
|
67
|
-
onDidSignOut: Event<void>;
|
|
66
|
+
onDidSignIn: vscode.Event<void>;
|
|
67
|
+
onDidSignOut: vscode.Event<void>;
|
|
68
68
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
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 { Disposable } from 'vscode';
|
|
6
5
|
import { getConfiguredAzureEnv } from './utils/configuredAzureEnv';
|
|
7
6
|
let azureDevOpsSubscriptionProvider;
|
|
8
7
|
export function createAzureDevOpsSubscriptionProviderFactory(initializer) {
|
|
@@ -140,8 +139,8 @@ export class AzureDevOpsSubscriptionProvider {
|
|
|
140
139
|
}
|
|
141
140
|
};
|
|
142
141
|
}
|
|
143
|
-
onDidSignIn = () => { return
|
|
144
|
-
onDidSignOut = () => { return
|
|
142
|
+
onDidSignIn = () => { return { dispose() { } }; };
|
|
143
|
+
onDidSignOut = () => { return { dispose() { } }; };
|
|
145
144
|
}
|
|
146
145
|
/*
|
|
147
146
|
* @param serviceConnectionId The resource ID of the Azure DevOps federated service connection,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TokenCredential } from '@azure/core-auth';
|
|
2
2
|
import type { Environment } from '@azure/ms-rest-azure-env';
|
|
3
|
-
import * as vscode from "vscode";
|
|
4
|
-
import { AzureAuthentication } from './AzureAuthentication';
|
|
3
|
+
import type * as vscode from "vscode";
|
|
4
|
+
import type { AzureAuthentication } from './AzureAuthentication';
|
|
5
5
|
/**
|
|
6
6
|
* A type representing an Azure subscription ID, not including the tenant ID.
|
|
7
7
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TenantIdDescription } from "@azure/arm-resources-subscriptions";
|
|
2
|
-
import * as vscode from 'vscode';
|
|
1
|
+
import type { TenantIdDescription } from "@azure/arm-resources-subscriptions";
|
|
2
|
+
import type * as vscode from 'vscode';
|
|
3
3
|
export interface AzureTenant extends TenantIdDescription {
|
|
4
4
|
account: vscode.AuthenticationSessionAccountInformation;
|
|
5
5
|
}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import * as vscode from 'vscode';
|
|
2
2
|
import { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
|
|
3
|
-
import { AzureSubscriptionProvider, GetSubscriptionsFilter } from './AzureSubscriptionProvider';
|
|
4
|
-
import { AzureTenant } from './AzureTenant';
|
|
3
|
+
import type { AzureSubscriptionProvider, GetSubscriptionsFilter } from './AzureSubscriptionProvider';
|
|
4
|
+
import type { AzureTenant } from './AzureTenant';
|
|
5
5
|
/**
|
|
6
6
|
* A class for obtaining Azure subscription information using VSCode's built-in authentication
|
|
7
7
|
* provider.
|
|
8
8
|
*/
|
|
9
|
-
export declare class VSCodeAzureSubscriptionProvider
|
|
9
|
+
export declare class VSCodeAzureSubscriptionProvider implements AzureSubscriptionProvider, vscode.Disposable {
|
|
10
10
|
private readonly logger?;
|
|
11
|
-
private readonly onDidSignInEmitter;
|
|
12
11
|
private lastSignInEventFired;
|
|
13
12
|
private suppressSignInEvents;
|
|
14
|
-
private readonly onDidSignOutEmitter;
|
|
15
13
|
private lastSignOutEventFired;
|
|
14
|
+
private priorAccounts;
|
|
16
15
|
constructor(logger?: vscode.LogOutputChannel | undefined);
|
|
16
|
+
onDidSignIn(callback: () => any, thisArg?: any, disposables?: vscode.Disposable[]): vscode.Disposable;
|
|
17
|
+
onDidSignOut(callback: () => any, thisArg?: any, disposables?: vscode.Disposable[]): vscode.Disposable;
|
|
18
|
+
private onDidChangeSessions;
|
|
19
|
+
dispose(): void;
|
|
17
20
|
/**
|
|
18
21
|
* Gets a list of tenants available to the user.
|
|
19
22
|
* Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
|
|
@@ -62,20 +65,12 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
|
|
|
62
65
|
* @returns True if the user is signed in, false otherwise.
|
|
63
66
|
*/
|
|
64
67
|
signIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
|
|
67
|
-
*/
|
|
68
|
-
readonly onDidSignIn: vscode.Event<void>;
|
|
69
68
|
/**
|
|
70
69
|
* Signs the user out
|
|
71
70
|
*
|
|
72
71
|
* @deprecated Not currently supported by VS Code auth providers
|
|
73
72
|
*/
|
|
74
73
|
signOut(): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
|
|
77
|
-
*/
|
|
78
|
-
readonly onDidSignOut: vscode.Event<void>;
|
|
79
74
|
/**
|
|
80
75
|
* Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
|
|
81
76
|
* override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
|
|
@@ -7,42 +7,82 @@ import { getSessionFromVSCode } from './getSessionFromVSCode';
|
|
|
7
7
|
import { NotSignedInError } from './NotSignedInError';
|
|
8
8
|
import { getConfiguredAuthProviderId, getConfiguredAzureEnv } from './utils/configuredAzureEnv';
|
|
9
9
|
import { isAuthenticationWwwAuthenticateRequest } from './utils/isAuthenticationWwwAuthenticateRequest';
|
|
10
|
+
import { isGetSubscriptionsAccountFilter, isGetSubscriptionsTenantFilter } from './utils/isGetSubscriptionsFilter';
|
|
10
11
|
const EventDebounce = 5 * 1000; // 5 seconds
|
|
12
|
+
let armSubs;
|
|
11
13
|
/**
|
|
12
14
|
* A class for obtaining Azure subscription information using VSCode's built-in authentication
|
|
13
15
|
* provider.
|
|
14
16
|
*/
|
|
15
|
-
export class VSCodeAzureSubscriptionProvider
|
|
17
|
+
export class VSCodeAzureSubscriptionProvider {
|
|
16
18
|
logger;
|
|
17
|
-
onDidSignInEmitter = new vscode.EventEmitter();
|
|
18
19
|
lastSignInEventFired = 0;
|
|
19
20
|
suppressSignInEvents = false;
|
|
20
|
-
onDidSignOutEmitter = new vscode.EventEmitter();
|
|
21
21
|
lastSignOutEventFired = 0;
|
|
22
|
+
priorAccounts;
|
|
22
23
|
// So that customers can easily share logs, try to only log PII using trace level
|
|
23
24
|
constructor(logger) {
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
// Load accounts initially, then onDidChangeSessions can compare against them
|
|
27
|
+
void vscode.authentication.getAccounts(getConfiguredAuthProviderId()).then(accounts => {
|
|
28
|
+
this.priorAccounts = Array.from(accounts); // The Array.from is to get rid of the readonly marker on the array returned by the API
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
onDidSignIn(callback, thisArg, disposables) {
|
|
33
|
+
return this.onDidChangeSessions(true, callback, thisArg, disposables);
|
|
34
|
+
}
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
onDidSignOut(callback, thisArg, disposables) {
|
|
37
|
+
return this.onDidChangeSessions(false, callback, thisArg, disposables);
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
onDidChangeSessions(signIn, callback, thisArg, disposables) {
|
|
41
|
+
const isASignInEvent = async () => {
|
|
42
|
+
const currentAccounts = Array.from(await vscode.authentication.getAccounts(getConfiguredAuthProviderId())); // The Array.from is to get rid of the readonly marker on the array returned by the API
|
|
43
|
+
const priorAccountCount = this.priorAccounts?.length ?? 0;
|
|
44
|
+
this.priorAccounts = currentAccounts;
|
|
45
|
+
// The only way a sign out happens is if an account is removed entirely from the list of accounts
|
|
46
|
+
if (currentAccounts.length === 0 || currentAccounts.length < priorAccountCount) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const wrappedCallback = () => {
|
|
52
|
+
const immediate = setImmediate(() => {
|
|
53
|
+
clearImmediate(immediate);
|
|
54
|
+
void callback.call(thisArg);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
24
57
|
const disposable = vscode.authentication.onDidChangeSessions(async (e) => {
|
|
25
58
|
// Ignore any sign in that isn't for the configured auth provider
|
|
26
59
|
if (e.provider.id !== getConfiguredAuthProviderId()) {
|
|
27
60
|
return;
|
|
28
61
|
}
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
62
|
+
if (signIn) {
|
|
63
|
+
if (this.suppressSignInEvents || Date.now() < this.lastSignInEventFired + EventDebounce) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
else if (await isASignInEvent()) {
|
|
31
67
|
this.lastSignInEventFired = Date.now();
|
|
32
|
-
|
|
68
|
+
wrappedCallback();
|
|
33
69
|
}
|
|
34
70
|
}
|
|
35
|
-
else
|
|
36
|
-
|
|
37
|
-
|
|
71
|
+
else {
|
|
72
|
+
if (Date.now() < this.lastSignOutEventFired + EventDebounce) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
else if (!await isASignInEvent()) {
|
|
76
|
+
this.lastSignOutEventFired = Date.now();
|
|
77
|
+
wrappedCallback();
|
|
78
|
+
}
|
|
38
79
|
}
|
|
39
80
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.logger = logger;
|
|
81
|
+
disposables?.push(disposable);
|
|
82
|
+
return disposable;
|
|
83
|
+
}
|
|
84
|
+
dispose() {
|
|
85
|
+
// No-op, this class no longer has disposables
|
|
46
86
|
}
|
|
47
87
|
/**
|
|
48
88
|
* Gets a list of tenants available to the user.
|
|
@@ -88,24 +128,28 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
88
128
|
async getSubscriptions(filter = true) {
|
|
89
129
|
this.logger?.debug('auth: Loading subscriptions...');
|
|
90
130
|
const startTime = Date.now();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
131
|
+
let tenantIdsToFilterBy;
|
|
132
|
+
if (isGetSubscriptionsTenantFilter(filter)) {
|
|
133
|
+
// Only filter by the tenant ID option if it is provided
|
|
134
|
+
tenantIdsToFilterBy = [filter.tenantId];
|
|
135
|
+
}
|
|
136
|
+
else if (filter === true) {
|
|
95
137
|
// Only filter by the configured filter if `filter` is true AND there are tenants in the configured filter
|
|
96
|
-
|
|
97
|
-
|
|
138
|
+
const configuredTenantFilter = await this.getTenantFilters();
|
|
139
|
+
if (configuredTenantFilter.length > 0) {
|
|
140
|
+
tenantIdsToFilterBy = configuredTenantFilter;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
98
143
|
const allSubscriptions = [];
|
|
99
144
|
let accountCount; // only used for logging
|
|
100
145
|
try {
|
|
101
146
|
this.suppressSignInEvents = true;
|
|
102
147
|
// Get the list of tenants from each account (filtered or all)
|
|
103
|
-
const accounts =
|
|
148
|
+
const accounts = isGetSubscriptionsAccountFilter(filter) ? [filter.account] : await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
|
|
104
149
|
accountCount = accounts.length;
|
|
105
150
|
for (const account of accounts) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const tenantId = tenant.tenantId;
|
|
151
|
+
const tenantIds = isGetSubscriptionsTenantFilter(filter) ? [filter.tenantId] : (await this.getTenants(account)).map(t => t.tenantId);
|
|
152
|
+
for (const tenantId of tenantIds) {
|
|
109
153
|
if (tenantIdsToFilterBy?.includes(tenantId) === false) {
|
|
110
154
|
continue;
|
|
111
155
|
}
|
|
@@ -121,8 +165,9 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
121
165
|
}
|
|
122
166
|
// It's possible that by listing subscriptions in all tenants and the "home" tenant there could be duplicate subscriptions
|
|
123
167
|
// Thus, we remove duplicate subscriptions. However, if multiple accounts have the same subscription, we keep them.
|
|
168
|
+
// There are also cases where the same subscription could appear in different tenants under the same account so we also need to keep those
|
|
124
169
|
const subscriptionMap = new Map();
|
|
125
|
-
allSubscriptions.forEach(sub => subscriptionMap.set(`${sub.account.id}/${sub.subscriptionId}`, sub));
|
|
170
|
+
allSubscriptions.forEach(sub => subscriptionMap.set(`${sub.account.id}/${sub.tenantId}/${sub.subscriptionId}`, sub));
|
|
126
171
|
const uniqueSubscriptions = Array.from(subscriptionMap.values());
|
|
127
172
|
const endTime = Date.now();
|
|
128
173
|
this.logger?.debug(`auth: Got ${uniqueSubscriptions.length} subscriptions from ${accountCount} accounts in ${endTime - startTime}ms`);
|
|
@@ -178,18 +223,20 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
178
223
|
*/
|
|
179
224
|
async signIn(tenantId, account) {
|
|
180
225
|
this.logger?.debug(`auth: Signing in (account="${account?.label ?? 'none'}") (tenantId="${tenantId ?? 'none'}")`);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
226
|
+
try {
|
|
227
|
+
this.suppressSignInEvents = true;
|
|
228
|
+
const session = await getSessionFromVSCode([], tenantId, {
|
|
229
|
+
createIfNone: true,
|
|
230
|
+
// If no account is provided, then clear the session preference which tells VS Code to show the account picker
|
|
231
|
+
clearSessionPreference: !account,
|
|
232
|
+
account,
|
|
233
|
+
});
|
|
234
|
+
return !!session;
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
this.suppressSignInEvents = false;
|
|
238
|
+
}
|
|
188
239
|
}
|
|
189
|
-
/**
|
|
190
|
-
* An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
|
|
191
|
-
*/
|
|
192
|
-
onDidSignIn = this.onDidSignInEmitter.event;
|
|
193
240
|
/**
|
|
194
241
|
* Signs the user out
|
|
195
242
|
*
|
|
@@ -198,10 +245,6 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
198
245
|
signOut() {
|
|
199
246
|
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.'));
|
|
200
247
|
}
|
|
201
|
-
/**
|
|
202
|
-
* An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
|
|
203
|
-
*/
|
|
204
|
-
onDidSignOut = this.onDidSignOutEmitter.event;
|
|
205
248
|
/**
|
|
206
249
|
* Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
|
|
207
250
|
* override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
|
|
@@ -272,7 +315,7 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
272
315
|
* @returns A client, the credential used by the client, and the authentication function
|
|
273
316
|
*/
|
|
274
317
|
async getSubscriptionClient(account, tenantId, scopes) {
|
|
275
|
-
|
|
318
|
+
armSubs ||= await import('@azure/arm-resources-subscriptions');
|
|
276
319
|
const session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true, account });
|
|
277
320
|
if (!session) {
|
|
278
321
|
throw new NotSignedInError();
|
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -3,54 +3,9 @@ export * from './AzureDevOpsSubscriptionProvider';
|
|
|
3
3
|
export * from './AzureSubscription';
|
|
4
4
|
export * from './AzureSubscriptionProvider';
|
|
5
5
|
export * from './AzureTenant';
|
|
6
|
+
export * from './getSessionFromVSCode';
|
|
6
7
|
export * from './NotSignedInError';
|
|
7
8
|
export * from './signInToTenant';
|
|
8
9
|
export * from './utils/configuredAzureEnv';
|
|
9
10
|
export * from './utils/getUnauthenticatedTenants';
|
|
10
11
|
export * from './VSCodeAzureSubscriptionProvider';
|
|
11
|
-
declare module 'vscode' {
|
|
12
|
-
/**
|
|
13
|
-
* Represents parameters for creating a session based on a WWW-Authenticate header value.
|
|
14
|
-
* This is used when an API returns a 401 with a WWW-Authenticate header indicating
|
|
15
|
-
* that additional authentication is required. The details of which will be passed down
|
|
16
|
-
* to the authentication provider to create a session.
|
|
17
|
-
*
|
|
18
|
-
* @note The authorization provider must support handling challenges and specifically
|
|
19
|
-
* the challenges in this WWW-Authenticate value.
|
|
20
|
-
* @note For more information on WWW-Authenticate please see https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/WWW-Authenticate
|
|
21
|
-
*/
|
|
22
|
-
interface AuthenticationWwwAuthenticateRequest {
|
|
23
|
-
/**
|
|
24
|
-
* The raw WWW-Authenticate header value that triggered this challenge.
|
|
25
|
-
* This will be parsed by the authentication provider to extract the necessary
|
|
26
|
-
* challenge information.
|
|
27
|
-
*/
|
|
28
|
-
readonly wwwAuthenticate: string;
|
|
29
|
-
/**
|
|
30
|
-
* The fallback scopes to use if no scopes are found in the WWW-Authenticate header.
|
|
31
|
-
*/
|
|
32
|
-
readonly fallbackScopes?: readonly string[];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Namespace for authentication.
|
|
36
|
-
*/
|
|
37
|
-
namespace authentication {
|
|
38
|
-
/**
|
|
39
|
-
* Get an authentication session matching the desired scopes or request. Rejects if a provider with providerId is not
|
|
40
|
-
* registered, or if the user does not consent to sharing authentication information with the extension. If there
|
|
41
|
-
* are multiple sessions with the same scopes, the user will be shown a quickpick to select which account they would like to use.
|
|
42
|
-
*
|
|
43
|
-
* Built-in auth providers include:
|
|
44
|
-
* * 'github' - For GitHub.com
|
|
45
|
-
* * 'microsoft' For both personal & organizational Microsoft accounts
|
|
46
|
-
* * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server
|
|
47
|
-
* * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds
|
|
48
|
-
*
|
|
49
|
-
* @param providerId The id of the provider to use
|
|
50
|
-
* @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider.
|
|
51
|
-
* @param options The {@link AuthenticationGetSessionOptions} to use
|
|
52
|
-
* @returns A thenable that resolves to an authentication session or undefined if a silent flow was used and no session was found
|
|
53
|
-
*/
|
|
54
|
-
function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
|
|
55
|
-
}
|
|
56
|
-
}
|
package/dist/esm/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from './AzureDevOpsSubscriptionProvider';
|
|
|
7
7
|
export * from './AzureSubscription';
|
|
8
8
|
export * from './AzureSubscriptionProvider';
|
|
9
9
|
export * from './AzureTenant';
|
|
10
|
+
export * from './getSessionFromVSCode';
|
|
10
11
|
export * from './NotSignedInError';
|
|
11
12
|
export * from './signInToTenant';
|
|
12
13
|
export * from './utils/configuredAzureEnv';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type * as vscode from "vscode";
|
|
1
2
|
import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
|
|
2
3
|
import type { AzureTenant } from "../AzureTenant";
|
|
3
4
|
/**
|
|
5
|
+
* @param subscriptionProvider The {@link AzureSubscriptionProvider} to use
|
|
6
|
+
* @param account (Optional) The account to get unauthenticated tenants for
|
|
4
7
|
* @returns list of tenants that VS Code doesn't have sessions for
|
|
5
8
|
*/
|
|
6
|
-
export declare function getUnauthenticatedTenants(subscriptionProvider: AzureSubscriptionProvider): Promise<AzureTenant[]>;
|
|
9
|
+
export declare function getUnauthenticatedTenants(subscriptionProvider: AzureSubscriptionProvider, account?: vscode.AuthenticationSessionAccountInformation): Promise<AzureTenant[]>;
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
/**
|
|
6
|
+
* @param subscriptionProvider The {@link AzureSubscriptionProvider} to use
|
|
7
|
+
* @param account (Optional) The account to get unauthenticated tenants for
|
|
6
8
|
* @returns list of tenants that VS Code doesn't have sessions for
|
|
7
9
|
*/
|
|
8
|
-
export async function getUnauthenticatedTenants(subscriptionProvider) {
|
|
9
|
-
const tenants = await subscriptionProvider.getTenants();
|
|
10
|
+
export async function getUnauthenticatedTenants(subscriptionProvider, account) {
|
|
11
|
+
const tenants = await subscriptionProvider.getTenants(account);
|
|
10
12
|
const unauthenticatedTenants = [];
|
|
11
13
|
for await (const tenant of tenants) {
|
|
12
14
|
if (!await subscriptionProvider.isSignedIn(tenant.tenantId, tenant.account)) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as vscode from 'vscode';
|
|
2
|
+
import type { GetSubscriptionsFilter } from '../AzureSubscriptionProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Check if an object is a {@link GetSubscriptionsFilter} with a tenantId.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isGetSubscriptionsTenantFilter(obj: unknown): obj is GetSubscriptionsFilter & {
|
|
7
|
+
tenantId: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Check if an object is a {@link GetSubscriptionsFilter} with an account.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isGetSubscriptionsAccountFilter(obj: unknown): obj is GetSubscriptionsFilter & {
|
|
13
|
+
account: vscode.AuthenticationSessionAccountInformation;
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.md in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if an object is a {@link GetSubscriptionsFilter} with a tenantId.
|
|
7
|
+
*/
|
|
8
|
+
export function isGetSubscriptionsTenantFilter(obj) {
|
|
9
|
+
if (typeof obj === 'object' && !!obj && 'tenantId' in obj && typeof obj.tenantId === 'string' && !!obj.tenantId) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if an object is a {@link GetSubscriptionsFilter} with an account.
|
|
16
|
+
*/
|
|
17
|
+
export function isGetSubscriptionsAccountFilter(obj) {
|
|
18
|
+
if (typeof obj === 'object' && !!obj && 'account' in obj && typeof obj.account === 'object' && !!obj.account) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=isGetSubscriptionsFilter.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": "5.
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"description": "Azure authentication helpers for Visual Studio Code",
|
|
6
6
|
"tags": [
|
|
7
7
|
"azure",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "npm run build:esm && npm run build:cjs",
|
|
28
28
|
"build:esm": "tsc -p ./",
|
|
29
|
-
"build:cjs": "tsc -p ./ --outDir ./dist/cjs --module nodenext --moduleResolution nodenext",
|
|
29
|
+
"build:cjs": "tsc -p ./ --outDir ./dist/cjs --module nodenext --moduleResolution nodenext --declaration false",
|
|
30
30
|
"lint": "eslint --ext .ts .",
|
|
31
31
|
"lint-fix": "eslint --ext .ts . --fix",
|
|
32
32
|
"test": "node ./dist/cjs/test/runTest.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/glob": "^8.1.0",
|
|
43
43
|
"@types/mocha": "^7.0.2",
|
|
44
44
|
"@types/node": "^18.18.7",
|
|
45
|
-
"@types/vscode": "1.
|
|
45
|
+
"@types/vscode": "1.105.0",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
47
47
|
"@vscode/test-electron": "^2.3.8",
|
|
48
48
|
"eslint": "^8.34.0",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type * as vscode from 'vscode';
|
|
2
|
-
/**
|
|
3
|
-
* Represents a means of obtaining authentication data for an Azure subscription.
|
|
4
|
-
*/
|
|
5
|
-
export interface AzureAuthentication {
|
|
6
|
-
/**
|
|
7
|
-
* Gets a VS Code authentication session for an Azure subscription.
|
|
8
|
-
* Always uses the default scope, `https://management.azure.com/.default/` and respects `microsoft-sovereign-cloud.environment` setting.
|
|
9
|
-
*
|
|
10
|
-
* @returns A VS Code authentication session or undefined, if none could be obtained.
|
|
11
|
-
*/
|
|
12
|
-
getSession(): vscode.ProviderResult<vscode.AuthenticationSession>;
|
|
13
|
-
/**
|
|
14
|
-
* Gets a VS Code authentication session for an Azure subscription.
|
|
15
|
-
*
|
|
16
|
-
* @param scopeListOrRequest - The scopes or request for which the authentication is needed.
|
|
17
|
-
*
|
|
18
|
-
* @returns A VS Code authentication session or undefined, if none could be obtained.
|
|
19
|
-
*/
|
|
20
|
-
getSessionWithScopes(scopeListOrRequest: string[] | vscode.AuthenticationWwwAuthenticateRequest): vscode.ProviderResult<vscode.AuthenticationSession>;
|
|
21
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Event } from 'vscode';
|
|
2
|
-
import { AzureSubscription } from './AzureSubscription';
|
|
3
|
-
import { AzureSubscriptionProvider, GetSubscriptionsFilter } from './AzureSubscriptionProvider';
|
|
4
|
-
import { AzureTenant } from './AzureTenant';
|
|
5
|
-
export interface AzureDevOpsSubscriptionProviderInitializer {
|
|
6
|
-
/**
|
|
7
|
-
* The resource ID of the Azure DevOps federated service connection,
|
|
8
|
-
* which can be found on the `resourceId` field of the URL at the address bar
|
|
9
|
-
* when viewing the service connection in the Azure DevOps portal
|
|
10
|
-
*/
|
|
11
|
-
serviceConnectionId: string;
|
|
12
|
-
/**
|
|
13
|
-
* The `Tenant ID` field of the service connection properties
|
|
14
|
-
*/
|
|
15
|
-
domain: string;
|
|
16
|
-
/**
|
|
17
|
-
* The `Service Principal Id` field of the service connection properties
|
|
18
|
-
*/
|
|
19
|
-
clientId: string;
|
|
20
|
-
}
|
|
21
|
-
export declare function createAzureDevOpsSubscriptionProviderFactory(initializer: AzureDevOpsSubscriptionProviderInitializer): () => Promise<AzureDevOpsSubscriptionProvider>;
|
|
22
|
-
/**
|
|
23
|
-
* AzureSubscriptionProvider implemented to authenticate via federated DevOps service connection, using workflow identity federation
|
|
24
|
-
* To learn how to configure your DevOps environment to use this provider, refer to the README.md
|
|
25
|
-
* NOTE: This provider is only available when running in an Azure DevOps pipeline
|
|
26
|
-
* Reference: https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation
|
|
27
|
-
*/
|
|
28
|
-
export declare class AzureDevOpsSubscriptionProvider implements AzureSubscriptionProvider {
|
|
29
|
-
private _tokenCredential;
|
|
30
|
-
/**
|
|
31
|
-
* The resource ID of the Azure DevOps federated service connection,
|
|
32
|
-
* which can be found on the `resourceId` field of the URL at the address bar
|
|
33
|
-
* when viewing the service connection in the Azure DevOps portal
|
|
34
|
-
*/
|
|
35
|
-
private _SERVICE_CONNECTION_ID;
|
|
36
|
-
/**
|
|
37
|
-
* The `Tenant ID` field of the service connection properties
|
|
38
|
-
*/
|
|
39
|
-
private _DOMAIN;
|
|
40
|
-
/**
|
|
41
|
-
* The `Service Principal Id` field of the service connection properties
|
|
42
|
-
*/
|
|
43
|
-
private _CLIENT_ID;
|
|
44
|
-
constructor({ serviceConnectionId, domain, clientId }: AzureDevOpsSubscriptionProviderInitializer);
|
|
45
|
-
getSubscriptions(_filter: boolean | GetSubscriptionsFilter): Promise<AzureSubscription[]>;
|
|
46
|
-
isSignedIn(): Promise<boolean>;
|
|
47
|
-
signIn(): Promise<boolean>;
|
|
48
|
-
signOut(): Promise<void>;
|
|
49
|
-
getTenants(): Promise<AzureTenant[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Gets the subscriptions for a given tenant.
|
|
52
|
-
*
|
|
53
|
-
* @param tenantId The tenant ID to get subscriptions for.
|
|
54
|
-
*
|
|
55
|
-
* @returns The list of subscriptions for the tenant.
|
|
56
|
-
*/
|
|
57
|
-
private getSubscriptionsForTenant;
|
|
58
|
-
/**
|
|
59
|
-
* Gets a fully-configured subscription client for a given tenant ID
|
|
60
|
-
*
|
|
61
|
-
* @param tenantId (Optional) The tenant ID to get a client for
|
|
62
|
-
*
|
|
63
|
-
* @returns A client, the credential used by the client, and the authentication function
|
|
64
|
-
*/
|
|
65
|
-
private getSubscriptionClient;
|
|
66
|
-
onDidSignIn: Event<void>;
|
|
67
|
-
onDidSignOut: Event<void>;
|
|
68
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { TokenCredential } from '@azure/core-auth';
|
|
2
|
-
import type { Environment } from '@azure/ms-rest-azure-env';
|
|
3
|
-
import * as vscode from "vscode";
|
|
4
|
-
import { AzureAuthentication } from './AzureAuthentication';
|
|
5
|
-
/**
|
|
6
|
-
* A type representing an Azure subscription ID, not including the tenant ID.
|
|
7
|
-
*/
|
|
8
|
-
export type SubscriptionId = string;
|
|
9
|
-
/**
|
|
10
|
-
* A type representing an Azure tenant ID.
|
|
11
|
-
*/
|
|
12
|
-
export type TenantId = string;
|
|
13
|
-
/**
|
|
14
|
-
* Represents an Azure subscription.
|
|
15
|
-
*/
|
|
16
|
-
export interface AzureSubscription {
|
|
17
|
-
/**
|
|
18
|
-
* Access to the authentication session associated with this subscription.
|
|
19
|
-
*/
|
|
20
|
-
readonly authentication: AzureAuthentication;
|
|
21
|
-
/**
|
|
22
|
-
* The Azure environment to which this subscription belongs.
|
|
23
|
-
*/
|
|
24
|
-
readonly environment: Environment;
|
|
25
|
-
/**
|
|
26
|
-
* Whether this subscription belongs to a custom cloud.
|
|
27
|
-
*/
|
|
28
|
-
readonly isCustomCloud: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* The display name of this subscription.
|
|
31
|
-
*/
|
|
32
|
-
readonly name: string;
|
|
33
|
-
/**
|
|
34
|
-
* The ID of this subscription.
|
|
35
|
-
*/
|
|
36
|
-
readonly subscriptionId: SubscriptionId;
|
|
37
|
-
/**
|
|
38
|
-
* The ID of the tenant to which this subscription belongs.
|
|
39
|
-
*/
|
|
40
|
-
readonly tenantId: TenantId;
|
|
41
|
-
/**
|
|
42
|
-
* The credential for authentication to this subscription. Compatible with Azure track 2 SDKs.
|
|
43
|
-
*/
|
|
44
|
-
readonly credential: TokenCredential;
|
|
45
|
-
/**
|
|
46
|
-
* The account associated with this subscription.
|
|
47
|
-
*/
|
|
48
|
-
readonly account: vscode.AuthenticationSessionAccountInformation;
|
|
49
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type * as vscode from 'vscode';
|
|
2
|
-
import type { AzureSubscription } from './AzureSubscription';
|
|
3
|
-
import type { AzureTenant } from './AzureTenant';
|
|
4
|
-
/**
|
|
5
|
-
* A filter for {@link AzureSubscriptionProvider.getSubscriptions}
|
|
6
|
-
*/
|
|
7
|
-
export type GetSubscriptionsFilter = {
|
|
8
|
-
/**
|
|
9
|
-
* The account to get subscriptions for. If not provided, all accounts the extension
|
|
10
|
-
* currently has access to are used.
|
|
11
|
-
*/
|
|
12
|
-
account?: vscode.AuthenticationSessionAccountInformation;
|
|
13
|
-
/**
|
|
14
|
-
* The tenant to get subscriptions for. If not provided, all tenants for each account
|
|
15
|
-
* are used.
|
|
16
|
-
*/
|
|
17
|
-
tenantId?: string;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* An interface for obtaining Azure subscription information
|
|
21
|
-
*/
|
|
22
|
-
export interface AzureSubscriptionProvider {
|
|
23
|
-
/**
|
|
24
|
-
* Gets a list of tenants available to the user.
|
|
25
|
-
* Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
|
|
26
|
-
*
|
|
27
|
-
* @param account - Optionally pass in a specific account to get tenants for.
|
|
28
|
-
*
|
|
29
|
-
* @returns A list of tenants.
|
|
30
|
-
*/
|
|
31
|
-
getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<AzureTenant[]>;
|
|
32
|
-
/**
|
|
33
|
-
* Gets a list of Azure subscriptions available to the user.
|
|
34
|
-
*
|
|
35
|
-
* @param filter - Whether to filter the list returned. When:
|
|
36
|
-
* - `true`: according to the list returned by `getTenantFilters()` and `getSubscriptionFilters()`.
|
|
37
|
-
* - `false`: return all subscriptions.
|
|
38
|
-
* - `GetSubscriptionsFilter`: according to the values in the filter.
|
|
39
|
-
*
|
|
40
|
-
* Optional, default true.
|
|
41
|
-
*
|
|
42
|
-
* @returns A list of Azure subscriptions.
|
|
43
|
-
*
|
|
44
|
-
* @throws A {@link NotSignedInError} If the user is not signed in to Azure.
|
|
45
|
-
* Use {@link isSignedIn} and/or {@link signIn} before this method to ensure
|
|
46
|
-
* the user is signed in.
|
|
47
|
-
*/
|
|
48
|
-
getSubscriptions(filter: boolean | GetSubscriptionsFilter): Promise<AzureSubscription[]>;
|
|
49
|
-
/**
|
|
50
|
-
* Checks to see if a user is signed in.
|
|
51
|
-
*
|
|
52
|
-
* @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
|
|
53
|
-
*
|
|
54
|
-
* @returns True if the user is signed in, false otherwise.
|
|
55
|
-
*/
|
|
56
|
-
isSignedIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
|
|
57
|
-
/**
|
|
58
|
-
* Asks the user to sign in or pick an account to use.
|
|
59
|
-
*
|
|
60
|
-
* @param tenantId (Optional) Provide to sign in to a specific tenant.
|
|
61
|
-
* @param account (Optional) Provide to sign in to a specific account.
|
|
62
|
-
*
|
|
63
|
-
* @returns True if the user is signed in, false otherwise.
|
|
64
|
-
*/
|
|
65
|
-
signIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
|
|
68
|
-
*/
|
|
69
|
-
onDidSignIn: vscode.Event<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Signs the user out
|
|
72
|
-
*
|
|
73
|
-
* @deprecated Not currently supported by VS Code auth providers
|
|
74
|
-
*
|
|
75
|
-
* @throws Throws an {@link Error} every time
|
|
76
|
-
*/
|
|
77
|
-
signOut(): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
|
|
80
|
-
*/
|
|
81
|
-
onDidSignOut: vscode.Event<void>;
|
|
82
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An error indicating the user is not signed in.
|
|
3
|
-
*/
|
|
4
|
-
export declare class NotSignedInError extends Error {
|
|
5
|
-
readonly isNotSignedInError = true;
|
|
6
|
-
constructor();
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Tests if an object is a `NotSignedInError`. This should be used instead of `instanceof`.
|
|
10
|
-
*
|
|
11
|
-
* @param error The object to test
|
|
12
|
-
*
|
|
13
|
-
* @returns True if the object is a NotSignedInError, false otherwise
|
|
14
|
-
*/
|
|
15
|
-
export declare function isNotSignedInError(error: unknown): error is NotSignedInError;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import * as vscode from 'vscode';
|
|
2
|
-
import { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
|
|
3
|
-
import { AzureSubscriptionProvider, GetSubscriptionsFilter } from './AzureSubscriptionProvider';
|
|
4
|
-
import { AzureTenant } from './AzureTenant';
|
|
5
|
-
/**
|
|
6
|
-
* A class for obtaining Azure subscription information using VSCode's built-in authentication
|
|
7
|
-
* provider.
|
|
8
|
-
*/
|
|
9
|
-
export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable implements AzureSubscriptionProvider {
|
|
10
|
-
private readonly logger?;
|
|
11
|
-
private readonly onDidSignInEmitter;
|
|
12
|
-
private lastSignInEventFired;
|
|
13
|
-
private suppressSignInEvents;
|
|
14
|
-
private readonly onDidSignOutEmitter;
|
|
15
|
-
private lastSignOutEventFired;
|
|
16
|
-
constructor(logger?: vscode.LogOutputChannel | undefined);
|
|
17
|
-
/**
|
|
18
|
-
* Gets a list of tenants available to the user.
|
|
19
|
-
* Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
|
|
20
|
-
*
|
|
21
|
-
* @param account (Optional) A specific account to get tenants for. If not provided, all accounts will be used.
|
|
22
|
-
*
|
|
23
|
-
* @returns A list of tenants.
|
|
24
|
-
*/
|
|
25
|
-
getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<AzureTenant[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Gets a list of Azure subscriptions available to the user.
|
|
28
|
-
*
|
|
29
|
-
* @param filter - Whether to filter the list returned. When:
|
|
30
|
-
* - `true`: according to the list returned by `getTenantFilters()` and `getSubscriptionFilters()`.
|
|
31
|
-
* - `false`: return all subscriptions.
|
|
32
|
-
* - `GetSubscriptionsFilter`: according to the values in the filter.
|
|
33
|
-
*
|
|
34
|
-
* Optional, default true.
|
|
35
|
-
*
|
|
36
|
-
* @returns A list of Azure subscriptions. The list is sorted by subscription name.
|
|
37
|
-
* The list can contain duplicate subscriptions if they come from different accounts.
|
|
38
|
-
*
|
|
39
|
-
* @throws A {@link NotSignedInError} If the user is not signed in to Azure.
|
|
40
|
-
* Use {@link isSignedIn} and/or {@link signIn} before this method to ensure
|
|
41
|
-
* the user is signed in.
|
|
42
|
-
*/
|
|
43
|
-
getSubscriptions(filter?: boolean | GetSubscriptionsFilter): Promise<AzureSubscription[]>;
|
|
44
|
-
/**
|
|
45
|
-
* Checks to see if a user is signed in.
|
|
46
|
-
*
|
|
47
|
-
* @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
|
|
48
|
-
* @param account (Optional) Provide to check if a user is signed in to a specific account.
|
|
49
|
-
*
|
|
50
|
-
* @returns True if the user is signed in, false otherwise.
|
|
51
|
-
*
|
|
52
|
-
* If no tenant or account is provided, then
|
|
53
|
-
* checks all accounts for a session.
|
|
54
|
-
*/
|
|
55
|
-
isSignedIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
|
|
56
|
-
/**
|
|
57
|
-
* Asks the user to sign in or pick an account to use.
|
|
58
|
-
*
|
|
59
|
-
* @param tenantId (Optional) Provide to sign in to a specific tenant.
|
|
60
|
-
* @param account (Optional) Provide to sign in to a specific account.
|
|
61
|
-
*
|
|
62
|
-
* @returns True if the user is signed in, false otherwise.
|
|
63
|
-
*/
|
|
64
|
-
signIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
|
|
67
|
-
*/
|
|
68
|
-
readonly onDidSignIn: vscode.Event<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Signs the user out
|
|
71
|
-
*
|
|
72
|
-
* @deprecated Not currently supported by VS Code auth providers
|
|
73
|
-
*/
|
|
74
|
-
signOut(): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
|
|
77
|
-
*/
|
|
78
|
-
readonly onDidSignOut: vscode.Event<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
|
|
81
|
-
* override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
|
|
82
|
-
* and/or `getTenantFilters()` overridden.
|
|
83
|
-
*
|
|
84
|
-
* If no values are returned by `getTenantFilters()`, then all tenants will be scanned for subscriptions.
|
|
85
|
-
*
|
|
86
|
-
* @returns A list of tenant IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
|
|
87
|
-
*/
|
|
88
|
-
protected getTenantFilters(): Promise<TenantId[]>;
|
|
89
|
-
/**
|
|
90
|
-
* Gets the subscription filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
|
|
91
|
-
* override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
|
|
92
|
-
* and/or `getTenantFilters()` overridden.
|
|
93
|
-
*
|
|
94
|
-
* If no values are returned by `getSubscriptionFilters()`, then all subscriptions will be returned.
|
|
95
|
-
*
|
|
96
|
-
* @returns A list of subscription IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
|
|
97
|
-
*/
|
|
98
|
-
protected getSubscriptionFilters(): Promise<SubscriptionId[]>;
|
|
99
|
-
/**
|
|
100
|
-
* Gets the subscriptions for a given tenant.
|
|
101
|
-
*
|
|
102
|
-
* @param tenantId The tenant ID to get subscriptions for.
|
|
103
|
-
* @param account The account to get the subscriptions for.
|
|
104
|
-
*
|
|
105
|
-
* @returns The list of subscriptions for the tenant.
|
|
106
|
-
*/
|
|
107
|
-
private getSubscriptionsForTenant;
|
|
108
|
-
/**
|
|
109
|
-
* Gets a fully-configured subscription client for a given tenant ID
|
|
110
|
-
*
|
|
111
|
-
* @param tenantId (Optional) The tenant ID to get a client for
|
|
112
|
-
* @param account The account that you would like to get the session for
|
|
113
|
-
*
|
|
114
|
-
* @returns A client, the credential used by the client, and the authentication function
|
|
115
|
-
*/
|
|
116
|
-
private getSubscriptionClient;
|
|
117
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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 scopeOrListOrRequest - 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
|
-
* Use `vscode.AuthenticationWwwAuthenticateRequest` if you need to pass in a challenge (WWW-Authenticate header). Note: Use of `vscode.AuthenticationWwwAuthenticateRequest` requires VS Code 1.105.0 or newer.
|
|
9
|
-
* @param tenantId - (Optional) The tenant ID, will be added to the scopes
|
|
10
|
-
* @param options - see {@link vscode.AuthenticationGetSessionOptions}
|
|
11
|
-
* @returns An authentication session if available, or undefined if there are no sessions
|
|
12
|
-
*/
|
|
13
|
-
export declare function getSessionFromVSCode(scopeOrListOrRequest?: string | string[] | vscode.AuthenticationWwwAuthenticateRequest, tenantId?: string, options?: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined>;
|
package/dist/cjs/src/index.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export * from './AzureAuthentication';
|
|
2
|
-
export * from './AzureDevOpsSubscriptionProvider';
|
|
3
|
-
export * from './AzureSubscription';
|
|
4
|
-
export * from './AzureSubscriptionProvider';
|
|
5
|
-
export * from './AzureTenant';
|
|
6
|
-
export * from './NotSignedInError';
|
|
7
|
-
export * from './signInToTenant';
|
|
8
|
-
export * from './utils/configuredAzureEnv';
|
|
9
|
-
export * from './utils/getUnauthenticatedTenants';
|
|
10
|
-
export * from './VSCodeAzureSubscriptionProvider';
|
|
11
|
-
declare module 'vscode' {
|
|
12
|
-
/**
|
|
13
|
-
* Represents parameters for creating a session based on a WWW-Authenticate header value.
|
|
14
|
-
* This is used when an API returns a 401 with a WWW-Authenticate header indicating
|
|
15
|
-
* that additional authentication is required. The details of which will be passed down
|
|
16
|
-
* to the authentication provider to create a session.
|
|
17
|
-
*
|
|
18
|
-
* @note The authorization provider must support handling challenges and specifically
|
|
19
|
-
* the challenges in this WWW-Authenticate value.
|
|
20
|
-
* @note For more information on WWW-Authenticate please see https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/WWW-Authenticate
|
|
21
|
-
*/
|
|
22
|
-
interface AuthenticationWwwAuthenticateRequest {
|
|
23
|
-
/**
|
|
24
|
-
* The raw WWW-Authenticate header value that triggered this challenge.
|
|
25
|
-
* This will be parsed by the authentication provider to extract the necessary
|
|
26
|
-
* challenge information.
|
|
27
|
-
*/
|
|
28
|
-
readonly wwwAuthenticate: string;
|
|
29
|
-
/**
|
|
30
|
-
* The fallback scopes to use if no scopes are found in the WWW-Authenticate header.
|
|
31
|
-
*/
|
|
32
|
-
readonly fallbackScopes?: readonly string[];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Namespace for authentication.
|
|
36
|
-
*/
|
|
37
|
-
namespace authentication {
|
|
38
|
-
/**
|
|
39
|
-
* Get an authentication session matching the desired scopes or request. Rejects if a provider with providerId is not
|
|
40
|
-
* registered, or if the user does not consent to sharing authentication information with the extension. If there
|
|
41
|
-
* are multiple sessions with the same scopes, the user will be shown a quickpick to select which account they would like to use.
|
|
42
|
-
*
|
|
43
|
-
* Built-in auth providers include:
|
|
44
|
-
* * 'github' - For GitHub.com
|
|
45
|
-
* * 'microsoft' For both personal & organizational Microsoft accounts
|
|
46
|
-
* * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server
|
|
47
|
-
* * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds
|
|
48
|
-
*
|
|
49
|
-
* @param providerId The id of the provider to use
|
|
50
|
-
* @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider.
|
|
51
|
-
* @param options The {@link AuthenticationGetSessionOptions} to use
|
|
52
|
-
* @returns A thenable that resolves to an authentication session or undefined if a silent flow was used and no session was found
|
|
53
|
-
*/
|
|
54
|
-
function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AzureSubscriptionProvider } from "./AzureSubscriptionProvider";
|
|
2
|
-
/**
|
|
3
|
-
* Prompts user to select from a list of unauthenticated tenants.
|
|
4
|
-
* Once selected, requests a new session from VS Code specifially for this tenant.
|
|
5
|
-
*/
|
|
6
|
-
export declare function signInToTenant(subscriptionProvider: AzureSubscriptionProvider): Promise<void>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as azureEnv from '@azure/ms-rest-azure-env';
|
|
2
|
-
import * as vscode from 'vscode';
|
|
3
|
-
/**
|
|
4
|
-
* Gets the configured Azure environment.
|
|
5
|
-
*
|
|
6
|
-
* @returns The configured Azure environment from the settings in the built-in authentication provider extension
|
|
7
|
-
*/
|
|
8
|
-
export declare function getConfiguredAzureEnv(): azureEnv.Environment & {
|
|
9
|
-
isCustomCloud: boolean;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Sets the configured Azure cloud.
|
|
13
|
-
*
|
|
14
|
-
* @param cloud Use `'AzureCloud'` or `undefined` for public Azure cloud, `'ChinaCloud'` for Azure China, or `'USGovernment'` for Azure US Government.
|
|
15
|
-
* 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}.
|
|
16
|
-
*
|
|
17
|
-
* @param target (Optional) The configuration target to use, by default {@link vscode.ConfigurationTarget.Global}.
|
|
18
|
-
*/
|
|
19
|
-
export declare function setConfiguredAzureEnv(cloud: 'AzureCloud' | 'ChinaCloud' | 'USGovernment' | undefined | azureEnv.EnvironmentParameters, target?: vscode.ConfigurationTarget): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Gets the ID of the authentication provider configured to be used
|
|
22
|
-
* @returns The provider ID to use, either `'microsoft'` or `'microsoft-sovereign-cloud'`
|
|
23
|
-
*/
|
|
24
|
-
export declare function getConfiguredAuthProviderId(): string;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
|
|
2
|
-
import type { AzureTenant } from "../AzureTenant";
|
|
3
|
-
/**
|
|
4
|
-
* @returns list of tenants that VS Code doesn't have sessions for
|
|
5
|
-
*/
|
|
6
|
-
export declare function getUnauthenticatedTenants(subscriptionProvider: AzureSubscriptionProvider): Promise<AzureTenant[]>;
|