@microsoft/vscode-azext-azureauth 5.1.1 → 6.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +9 -79
- package/dist/cjs/src/contracts/AzureAccount.js +7 -0
- package/dist/cjs/src/contracts/AzureSubscriptionProviderRequestOptions.js +48 -0
- package/dist/cjs/src/index.js +13 -10
- package/dist/cjs/src/providers/AzureDevOpsSubscriptionProvider.js +178 -0
- package/dist/cjs/src/providers/AzureSubscriptionProviderBase.js +393 -0
- package/dist/cjs/src/providers/VSCodeAzureSubscriptionProvider.js +269 -0
- package/dist/cjs/src/utils/Limiter.js +41 -0
- package/dist/cjs/src/{NotSignedInError.js → utils/NotSignedInError.js} +3 -2
- package/dist/cjs/src/utils/configuredAzureEnv.js +14 -16
- package/dist/cjs/src/utils/dedupeSubscriptions.js +27 -0
- package/dist/cjs/src/utils/getMetricsForTelemetry.js +47 -0
- package/dist/cjs/src/{getSessionFromVSCode.js → utils/getSessionFromVSCode.js} +5 -2
- package/dist/cjs/src/utils/getSignalForToken.js +29 -0
- package/dist/cjs/src/utils/map/CaselessMap.js +71 -0
- package/dist/cjs/src/utils/map/TwoKeyCaselessMap.js +194 -0
- package/dist/cjs/src/utils/screen.js +62 -0
- package/dist/cjs/src/{signInToTenant.js → utils/signInToTenant.js} +15 -13
- package/dist/cjs/src/utils/tryGetTokenExpiration.js +25 -0
- package/dist/esm/src/contracts/AzureAccount.d.ts +5 -0
- package/dist/esm/src/contracts/AzureAccount.js +6 -0
- package/dist/esm/src/{AzureAuthentication.d.ts → contracts/AzureAuthentication.d.ts} +1 -1
- package/dist/esm/src/{AzureSubscription.d.ts → contracts/AzureSubscription.d.ts} +4 -4
- package/dist/esm/src/contracts/AzureSubscriptionProvider.d.ts +112 -0
- package/dist/esm/src/contracts/AzureSubscriptionProviderRequestOptions.d.ts +103 -0
- package/dist/esm/src/contracts/AzureSubscriptionProviderRequestOptions.js +44 -0
- package/dist/esm/src/contracts/AzureTenant.d.ts +15 -0
- package/dist/esm/src/index.d.ts +13 -10
- package/dist/esm/src/index.js +13 -10
- package/dist/esm/src/providers/AzureDevOpsSubscriptionProvider.d.ts +68 -0
- package/dist/esm/src/providers/AzureDevOpsSubscriptionProvider.js +140 -0
- package/dist/esm/src/providers/AzureSubscriptionProviderBase.d.ts +74 -0
- package/dist/esm/src/providers/AzureSubscriptionProviderBase.js +356 -0
- package/dist/esm/src/providers/VSCodeAzureSubscriptionProvider.d.ts +70 -0
- package/dist/esm/src/providers/VSCodeAzureSubscriptionProvider.js +232 -0
- package/dist/esm/src/utils/Limiter.d.ts +9 -0
- package/dist/esm/src/utils/Limiter.js +37 -0
- package/dist/esm/src/{NotSignedInError.d.ts → utils/NotSignedInError.d.ts} +2 -2
- package/dist/esm/src/{NotSignedInError.js → utils/NotSignedInError.js} +3 -2
- package/dist/esm/src/utils/configuredAzureEnv.d.ts +7 -4
- package/dist/esm/src/utils/configuredAzureEnv.js +14 -16
- package/dist/esm/src/utils/dedupeSubscriptions.d.ts +14 -0
- package/dist/esm/src/utils/dedupeSubscriptions.js +24 -0
- package/dist/esm/src/utils/getMetricsForTelemetry.d.ts +32 -0
- package/dist/esm/src/utils/getMetricsForTelemetry.js +44 -0
- package/dist/esm/src/{getSessionFromVSCode.js → utils/getSessionFromVSCode.js} +5 -2
- package/dist/esm/src/utils/getSignalForToken.d.ts +7 -0
- package/dist/esm/src/utils/getSignalForToken.js +26 -0
- package/dist/esm/src/utils/map/CaselessMap.d.ts +28 -0
- package/dist/esm/src/utils/map/CaselessMap.js +67 -0
- package/dist/esm/src/utils/map/TwoKeyCaselessMap.d.ts +49 -0
- package/dist/esm/src/utils/map/TwoKeyCaselessMap.js +190 -0
- package/dist/esm/src/utils/screen.d.ts +9 -0
- package/dist/esm/src/utils/screen.js +59 -0
- package/dist/esm/src/utils/signInToTenant.d.ts +7 -0
- package/dist/esm/src/{signInToTenant.js → utils/signInToTenant.js} +16 -14
- package/dist/esm/src/utils/tryGetTokenExpiration.d.ts +2 -0
- package/dist/esm/src/utils/tryGetTokenExpiration.js +22 -0
- package/package.json +33 -23
- package/AzureFederatedCredentialsGuide.md +0 -174
- package/dist/cjs/src/AzureDevOpsSubscriptionProvider.js +0 -215
- package/dist/cjs/src/VSCodeAzureSubscriptionProvider.js +0 -395
- package/dist/cjs/src/utils/getUnauthenticatedTenants.js +0 -23
- package/dist/cjs/src/utils/isGetSubscriptionsFilter.js +0 -27
- package/dist/esm/src/AzureDevOpsSubscriptionProvider.d.ts +0 -68
- package/dist/esm/src/AzureDevOpsSubscriptionProvider.js +0 -210
- package/dist/esm/src/AzureSubscriptionProvider.d.ts +0 -82
- package/dist/esm/src/AzureTenant.d.ts +0 -5
- package/dist/esm/src/VSCodeAzureSubscriptionProvider.d.ts +0 -116
- package/dist/esm/src/VSCodeAzureSubscriptionProvider.js +0 -358
- package/dist/esm/src/signInToTenant.d.ts +0 -6
- package/dist/esm/src/utils/getUnauthenticatedTenants.d.ts +0 -9
- package/dist/esm/src/utils/getUnauthenticatedTenants.js +0 -20
- package/dist/esm/src/utils/isGetSubscriptionsFilter.d.ts +0 -14
- package/dist/esm/src/utils/isGetSubscriptionsFilter.js +0 -23
- /package/dist/cjs/src/{AzureAuthentication.js → contracts/AzureAuthentication.js} +0 -0
- /package/dist/cjs/src/{AzureSubscription.js → contracts/AzureSubscription.js} +0 -0
- /package/dist/cjs/src/{AzureSubscriptionProvider.js → contracts/AzureSubscriptionProvider.js} +0 -0
- /package/dist/cjs/src/{AzureTenant.js → contracts/AzureTenant.js} +0 -0
- /package/dist/esm/src/{AzureAuthentication.js → contracts/AzureAuthentication.js} +0 -0
- /package/dist/esm/src/{AzureSubscription.js → contracts/AzureSubscription.js} +0 -0
- /package/dist/esm/src/{AzureSubscriptionProvider.js → contracts/AzureSubscriptionProvider.js} +0 -0
- /package/dist/esm/src/{AzureTenant.js → contracts/AzureTenant.js} +0 -0
- /package/dist/esm/src/{getSessionFromVSCode.d.ts → utils/getSessionFromVSCode.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 6.0.0-alpha.2 - 2026-02-09
|
|
4
|
+
|
|
5
|
+
* Fix copy all optional properties in `ExtendedEnvironment` constructor
|
|
6
|
+
|
|
7
|
+
## 6.0.0 - 2025-12-15
|
|
8
|
+
|
|
9
|
+
* [#2119](https://github.com/microsoft/vscode-azuretools/pull/2119) Complete rewrite of the auth package. Adds caching, parallelization, and smarter filtering.
|
|
10
|
+
|
|
3
11
|
## 5.1.1 - 2025-10-28
|
|
4
12
|
|
|
5
13
|
* [#2111](https://github.com/microsoft/vscode-azuretools/pull/2111) Same as https://github.com/microsoft/vscode-azuretools/pull/2110 but a better fix.
|
package/README.md
CHANGED
|
@@ -4,79 +4,9 @@ This package provides a simple way to authenticate to Azure and receive Azure su
|
|
|
4
4
|
|
|
5
5
|
## Azure Subscription Provider
|
|
6
6
|
|
|
7
|
-
The `AzureSubscriptionProvider` interface describes the functions of this package.
|
|
7
|
+
The [`AzureSubscriptionProvider`](./src/contracts/AzureSubscriptionProvider.ts) interface describes the functions of this package.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* An interface for obtaining Azure subscription information
|
|
12
|
-
*/
|
|
13
|
-
export interface AzureSubscriptionProvider {
|
|
14
|
-
/**
|
|
15
|
-
* Gets a list of tenants available to the user.
|
|
16
|
-
* Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
|
|
17
|
-
*
|
|
18
|
-
* @returns A list of tenants.
|
|
19
|
-
*/
|
|
20
|
-
getTenants(): Promise<TenantIdDescription[]>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Gets a list of Azure subscriptions available to the user.
|
|
24
|
-
*
|
|
25
|
-
* @param filter - Whether to filter the list returned. When:
|
|
26
|
-
* - `true`: according to the list returned by `getTenantFilters()` and `getSubscriptionFilters()`.
|
|
27
|
-
* - `false`: return all subscriptions.
|
|
28
|
-
* - `GetSubscriptionsFilter`: according to the values in the filter.
|
|
29
|
-
*
|
|
30
|
-
* Optional, default true.
|
|
31
|
-
*
|
|
32
|
-
* @returns A list of Azure subscriptions.
|
|
33
|
-
*
|
|
34
|
-
* @throws A {@link NotSignedInError} If the user is not signed in to Azure.
|
|
35
|
-
* Use {@link isSignedIn} and/or {@link signIn} before this method to ensure
|
|
36
|
-
* the user is signed in.
|
|
37
|
-
*/
|
|
38
|
-
getSubscriptions(filter: boolean): Promise<AzureSubscription[]>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Checks to see if a user is signed in.
|
|
42
|
-
*
|
|
43
|
-
* @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
|
|
44
|
-
*
|
|
45
|
-
* @returns True if the user is signed in, false otherwise.
|
|
46
|
-
*/
|
|
47
|
-
isSignedIn(tenantId?: string): Promise<boolean>;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Asks the user to sign in or pick an account to use.
|
|
51
|
-
*
|
|
52
|
-
* @param tenantId (Optional) Provide to sign in to a specific tenant.
|
|
53
|
-
*
|
|
54
|
-
* @returns True if the user is signed in, false otherwise.
|
|
55
|
-
*/
|
|
56
|
-
signIn(tenantId?: string): Promise<boolean>;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
|
|
60
|
-
*/
|
|
61
|
-
onDidSignIn: vscode.Event<void>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Signs the user out
|
|
65
|
-
*
|
|
66
|
-
* @deprecated Not currently supported by VS Code auth providers
|
|
67
|
-
*
|
|
68
|
-
* @throws Throws an {@link Error} every time
|
|
69
|
-
*/
|
|
70
|
-
signOut(): Promise<void>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
|
|
74
|
-
*/
|
|
75
|
-
onDidSignOut: vscode.Event<void>;
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
If the caller calls `getSubscriptions()` when the user is not signed in, a `NotSignedInError` will be thrown. You can check to see if a caught error is an instance of this error with `isNotSignedInError()`.
|
|
9
|
+
If the caller calls `getAvailableSubscriptions()` or `getAccounts()` when the user is not signed in, a `NotSignedInError` will be thrown. You can check to see if a caught error is an instance of this error with `isNotSignedInError()`.
|
|
80
10
|
|
|
81
11
|
## Azure Cloud Configuration
|
|
82
12
|
Two methods are available for controlling the VSCode settings that determine what cloud is connected to when enumerating subscriptions.
|
|
@@ -104,7 +34,7 @@ export declare function setConfiguredAzureEnv(cloud: string | azureEnv.Environme
|
|
|
104
34
|
|
|
105
35
|
## Azure DevOps Subscription Provider
|
|
106
36
|
|
|
107
|
-
The auth package also exports `AzureDevOpsSubscriptionProvider
|
|
37
|
+
The auth package also exports [`AzureDevOpsSubscriptionProvider`](./src/providers/AzureDevOpsSubscriptionProvider.ts), a class which implements the `AzureSubscriptionProvider` interface, which authenticates via
|
|
108
38
|
a federated Azure DevOps service connection, using [workflow identity federation](https://learn.microsoft.com/entra/workload-id/workload-identity-federation).
|
|
109
39
|
|
|
110
40
|
This provider only works when running in the context of an Azure DevOps pipeline. It can be used to run end-to-end tests that require authentication to Azure,
|
|
@@ -114,19 +44,19 @@ The constructor expects an initializer object with three values set to identify
|
|
|
114
44
|
These are:
|
|
115
45
|
|
|
116
46
|
- `serviceConnectionId`: The resource ID of your service connection, 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
|
|
117
|
-
- `
|
|
47
|
+
- `tenantId`: The `Tenant ID` field of the service connection properties, which can be accessed by clicking "Edit" on the service connection page
|
|
118
48
|
- `clientId`: The `Service Principal Id` field of the service connection properties, which can be accessed by clicking "Edit" on the service connection page
|
|
119
49
|
|
|
120
50
|
Here is an example code of how you might use `AzureDevOpsSubscriptionProvider`:
|
|
121
51
|
|
|
122
52
|
```typescript
|
|
123
|
-
import { AzureDevOpsSubscriptionProviderInitializer, AzureDevOpsSubscriptionProvider } from "@microsoft/vscode-azext-azureauth";
|
|
53
|
+
import { AzureDevOpsSubscriptionProviderInitializer, AzureDevOpsSubscriptionProvider } from "@microsoft/vscode-azext-azureauth/azdo";
|
|
124
54
|
|
|
125
55
|
const initializer: AzureDevOpsSubscriptionProviderInitializer = {
|
|
126
56
|
serviceConnectionId: "<REPLACE_WITH_SERVICE_CONNECTION_ID>",
|
|
127
|
-
|
|
57
|
+
tenantId: "<REPLACE_WITH_TENANT_ID>",
|
|
128
58
|
clientId: "<REPLACE_WITH_CLIENT_ID>",
|
|
129
|
-
}
|
|
59
|
+
};
|
|
130
60
|
|
|
131
61
|
const subscriptionProvider = new AzureDevOpsSubscriptionProvider(initializer);
|
|
132
62
|
|
|
@@ -135,9 +65,9 @@ if (!signedIn) {
|
|
|
135
65
|
throw new Error("Couldn't sign in");
|
|
136
66
|
}
|
|
137
67
|
|
|
138
|
-
const subscriptions = await subscriptionProvider.
|
|
68
|
+
const subscriptions = await subscriptionProvider.getAvailableSubscriptions();
|
|
139
69
|
|
|
140
|
-
// logic on the subscriptions
|
|
70
|
+
// logic on the subscriptions objects
|
|
141
71
|
```
|
|
142
72
|
|
|
143
73
|
For more detailed steps on how to setup your Azure environment to use workflow identity federation and use this `AzureDevOpsSubscriptionProvider` object effectively,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=AzureAccount.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
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.DefaultOptions = exports.DefaultSignInOptions = void 0;
|
|
8
|
+
exports.getCoalescenceKey = getCoalescenceKey;
|
|
9
|
+
/**
|
|
10
|
+
* Default options for signing in to a tenant
|
|
11
|
+
*/
|
|
12
|
+
exports.DefaultSignInOptions = {
|
|
13
|
+
clearSessionPreference: false,
|
|
14
|
+
promptIfNeeded: true,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The default options when getting available subscriptions.
|
|
18
|
+
* @note This same value also is passed as the default to all the get* methods, since it
|
|
19
|
+
* is a superset of all of the available options.
|
|
20
|
+
*/
|
|
21
|
+
exports.DefaultOptions = {
|
|
22
|
+
filter: true,
|
|
23
|
+
noCache: false,
|
|
24
|
+
token: undefined,
|
|
25
|
+
dedupe: true,
|
|
26
|
+
maximumTenants: 10,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Gets a promise coalescence key for the given {@link GetAvailableSubscriptionsOptions}.
|
|
30
|
+
* @param options The options to get the key for
|
|
31
|
+
* @returns A string key for coalescing promises, or undefined if coalescing is not applicable
|
|
32
|
+
* @internal This should not be used by external code. This is placed here so it can be adjacent
|
|
33
|
+
* to the {@link GetAvailableSubscriptionsOptions} type, but should be used only by internal
|
|
34
|
+
* implementations
|
|
35
|
+
*/
|
|
36
|
+
function getCoalescenceKey(options) {
|
|
37
|
+
// Never coalesce if there is a cancellation token--no way to do it safely
|
|
38
|
+
if (options.token) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return Object
|
|
42
|
+
.keys(options)
|
|
43
|
+
.filter(k => k !== 'token') // ignore token
|
|
44
|
+
.sort()
|
|
45
|
+
.map(k => `${k}:${options[k] ?? exports.DefaultOptions[k]}`)
|
|
46
|
+
.join(',');
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=AzureSubscriptionProviderRequestOptions.js.map
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -18,15 +18,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./AzureSubscription"), exports);
|
|
24
|
-
__exportStar(require("./AzureSubscriptionProvider"), exports);
|
|
25
|
-
__exportStar(require("./AzureTenant"), exports);
|
|
26
|
-
|
|
27
|
-
__exportStar(require("./
|
|
28
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./contracts/AzureAccount"), exports);
|
|
22
|
+
__exportStar(require("./contracts/AzureAuthentication"), exports);
|
|
23
|
+
__exportStar(require("./contracts/AzureSubscription"), exports);
|
|
24
|
+
__exportStar(require("./contracts/AzureSubscriptionProvider"), exports);
|
|
25
|
+
__exportStar(require("./contracts/AzureTenant"), exports);
|
|
26
|
+
// The `AzureDevOpsSubscriptionProvider` is intentionally not exported, it must be imported from `'@microsoft/vscode-azext-azureauth/azdo'`
|
|
27
|
+
__exportStar(require("./providers/AzureSubscriptionProviderBase"), exports);
|
|
28
|
+
__exportStar(require("./providers/VSCodeAzureSubscriptionProvider"), exports);
|
|
29
29
|
__exportStar(require("./utils/configuredAzureEnv"), exports);
|
|
30
|
-
__exportStar(require("./utils/
|
|
31
|
-
__exportStar(require("./
|
|
30
|
+
__exportStar(require("./utils/dedupeSubscriptions"), exports);
|
|
31
|
+
__exportStar(require("./utils/getMetricsForTelemetry"), exports);
|
|
32
|
+
__exportStar(require("./utils/getSessionFromVSCode"), exports);
|
|
33
|
+
__exportStar(require("./utils/NotSignedInError"), exports);
|
|
34
|
+
__exportStar(require("./utils/signInToTenant"), exports);
|
|
32
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,178 @@
|
|
|
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.AzureDevOpsSubscriptionProvider = void 0;
|
|
41
|
+
exports.createAzureDevOpsSubscriptionProviderFactory = createAzureDevOpsSubscriptionProviderFactory;
|
|
42
|
+
const azureEnv = __importStar(require("@azure/ms-rest-azure-env")); // This package is so small that it's not worth lazy loading
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
const isAuthenticationWwwAuthenticateRequest_1 = require("../utils/isAuthenticationWwwAuthenticateRequest");
|
|
45
|
+
const NotSignedInError_1 = require("../utils/NotSignedInError");
|
|
46
|
+
const AzureSubscriptionProviderBase_1 = require("./AzureSubscriptionProviderBase");
|
|
47
|
+
let azureDevOpsSubscriptionProvider;
|
|
48
|
+
function createAzureDevOpsSubscriptionProviderFactory(initializer) {
|
|
49
|
+
return () => {
|
|
50
|
+
azureDevOpsSubscriptionProvider ??= new AzureDevOpsSubscriptionProvider(initializer);
|
|
51
|
+
return Promise.resolve(azureDevOpsSubscriptionProvider);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
let armSubs;
|
|
55
|
+
let azIdentity;
|
|
56
|
+
/**
|
|
57
|
+
* AzureSubscriptionProvider implemented to authenticate via federated DevOps service connection, using workflow identity federation
|
|
58
|
+
* To learn how to configure your DevOps environment to use this provider, refer to the README.md
|
|
59
|
+
* NOTE: This provider is only available when running in an Azure DevOps pipeline
|
|
60
|
+
* Reference: https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation
|
|
61
|
+
*/
|
|
62
|
+
class AzureDevOpsSubscriptionProvider extends AzureSubscriptionProviderBase_1.AzureSubscriptionProviderBase {
|
|
63
|
+
_tokenCredential;
|
|
64
|
+
_serviceConnectionId;
|
|
65
|
+
_tenantId;
|
|
66
|
+
_clientId;
|
|
67
|
+
constructor({ serviceConnectionId, tenantId, clientId }, logger) {
|
|
68
|
+
super(logger);
|
|
69
|
+
if (!serviceConnectionId || !tenantId || !clientId) {
|
|
70
|
+
throw new Error(`Missing initializer values to identify Azure DevOps federated service connection\n
|
|
71
|
+
Values provided:\n
|
|
72
|
+
serviceConnectionId: ${serviceConnectionId ? "✅" : "❌"}\n
|
|
73
|
+
tenantId: ${tenantId ? "✅" : "❌"}\n
|
|
74
|
+
clientId: ${clientId ? "✅" : "❌"}\n
|
|
75
|
+
`);
|
|
76
|
+
}
|
|
77
|
+
this._serviceConnectionId = serviceConnectionId;
|
|
78
|
+
this._tenantId = tenantId;
|
|
79
|
+
this._clientId = clientId;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* For {@link AzureSubscriptionProviderBase}, this event will never fire
|
|
83
|
+
*/
|
|
84
|
+
onRefreshSuggested = () => { return { dispose: () => { } }; };
|
|
85
|
+
/**
|
|
86
|
+
* For {@link AzureSubscriptionProviderBase}, this returns a single account with a fixed ID and label
|
|
87
|
+
*/
|
|
88
|
+
getAccounts() {
|
|
89
|
+
return Promise.resolve([
|
|
90
|
+
{
|
|
91
|
+
id: 'test-account-id',
|
|
92
|
+
label: 'test-account',
|
|
93
|
+
}
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* For {@link AzureSubscriptionProviderBase}, this returns an empty array
|
|
98
|
+
*/
|
|
99
|
+
getUnauthenticatedTenantsForAccount() {
|
|
100
|
+
// For DevOps federated service connection, there is only one tenant associated with the service principal, and we will be authenticated
|
|
101
|
+
return Promise.resolve([]);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* For {@link AzureSubscriptionProviderBase}, this returns a single tenant associated with the service principal
|
|
105
|
+
*/
|
|
106
|
+
getTenantsForAccount(account) {
|
|
107
|
+
return Promise.resolve([{
|
|
108
|
+
tenantId: this._tenantId,
|
|
109
|
+
account: account,
|
|
110
|
+
}]);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @inheritdoc
|
|
114
|
+
*/
|
|
115
|
+
async signIn() {
|
|
116
|
+
this._tokenCredential ??= await getTokenCredential(this._serviceConnectionId, this._tenantId, this._clientId);
|
|
117
|
+
return !!this._tokenCredential;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @inheritdoc
|
|
121
|
+
*/
|
|
122
|
+
async getSubscriptionClient(tenant) {
|
|
123
|
+
if (!this._tokenCredential) {
|
|
124
|
+
throw new NotSignedInError_1.NotSignedInError();
|
|
125
|
+
}
|
|
126
|
+
const getSessionWithScopes = async (scopes) => {
|
|
127
|
+
if ((0, isAuthenticationWwwAuthenticateRequest_1.isAuthenticationWwwAuthenticateRequest)(scopes)) {
|
|
128
|
+
throw new Error('Getting session with challenge is not supported in AzureDevOpsSubscriptionProvider.');
|
|
129
|
+
}
|
|
130
|
+
const token = await this._tokenCredential?.getToken(scopes);
|
|
131
|
+
if (!token) {
|
|
132
|
+
throw new NotSignedInError_1.NotSignedInError();
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
accessToken: token.token,
|
|
136
|
+
id: crypto.randomUUID(),
|
|
137
|
+
account: tenant.account,
|
|
138
|
+
scopes: scopes,
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
armSubs ??= await import('@azure/arm-resources-subscriptions');
|
|
142
|
+
return {
|
|
143
|
+
client: new armSubs.SubscriptionClient(this._tokenCredential),
|
|
144
|
+
credential: this._tokenCredential,
|
|
145
|
+
authentication: {
|
|
146
|
+
getSession: () => {
|
|
147
|
+
return getSessionWithScopes([azureEnv.Environment.AzureCloud.managementEndpointUrl + '/.default']);
|
|
148
|
+
},
|
|
149
|
+
getSessionWithScopes: getSessionWithScopes,
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.AzureDevOpsSubscriptionProvider = AzureDevOpsSubscriptionProvider;
|
|
155
|
+
/**
|
|
156
|
+
* @param serviceConnectionId The resource ID of the Azure DevOps federated service connection,
|
|
157
|
+
* 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
|
|
158
|
+
* @param tenantId The `Tenant ID` field of the service connection properties
|
|
159
|
+
* @param clientId The `Service Principal Id` field of the service connection properties
|
|
160
|
+
*/
|
|
161
|
+
async function getTokenCredential(serviceConnectionId, tenantId, clientId) {
|
|
162
|
+
if (!process.env.AGENT_BUILDDIRECTORY) {
|
|
163
|
+
// Assume that AGENT_BUILDDIRECTORY is set if running in an Azure DevOps pipeline.
|
|
164
|
+
// So when not running in an Azure DevOps pipeline, throw an error since we cannot use the DevOps federated service connection credential.
|
|
165
|
+
throw new Error('Cannot create DevOps federated service connection credential outside of an Azure DevOps pipeline.');
|
|
166
|
+
}
|
|
167
|
+
else if (!process.env.SYSTEM_ACCESSTOKEN) {
|
|
168
|
+
throw new Error('Cannot create DevOps federated service connection credential because the SYSTEM_ACCESSTOKEN environment variable is not set.');
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
172
|
+
// @ts-ignore @azure/identity contains a bug where this type mismatches between CJS and ESM, we must ignore it. We also can't do @ts-expect-error because the error only happens when building CJS.
|
|
173
|
+
azIdentity ??= await import('@azure/identity');
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
|
|
175
|
+
return new azIdentity.AzurePipelinesCredential(tenantId, clientId, serviceConnectionId, process.env.SYSTEM_ACCESSTOKEN);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=AzureDevOpsSubscriptionProvider.js.map
|