@microsoft/vscode-azext-azureauth 4.2.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/{out → dist/cjs}/src/AzureAuthentication.d.ts +2 -2
  2. package/dist/cjs/src/AzureDevOpsSubscriptionProvider.js +216 -0
  3. package/dist/cjs/src/NotSignedInError.js +63 -0
  4. package/dist/cjs/src/VSCodeAzureSubscriptionProvider.js +342 -0
  5. package/{out → dist/cjs}/src/getSessionFromVSCode.d.ts +3 -3
  6. package/dist/cjs/src/getSessionFromVSCode.js +108 -0
  7. package/dist/cjs/src/index.d.ts +56 -0
  8. package/{out → dist/cjs}/src/index.js +1 -1
  9. package/dist/cjs/src/signInToTenant.js +79 -0
  10. package/dist/cjs/src/utils/configuredAzureEnv.js +128 -0
  11. package/dist/cjs/src/utils/getUnauthenticatedTenants.js +21 -0
  12. package/dist/esm/src/AzureAuthentication.d.ts +21 -0
  13. package/dist/esm/src/AzureAuthentication.js +6 -0
  14. package/dist/esm/src/AzureDevOpsSubscriptionProvider.d.ts +68 -0
  15. package/dist/esm/src/AzureDevOpsSubscriptionProvider.js +211 -0
  16. package/dist/esm/src/AzureSubscription.d.ts +49 -0
  17. package/dist/esm/src/AzureSubscription.js +6 -0
  18. package/dist/esm/src/AzureSubscriptionProvider.d.ts +82 -0
  19. package/dist/esm/src/AzureSubscriptionProvider.js +6 -0
  20. package/dist/esm/src/AzureTenant.d.ts +5 -0
  21. package/dist/esm/src/AzureTenant.js +6 -0
  22. package/dist/esm/src/NotSignedInError.d.ts +15 -0
  23. package/{out → dist/esm}/src/NotSignedInError.js +4 -9
  24. package/dist/esm/src/VSCodeAzureSubscriptionProvider.d.ts +117 -0
  25. package/dist/esm/src/VSCodeAzureSubscriptionProvider.js +305 -0
  26. package/dist/esm/src/getSessionFromVSCode.d.ts +13 -0
  27. package/dist/esm/src/getSessionFromVSCode.js +72 -0
  28. package/dist/esm/src/index.d.ts +56 -0
  29. package/{out/src/index.d.ts → dist/esm/src/index.js} +6 -1
  30. package/dist/esm/src/signInToTenant.d.ts +6 -0
  31. package/dist/esm/src/signInToTenant.js +43 -0
  32. package/dist/esm/src/utils/configuredAzureEnv.d.ts +24 -0
  33. package/dist/esm/src/utils/configuredAzureEnv.js +90 -0
  34. package/dist/esm/src/utils/getUnauthenticatedTenants.d.ts +6 -0
  35. package/dist/esm/src/utils/getUnauthenticatedTenants.js +18 -0
  36. package/dist/esm/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +2 -0
  37. package/dist/esm/src/utils/isAuthenticationWwwAuthenticateRequest.js +12 -0
  38. package/package.json +13 -12
  39. package/out/src/AzureDevOpsSubscriptionProvider.js +0 -252
  40. package/out/src/VSCodeAzureSubscriptionProvider.js +0 -384
  41. package/out/src/getSessionFromVSCode.js +0 -76
  42. package/out/src/signInToTenant.js +0 -64
  43. package/out/src/utils/configuredAzureEnv.js +0 -94
  44. package/out/src/utils/getUnauthenticatedTenants.js +0 -52
  45. /package/{out → dist/cjs}/src/AzureAuthentication.js +0 -0
  46. /package/{out → dist/cjs}/src/AzureDevOpsSubscriptionProvider.d.ts +0 -0
  47. /package/{out → dist/cjs}/src/AzureSubscription.d.ts +0 -0
  48. /package/{out → dist/cjs}/src/AzureSubscription.js +0 -0
  49. /package/{out → dist/cjs}/src/AzureSubscriptionProvider.d.ts +0 -0
  50. /package/{out → dist/cjs}/src/AzureSubscriptionProvider.js +0 -0
  51. /package/{out → dist/cjs}/src/AzureTenant.d.ts +0 -0
  52. /package/{out → dist/cjs}/src/AzureTenant.js +0 -0
  53. /package/{out → dist/cjs}/src/NotSignedInError.d.ts +0 -0
  54. /package/{out → dist/cjs}/src/VSCodeAzureSubscriptionProvider.d.ts +0 -0
  55. /package/{out → dist/cjs}/src/signInToTenant.d.ts +0 -0
  56. /package/{out → dist/cjs}/src/utils/configuredAzureEnv.d.ts +0 -0
  57. /package/{out → dist/cjs}/src/utils/getUnauthenticatedTenants.d.ts +0 -0
  58. /package/{out → dist/cjs}/src/utils/isAuthenticationWwwAuthenticateRequest.d.ts +0 -0
  59. /package/{out → dist/cjs}/src/utils/isAuthenticationWwwAuthenticateRequest.js +0 -0
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.getSessionFromVSCode = getSessionFromVSCode;
41
+ const vscode = __importStar(require("vscode"));
42
+ const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
43
+ const isAuthenticationWwwAuthenticateRequest_1 = require("./utils/isAuthenticationWwwAuthenticateRequest");
44
+ function ensureEndingSlash(value) {
45
+ return value.endsWith('/') ? value : `${value}/`;
46
+ }
47
+ function getResourceScopes(scopes) {
48
+ if (scopes === undefined || scopes === "" || scopes.length === 0) {
49
+ scopes = ensureEndingSlash((0, configuredAzureEnv_1.getConfiguredAzureEnv)().managementEndpointUrl);
50
+ }
51
+ const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
52
+ .map((scope) => {
53
+ if (scope.endsWith('.default')) {
54
+ return scope;
55
+ }
56
+ else {
57
+ return `${scope}.default`;
58
+ }
59
+ });
60
+ return Array.from(new Set(arrScopes));
61
+ }
62
+ function addTenantIdScope(scopes, tenantId) {
63
+ const scopeSet = new Set(scopes);
64
+ scopeSet.add(`VSCODE_TENANT:${tenantId}`);
65
+ return Array.from(scopeSet);
66
+ }
67
+ function getModifiedScopes(scopes, tenantId) {
68
+ let scopeArr = getResourceScopes(scopes);
69
+ if (tenantId) {
70
+ scopeArr = addTenantIdScope(scopeArr, tenantId);
71
+ }
72
+ return scopeArr;
73
+ }
74
+ /**
75
+ * Deconstructs and rebuilds the scopes arg in order to use the above utils to modify the scopes array.
76
+ * And then returns the proper type to pass directly to vscode.authentication.getSession
77
+ */
78
+ function formScopesArg(scopeOrListOrRequest, tenantId) {
79
+ const isChallenge = (0, isAuthenticationWwwAuthenticateRequest_1.isAuthenticationWwwAuthenticateRequest)(scopeOrListOrRequest);
80
+ let initialScopeList = undefined;
81
+ if (typeof scopeOrListOrRequest === 'string' && !!scopeOrListOrRequest) {
82
+ initialScopeList = [scopeOrListOrRequest];
83
+ }
84
+ else if (Array.isArray(scopeOrListOrRequest)) {
85
+ initialScopeList = scopeOrListOrRequest;
86
+ }
87
+ else if (isChallenge) {
88
+ // `scopeOrListOrRequest.fallbackScopes` being readonly forces us to rebuild the array
89
+ initialScopeList = scopeOrListOrRequest.fallbackScopes ? Array.from(scopeOrListOrRequest.fallbackScopes) : undefined;
90
+ }
91
+ const modifiedScopeList = getModifiedScopes(initialScopeList, tenantId);
92
+ return isChallenge ? { fallbackScopes: modifiedScopeList, wwwAuthenticate: scopeOrListOrRequest.wwwAuthenticate } : modifiedScopeList;
93
+ }
94
+ /**
95
+ * Wraps {@link vscode.authentication.getSession} and handles:
96
+ * * Passing the configured auth provider id
97
+ * * Getting the list of scopes, adding the tenant id to the scope list if needed
98
+ *
99
+ * @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.
100
+ * 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.
101
+ * @param tenantId - (Optional) The tenant ID, will be added to the scopes
102
+ * @param options - see {@link vscode.AuthenticationGetSessionOptions}
103
+ * @returns An authentication session if available, or undefined if there are no sessions
104
+ */
105
+ async function getSessionFromVSCode(scopeOrListOrRequest, tenantId, options) {
106
+ return await vscode.authentication.getSession((0, configuredAzureEnv_1.getConfiguredAuthProviderId)(), formScopesArg(scopeOrListOrRequest, tenantId), options);
107
+ }
108
+ //# sourceMappingURL=getSessionFromVSCode.js.map
@@ -0,0 +1,56 @@
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
+ }
@@ -20,9 +20,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  __exportStar(require("./AzureAuthentication"), exports);
22
22
  __exportStar(require("./AzureDevOpsSubscriptionProvider"), exports);
23
- __exportStar(require("./AzureTenant"), exports);
24
23
  __exportStar(require("./AzureSubscription"), exports);
25
24
  __exportStar(require("./AzureSubscriptionProvider"), exports);
25
+ __exportStar(require("./AzureTenant"), exports);
26
26
  __exportStar(require("./NotSignedInError"), exports);
27
27
  __exportStar(require("./signInToTenant"), exports);
28
28
  __exportStar(require("./utils/configuredAzureEnv"), exports);
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.signInToTenant = signInToTenant;
41
+ const vscode = __importStar(require("vscode"));
42
+ const getUnauthenticatedTenants_1 = require("./utils/getUnauthenticatedTenants");
43
+ /**
44
+ * Prompts user to select from a list of unauthenticated tenants.
45
+ * Once selected, requests a new session from VS Code specifially for this tenant.
46
+ */
47
+ async function signInToTenant(subscriptionProvider) {
48
+ const tenantId = await pickTenant(subscriptionProvider);
49
+ if (tenantId) {
50
+ await subscriptionProvider.signIn(tenantId);
51
+ }
52
+ }
53
+ async function pickTenant(subscriptionProvider) {
54
+ const pick = await vscode.window.showQuickPick(getPicks(subscriptionProvider), {
55
+ placeHolder: 'Select a Tenant (Directory) to Sign In To', // TODO: localize
56
+ matchOnDescription: true, // allow searching by tenantId
57
+ ignoreFocusOut: true,
58
+ });
59
+ return pick?.tenant.tenantId;
60
+ }
61
+ async function getPicks(subscriptionProvider) {
62
+ const unauthenticatedTenants = await (0, getUnauthenticatedTenants_1.getUnauthenticatedTenants)(subscriptionProvider);
63
+ const duplicateTenants = new Set(unauthenticatedTenants
64
+ .filter((tenant, index, self) => index !== self.findIndex(t => t.tenantId === tenant.tenantId))
65
+ .map(tenant => tenant.tenantId));
66
+ const isDuplicate = (tenantId) => duplicateTenants.has(tenantId);
67
+ const picks = unauthenticatedTenants
68
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
+ .sort((a, b) => (a.displayName).localeCompare(b.displayName))
70
+ .map(tenant => ({
71
+ label: tenant.displayName ?? '',
72
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
73
+ description: `${tenant.tenantId}${isDuplicate(tenant.tenantId) ? ` (${tenant.account.label})` : ''}`,
74
+ detail: tenant.defaultDomain ?? '',
75
+ tenant,
76
+ }));
77
+ return picks;
78
+ }
79
+ //# sourceMappingURL=signInToTenant.js.map
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.getConfiguredAzureEnv = getConfiguredAzureEnv;
41
+ exports.setConfiguredAzureEnv = setConfiguredAzureEnv;
42
+ exports.getConfiguredAuthProviderId = getConfiguredAuthProviderId;
43
+ const azureEnv = __importStar(require("@azure/ms-rest-azure-env")); // This package is so small that it's not worth lazy loading
44
+ const vscode = __importStar(require("vscode"));
45
+ // These strings come from https://github.com/microsoft/vscode/blob/eac16e9b63a11885b538db3e0b533a02a2fb8143/extensions/microsoft-authentication/package.json#L40-L99
46
+ const CustomCloudConfigurationSection = 'microsoft-sovereign-cloud';
47
+ const CloudEnvironmentSettingName = 'environment';
48
+ const CustomEnvironmentSettingName = 'customEnvironment';
49
+ var CloudEnvironmentSettingValue;
50
+ (function (CloudEnvironmentSettingValue) {
51
+ CloudEnvironmentSettingValue["ChinaCloud"] = "ChinaCloud";
52
+ CloudEnvironmentSettingValue["USGovernment"] = "USGovernment";
53
+ CloudEnvironmentSettingValue["Custom"] = "custom";
54
+ })(CloudEnvironmentSettingValue || (CloudEnvironmentSettingValue = {}));
55
+ /**
56
+ * Gets the configured Azure environment.
57
+ *
58
+ * @returns The configured Azure environment from the settings in the built-in authentication provider extension
59
+ */
60
+ function getConfiguredAzureEnv() {
61
+ const authProviderConfig = vscode.workspace.getConfiguration(CustomCloudConfigurationSection);
62
+ const environmentSettingValue = authProviderConfig.get(CloudEnvironmentSettingName);
63
+ if (environmentSettingValue === CloudEnvironmentSettingValue.ChinaCloud) {
64
+ return {
65
+ ...azureEnv.Environment.ChinaCloud,
66
+ isCustomCloud: false,
67
+ };
68
+ }
69
+ else if (environmentSettingValue === CloudEnvironmentSettingValue.USGovernment) {
70
+ return {
71
+ ...azureEnv.Environment.USGovernment,
72
+ isCustomCloud: false,
73
+ };
74
+ }
75
+ else if (environmentSettingValue === CloudEnvironmentSettingValue.Custom) {
76
+ const customCloud = authProviderConfig.get(CustomEnvironmentSettingName);
77
+ if (customCloud) {
78
+ return {
79
+ ...new azureEnv.Environment(customCloud),
80
+ isCustomCloud: true,
81
+ };
82
+ }
83
+ throw new Error(vscode.l10n.t('The custom cloud choice is not configured. Please configure the setting `{0}.{1}`.', CustomCloudConfigurationSection, CustomEnvironmentSettingName));
84
+ }
85
+ return {
86
+ ...azureEnv.Environment.get(azureEnv.Environment.AzureCloud.name),
87
+ isCustomCloud: false,
88
+ };
89
+ }
90
+ /**
91
+ * Sets the configured Azure cloud.
92
+ *
93
+ * @param cloud Use `'AzureCloud'` or `undefined` for public Azure cloud, `'ChinaCloud'` for Azure China, or `'USGovernment'` for Azure US Government.
94
+ * 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}.
95
+ *
96
+ * @param target (Optional) The configuration target to use, by default {@link vscode.ConfigurationTarget.Global}.
97
+ */
98
+ async function setConfiguredAzureEnv(cloud, target = vscode.ConfigurationTarget.Global) {
99
+ const authProviderConfig = vscode.workspace.getConfiguration(CustomCloudConfigurationSection);
100
+ if (typeof cloud === 'undefined' || !cloud) {
101
+ // Use public cloud implicitly--set `environment` setting to `undefined`
102
+ await authProviderConfig.update(CloudEnvironmentSettingName, undefined, target);
103
+ }
104
+ else if (typeof cloud === 'string' && cloud === 'AzureCloud') {
105
+ // Use public cloud explicitly--set `environment` setting to `undefined`
106
+ await authProviderConfig.update(CloudEnvironmentSettingName, undefined, target);
107
+ }
108
+ else if (typeof cloud === 'string') {
109
+ // Use a sovereign cloud--set the `environment` setting to the specified value
110
+ await authProviderConfig.update(CloudEnvironmentSettingName, cloud, target);
111
+ }
112
+ else if (typeof cloud === 'object') {
113
+ // use a custom cloud--set the `environment` setting to `custom` and the `customEnvironment` setting to the specified value
114
+ await authProviderConfig.update(CloudEnvironmentSettingName, CloudEnvironmentSettingValue.Custom, target);
115
+ await authProviderConfig.update(CustomEnvironmentSettingName, cloud, target);
116
+ }
117
+ else {
118
+ throw new Error(`Invalid cloud value: ${JSON.stringify(cloud)}`);
119
+ }
120
+ }
121
+ /**
122
+ * Gets the ID of the authentication provider configured to be used
123
+ * @returns The provider ID to use, either `'microsoft'` or `'microsoft-sovereign-cloud'`
124
+ */
125
+ function getConfiguredAuthProviderId() {
126
+ return getConfiguredAzureEnv().name === azureEnv.Environment.AzureCloud.name ? 'microsoft' : 'microsoft-sovereign-cloud';
127
+ }
128
+ //# sourceMappingURL=configuredAzureEnv.js.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getUnauthenticatedTenants = getUnauthenticatedTenants;
8
+ /**
9
+ * @returns list of tenants that VS Code doesn't have sessions for
10
+ */
11
+ async function getUnauthenticatedTenants(subscriptionProvider) {
12
+ const tenants = await subscriptionProvider.getTenants();
13
+ const unauthenticatedTenants = [];
14
+ for await (const tenant of tenants) {
15
+ if (!await subscriptionProvider.isSignedIn(tenant.tenantId, tenant.account)) {
16
+ unauthenticatedTenants.push(tenant);
17
+ }
18
+ }
19
+ return unauthenticatedTenants;
20
+ }
21
+ //# sourceMappingURL=getUnauthenticatedTenants.js.map
@@ -0,0 +1,21 @@
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
+ }
@@ -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=AzureAuthentication.js.map
@@ -0,0 +1,68 @@
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
+ }