@microsoft/vscode-azext-azureauth 4.2.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{out → dist/cjs}/src/AzureAuthentication.d.ts +2 -2
- package/dist/cjs/src/AzureDevOpsSubscriptionProvider.js +216 -0
- package/dist/cjs/src/NotSignedInError.js +63 -0
- package/dist/cjs/src/VSCodeAzureSubscriptionProvider.js +342 -0
- package/{out → dist/cjs}/src/getSessionFromVSCode.d.ts +3 -3
- package/dist/cjs/src/getSessionFromVSCode.js +108 -0
- package/dist/cjs/src/index.d.ts +56 -0
- package/{out → dist/cjs}/src/index.js +1 -1
- package/dist/cjs/src/signInToTenant.js +79 -0
- package/dist/cjs/src/utils/configuredAzureEnv.js +128 -0
- package/dist/cjs/src/utils/getUnauthenticatedTenants.js +21 -0
- package/dist/esm/src/AzureAuthentication.d.ts +21 -0
- package/dist/esm/src/AzureAuthentication.js +6 -0
- package/dist/esm/src/AzureDevOpsSubscriptionProvider.d.ts +68 -0
- package/dist/esm/src/AzureDevOpsSubscriptionProvider.js +211 -0
- package/dist/esm/src/AzureSubscription.d.ts +49 -0
- package/dist/esm/src/AzureSubscription.js +6 -0
- package/dist/esm/src/AzureSubscriptionProvider.d.ts +82 -0
- package/dist/esm/src/AzureSubscriptionProvider.js +6 -0
- package/dist/esm/src/AzureTenant.d.ts +5 -0
- package/dist/esm/src/AzureTenant.js +6 -0
- package/dist/esm/src/NotSignedInError.d.ts +15 -0
- package/{out → dist/esm}/src/NotSignedInError.js +4 -9
- package/dist/esm/src/VSCodeAzureSubscriptionProvider.d.ts +117 -0
- package/dist/esm/src/VSCodeAzureSubscriptionProvider.js +305 -0
- package/dist/esm/src/getSessionFromVSCode.d.ts +13 -0
- package/dist/esm/src/getSessionFromVSCode.js +72 -0
- package/dist/esm/src/index.d.ts +56 -0
- package/{out/src/index.d.ts → dist/esm/src/index.js} +6 -1
- package/dist/esm/src/signInToTenant.d.ts +6 -0
- package/dist/esm/src/signInToTenant.js +43 -0
- package/dist/esm/src/utils/configuredAzureEnv.d.ts +24 -0
- package/dist/esm/src/utils/configuredAzureEnv.js +90 -0
- package/dist/esm/src/utils/getUnauthenticatedTenants.d.ts +6 -0
- package/dist/esm/src/utils/getUnauthenticatedTenants.js +18 -0
- package/dist/esm/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +2 -0
- package/dist/esm/src/utils/isAuthenticationWwwAuthenticateRequest.js +12 -0
- package/package.json +13 -12
- package/out/src/AzureDevOpsSubscriptionProvider.js +0 -252
- package/out/src/VSCodeAzureSubscriptionProvider.js +0 -384
- package/out/src/getSessionFromVSCode.js +0 -76
- package/out/src/signInToTenant.js +0 -64
- package/out/src/utils/configuredAzureEnv.js +0 -94
- package/out/src/utils/getUnauthenticatedTenants.js +0 -52
- /package/{out → dist/cjs}/src/AzureAuthentication.js +0 -0
- /package/{out → dist/cjs}/src/AzureDevOpsSubscriptionProvider.d.ts +0 -0
- /package/{out → dist/cjs}/src/AzureSubscription.d.ts +0 -0
- /package/{out → dist/cjs}/src/AzureSubscription.js +0 -0
- /package/{out → dist/cjs}/src/AzureSubscriptionProvider.d.ts +0 -0
- /package/{out → dist/cjs}/src/AzureSubscriptionProvider.js +0 -0
- /package/{out → dist/cjs}/src/AzureTenant.d.ts +0 -0
- /package/{out → dist/cjs}/src/AzureTenant.js +0 -0
- /package/{out → dist/cjs}/src/NotSignedInError.d.ts +0 -0
- /package/{out → dist/cjs}/src/VSCodeAzureSubscriptionProvider.d.ts +0 -0
- /package/{out → dist/cjs}/src/signInToTenant.d.ts +0 -0
- /package/{out → dist/cjs}/src/utils/configuredAzureEnv.d.ts +0 -0
- /package/{out → dist/cjs}/src/utils/getUnauthenticatedTenants.d.ts +0 -0
- /package/{out → dist/cjs}/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +0 -0
- /package/{out → dist/cjs}/src/utils/isAuthenticationWwwAuthenticateRequest.js +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { Disposable } from 'vscode';
|
|
6
|
+
import { getConfiguredAzureEnv } from './utils/configuredAzureEnv';
|
|
7
|
+
let azureDevOpsSubscriptionProvider;
|
|
8
|
+
export function createAzureDevOpsSubscriptionProviderFactory(initializer) {
|
|
9
|
+
return async () => {
|
|
10
|
+
azureDevOpsSubscriptionProvider ??= new AzureDevOpsSubscriptionProvider(initializer);
|
|
11
|
+
return azureDevOpsSubscriptionProvider;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* AzureSubscriptionProvider implemented to authenticate via federated DevOps service connection, using workflow identity federation
|
|
16
|
+
* To learn how to configure your DevOps environment to use this provider, refer to the README.md
|
|
17
|
+
* NOTE: This provider is only available when running in an Azure DevOps pipeline
|
|
18
|
+
* Reference: https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation
|
|
19
|
+
*/
|
|
20
|
+
export class AzureDevOpsSubscriptionProvider {
|
|
21
|
+
_tokenCredential;
|
|
22
|
+
/**
|
|
23
|
+
* The resource ID of the Azure DevOps federated service connection,
|
|
24
|
+
* which can be found on the `resourceId` field of the URL at the address bar
|
|
25
|
+
* when viewing the service connection in the Azure DevOps portal
|
|
26
|
+
*/
|
|
27
|
+
_SERVICE_CONNECTION_ID;
|
|
28
|
+
/**
|
|
29
|
+
* The `Tenant ID` field of the service connection properties
|
|
30
|
+
*/
|
|
31
|
+
_DOMAIN;
|
|
32
|
+
/**
|
|
33
|
+
* The `Service Principal Id` field of the service connection properties
|
|
34
|
+
*/
|
|
35
|
+
_CLIENT_ID;
|
|
36
|
+
constructor({ serviceConnectionId, domain, clientId }) {
|
|
37
|
+
if (!serviceConnectionId || !domain || !clientId) {
|
|
38
|
+
throw new Error(`Missing initializer values to identify Azure DevOps federated service connection\n
|
|
39
|
+
Values provided:\n
|
|
40
|
+
serviceConnectionId: ${serviceConnectionId ? "✅" : "❌"}\n
|
|
41
|
+
domain: ${domain ? "✅" : "❌"}\n
|
|
42
|
+
clientId: ${clientId ? "✅" : "❌"}\n
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
45
|
+
this._SERVICE_CONNECTION_ID = serviceConnectionId;
|
|
46
|
+
this._DOMAIN = domain;
|
|
47
|
+
this._CLIENT_ID = clientId;
|
|
48
|
+
}
|
|
49
|
+
async getSubscriptions(_filter) {
|
|
50
|
+
// ignore the filter setting because not every consumer of this provider will use the Resources extension
|
|
51
|
+
const results = [];
|
|
52
|
+
for (const tenant of await this.getTenants()) {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
|
+
const tenantId = tenant.tenantId;
|
|
55
|
+
results.push(...await this.getSubscriptionsForTenant(tenantId));
|
|
56
|
+
}
|
|
57
|
+
const sortSubscriptions = (subscriptions) => subscriptions.sort((a, b) => a.name.localeCompare(b.name));
|
|
58
|
+
return sortSubscriptions(results);
|
|
59
|
+
}
|
|
60
|
+
async isSignedIn() {
|
|
61
|
+
return !!this._tokenCredential;
|
|
62
|
+
}
|
|
63
|
+
async signIn() {
|
|
64
|
+
this._tokenCredential = await getTokenCredential(this._SERVICE_CONNECTION_ID, this._DOMAIN, this._CLIENT_ID);
|
|
65
|
+
return !!this._tokenCredential;
|
|
66
|
+
}
|
|
67
|
+
async signOut() {
|
|
68
|
+
this._tokenCredential = undefined;
|
|
69
|
+
}
|
|
70
|
+
async getTenants() {
|
|
71
|
+
return [{
|
|
72
|
+
tenantId: this._tokenCredential?.tenantId,
|
|
73
|
+
account: {
|
|
74
|
+
id: "test-account-id",
|
|
75
|
+
label: "test-account",
|
|
76
|
+
}
|
|
77
|
+
}];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets the subscriptions for a given tenant.
|
|
81
|
+
*
|
|
82
|
+
* @param tenantId The tenant ID to get subscriptions for.
|
|
83
|
+
*
|
|
84
|
+
* @returns The list of subscriptions for the tenant.
|
|
85
|
+
*/
|
|
86
|
+
async getSubscriptionsForTenant(tenantId) {
|
|
87
|
+
const { client, credential, authentication } = await this.getSubscriptionClient(tenantId);
|
|
88
|
+
const environment = getConfiguredAzureEnv();
|
|
89
|
+
const subscriptions = [];
|
|
90
|
+
for await (const subscription of client.subscriptions.list()) {
|
|
91
|
+
subscriptions.push({
|
|
92
|
+
authentication,
|
|
93
|
+
environment: environment,
|
|
94
|
+
credential: credential,
|
|
95
|
+
isCustomCloud: environment.isCustomCloud,
|
|
96
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
97
|
+
name: subscription.displayName,
|
|
98
|
+
subscriptionId: subscription.subscriptionId,
|
|
99
|
+
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
|
100
|
+
tenantId,
|
|
101
|
+
account: {
|
|
102
|
+
id: "test-account-id",
|
|
103
|
+
label: "test-account",
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return subscriptions;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets a fully-configured subscription client for a given tenant ID
|
|
111
|
+
*
|
|
112
|
+
* @param tenantId (Optional) The tenant ID to get a client for
|
|
113
|
+
*
|
|
114
|
+
* @returns A client, the credential used by the client, and the authentication function
|
|
115
|
+
*/
|
|
116
|
+
async getSubscriptionClient(_tenantId, scopes) {
|
|
117
|
+
const armSubs = await import('@azure/arm-resources-subscriptions');
|
|
118
|
+
if (!this._tokenCredential) {
|
|
119
|
+
throw new Error('Not signed in');
|
|
120
|
+
}
|
|
121
|
+
const accessToken = (await this._tokenCredential?.getToken("https://management.azure.com/.default"))?.token || '';
|
|
122
|
+
const getSession = () => {
|
|
123
|
+
return {
|
|
124
|
+
accessToken,
|
|
125
|
+
id: this._tokenCredential?.tenantId || '',
|
|
126
|
+
account: {
|
|
127
|
+
id: this._tokenCredential?.tenantId || '',
|
|
128
|
+
label: this._tokenCredential?.tenantId || '',
|
|
129
|
+
},
|
|
130
|
+
tenantId: this._tokenCredential?.tenantId || '',
|
|
131
|
+
scopes: scopes || [],
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
client: new armSubs.SubscriptionClient(this._tokenCredential),
|
|
136
|
+
credential: this._tokenCredential,
|
|
137
|
+
authentication: {
|
|
138
|
+
getSession,
|
|
139
|
+
getSessionWithScopes: getSession,
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
onDidSignIn = () => { return new Disposable(() => { }); };
|
|
144
|
+
onDidSignOut = () => { return new Disposable(() => { }); };
|
|
145
|
+
}
|
|
146
|
+
/*
|
|
147
|
+
* @param serviceConnectionId The resource ID of the Azure DevOps federated service connection,
|
|
148
|
+
* which can be found on the `resourceId` field of the URL at the address bar when viewing the service connection in the Azure DevOps portal
|
|
149
|
+
* @param domain The `Tenant ID` field of the service connection properties
|
|
150
|
+
* @param clientId The `Service Principal Id` field of the service connection properties
|
|
151
|
+
*/
|
|
152
|
+
async function getTokenCredential(serviceConnectionId, domain, clientId) {
|
|
153
|
+
if (!process.env.AGENT_BUILDDIRECTORY) {
|
|
154
|
+
// Assume that AGENT_BUILDDIRECTORY is set if running in an Azure DevOps pipeline.
|
|
155
|
+
// So when not running in an Azure DevOps pipeline, throw an error since we cannot use the DevOps federated service connection credential.
|
|
156
|
+
throw new Error(`Cannot create DevOps federated service connection credential outside of an Azure DevOps pipeline.`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.log(`Creating DevOps federated service connection credential for service connection..`);
|
|
160
|
+
// Pre-defined DevOps variable reference: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops
|
|
161
|
+
const systemAccessToken = process.env.SYSTEM_ACCESSTOKEN;
|
|
162
|
+
const teamFoundationCollectionUri = process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI;
|
|
163
|
+
const teamProjectId = process.env.SYSTEM_TEAMPROJECTID;
|
|
164
|
+
const planId = process.env.SYSTEM_PLANID;
|
|
165
|
+
const jobId = process.env.SYSTEM_JOBID;
|
|
166
|
+
if (!systemAccessToken || !teamFoundationCollectionUri || !teamProjectId || !planId || !jobId) {
|
|
167
|
+
throw new Error(`Azure DevOps environment variables are not set.\n
|
|
168
|
+
process.env.SYSTEM_ACCESSTOKEN: ${process.env.SYSTEM_ACCESSTOKEN ? "✅" : "❌"}\n
|
|
169
|
+
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI: ${process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI ? "✅" : "❌"}\n
|
|
170
|
+
process.env.SYSTEM_TEAMPROJECTID: ${process.env.SYSTEM_TEAMPROJECTID ? "✅" : "❌"}\n
|
|
171
|
+
process.env.SYSTEM_PLANID: ${process.env.SYSTEM_PLANID ? "✅" : "❌"}\n
|
|
172
|
+
process.env.SYSTEM_JOBID: ${process.env.SYSTEM_JOBID ? "✅" : "❌"}\n
|
|
173
|
+
REMEMBER: process.env.SYSTEM_ACCESSTOKEN must be explicitly mapped!\n
|
|
174
|
+
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken
|
|
175
|
+
`);
|
|
176
|
+
}
|
|
177
|
+
const oidcRequestUrl = `${teamFoundationCollectionUri}${teamProjectId}/_apis/distributedtask/hubs/build/plans/${planId}/jobs/${jobId}/oidctoken?api-version=7.1-preview.1&serviceConnectionId=${serviceConnectionId}`;
|
|
178
|
+
const { ClientAssertionCredential } = await import("@azure/identity");
|
|
179
|
+
return new ClientAssertionCredential(domain, clientId, async () => await requestOidcToken(oidcRequestUrl, systemAccessToken));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* API reference: https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/oidctoken/create
|
|
184
|
+
*/
|
|
185
|
+
async function requestOidcToken(oidcRequestUrl, systemAccessToken) {
|
|
186
|
+
const { ServiceClient } = await import('@azure/core-client');
|
|
187
|
+
const { createHttpHeaders, createPipelineRequest } = await import('@azure/core-rest-pipeline');
|
|
188
|
+
const genericClient = new ServiceClient();
|
|
189
|
+
const request = createPipelineRequest({
|
|
190
|
+
url: oidcRequestUrl,
|
|
191
|
+
method: "POST",
|
|
192
|
+
headers: createHttpHeaders({
|
|
193
|
+
"Content-Type": "application/json",
|
|
194
|
+
"Authorization": `Bearer ${systemAccessToken}`
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
const response = await genericClient.sendRequest(request);
|
|
198
|
+
const body = response.bodyAsText?.toString() || "";
|
|
199
|
+
if (response.status !== 200) {
|
|
200
|
+
throw new Error(`Failed to get OIDC token:\n
|
|
201
|
+
Response status: ${response.status}\n
|
|
202
|
+
Response body: ${body}\n
|
|
203
|
+
Response headers: ${JSON.stringify(response.headers.toJSON())}
|
|
204
|
+
`);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.log(`Successfully got OIDC token with status ${response.status}`);
|
|
208
|
+
}
|
|
209
|
+
return JSON.parse(body).oidcToken;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=AzureDevOpsSubscriptionProvider.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=AzureSubscription.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=AzureSubscriptionProvider.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=AzureTenant.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
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,22 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*---------------------------------------------------------------------------------------------
|
|
3
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
4
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
|
|
7
|
-
exports.NotSignedInError = void 0;
|
|
8
|
-
exports.isNotSignedInError = isNotSignedInError;
|
|
9
|
-
const vscode = require("vscode");
|
|
5
|
+
import * as vscode from 'vscode';
|
|
10
6
|
/**
|
|
11
7
|
* An error indicating the user is not signed in.
|
|
12
8
|
*/
|
|
13
|
-
class NotSignedInError extends Error {
|
|
9
|
+
export class NotSignedInError extends Error {
|
|
10
|
+
isNotSignedInError = true;
|
|
14
11
|
constructor() {
|
|
15
12
|
super(vscode.l10n.t('You are not signed in to an Azure account. Please sign in.'));
|
|
16
|
-
this.isNotSignedInError = true;
|
|
17
13
|
}
|
|
18
14
|
}
|
|
19
|
-
exports.NotSignedInError = NotSignedInError;
|
|
20
15
|
/**
|
|
21
16
|
* Tests if an object is a `NotSignedInError`. This should be used instead of `instanceof`.
|
|
22
17
|
*
|
|
@@ -24,7 +19,7 @@ exports.NotSignedInError = NotSignedInError;
|
|
|
24
19
|
*
|
|
25
20
|
* @returns True if the object is a NotSignedInError, false otherwise
|
|
26
21
|
*/
|
|
27
|
-
function isNotSignedInError(error) {
|
|
22
|
+
export function isNotSignedInError(error) {
|
|
28
23
|
return !!error && typeof error === 'object' && error.isNotSignedInError === true;
|
|
29
24
|
}
|
|
30
25
|
//# sourceMappingURL=NotSignedInError.js.map
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
}
|