@azure/msal-node 2.2.0-alpha.0 → 2.3.0-alpha.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/dist/cache/NodeStorage.cjs +3 -3
- package/dist/cache/NodeStorage.cjs.map +1 -1
- package/dist/cache/NodeStorage.d.ts +2 -2
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/NodeStorage.mjs +3 -3
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.cjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.cjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
- package/dist/cache/serializer/Deserializer.cjs +1 -1
- package/dist/cache/serializer/Deserializer.mjs +1 -1
- package/dist/cache/serializer/Serializer.cjs +1 -1
- package/dist/cache/serializer/Serializer.mjs +1 -1
- package/dist/client/ClientApplication.cjs +2 -2
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +3 -3
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.cjs +1 -1
- package/dist/client/ClientAssertion.mjs +1 -1
- package/dist/client/ClientCredentialClient.cjs +27 -23
- package/dist/client/ClientCredentialClient.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +3 -3
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +28 -24
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.cjs +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +1 -1
- package/dist/client/DeviceCodeClient.cjs +1 -1
- package/dist/client/DeviceCodeClient.mjs +1 -1
- package/dist/client/ManagedIdentityApplication.cjs +96 -0
- package/dist/client/ManagedIdentityApplication.cjs.map +1 -0
- package/dist/client/ManagedIdentityApplication.d.ts +24 -0
- package/dist/client/ManagedIdentityApplication.d.ts.map +1 -0
- package/dist/client/ManagedIdentityApplication.mjs +94 -0
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -0
- package/dist/client/ManagedIdentityClient.cjs +49 -0
- package/dist/client/ManagedIdentityClient.cjs.map +1 -0
- package/dist/client/ManagedIdentityClient.d.ts +25 -0
- package/dist/client/ManagedIdentityClient.d.ts.map +1 -0
- package/dist/client/ManagedIdentityClient.mjs +47 -0
- package/dist/client/ManagedIdentityClient.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/AppService.cjs +79 -0
- package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -0
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/AppService.mjs +77 -0
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +107 -0
- package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +19 -0
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +104 -0
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +87 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +19 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +85 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +7 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/Imds.cjs +63 -0
- package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/Imds.d.ts +13 -0
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/Imds.mjs +61 -0
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +7 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -0
- package/dist/client/OnBehalfOfClient.cjs +1 -1
- package/dist/client/OnBehalfOfClient.mjs +1 -1
- package/dist/client/PublicClientApplication.cjs +1 -1
- package/dist/client/PublicClientApplication.mjs +1 -1
- package/dist/client/UsernamePasswordClient.cjs +1 -1
- package/dist/client/UsernamePasswordClient.mjs +1 -1
- package/dist/config/Configuration.cjs +18 -2
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +15 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +18 -3
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/config/ManagedIdentityId.cjs +59 -0
- package/dist/config/ManagedIdentityId.cjs.map +1 -0
- package/dist/config/ManagedIdentityId.d.ts +12 -0
- package/dist/config/ManagedIdentityId.d.ts.map +1 -0
- package/dist/config/ManagedIdentityId.mjs +57 -0
- package/dist/config/ManagedIdentityId.mjs.map +1 -0
- package/dist/config/ManagedIdentityRequestParameters.cjs +38 -0
- package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -0
- package/dist/config/ManagedIdentityRequestParameters.d.ts +12 -0
- package/dist/config/ManagedIdentityRequestParameters.d.ts.map +1 -0
- package/dist/config/ManagedIdentityRequestParameters.mjs +36 -0
- package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -0
- package/dist/crypto/CryptoProvider.cjs +1 -1
- package/dist/crypto/CryptoProvider.mjs +1 -1
- package/dist/crypto/GuidGenerator.cjs +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/HashUtils.cjs +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/PkceGenerator.cjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/error/ManagedIdentityError.cjs +40 -0
- package/dist/error/ManagedIdentityError.cjs.map +1 -0
- package/dist/error/ManagedIdentityError.d.ts +22 -0
- package/dist/error/ManagedIdentityError.d.ts.map +1 -0
- package/dist/error/ManagedIdentityError.mjs +36 -0
- package/dist/error/ManagedIdentityError.mjs.map +1 -0
- package/dist/error/ManagedIdentityErrorCodes.cjs +28 -0
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -0
- package/dist/error/ManagedIdentityErrorCodes.d.ts +10 -0
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -0
- package/dist/error/ManagedIdentityErrorCodes.mjs +18 -0
- package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -0
- package/dist/error/NodeAuthError.cjs +1 -1
- package/dist/error/NodeAuthError.mjs +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/network/HttpClient.cjs +13 -6
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +2 -1
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +13 -6
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/LoopbackClient.cjs +2 -1
- package/dist/network/LoopbackClient.cjs.map +1 -1
- package/dist/network/LoopbackClient.d.ts.map +1 -1
- package/dist/network/LoopbackClient.mjs +2 -1
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +2 -2
- package/dist/packageMetadata.cjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/ManagedIdentityRequest.d.ts +9 -0
- package/dist/request/ManagedIdentityRequest.d.ts.map +1 -0
- package/dist/request/ManagedIdentityRequestParams.d.ts +10 -0
- package/dist/request/ManagedIdentityRequestParams.d.ts.map +1 -0
- package/dist/response/ManagedIdentityTokenResponse.d.ts +25 -0
- package/dist/response/ManagedIdentityTokenResponse.d.ts.map +1 -0
- package/dist/utils/Constants.cjs +30 -1
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +20 -0
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +21 -2
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +1 -1
- package/dist/utils/EncodingUtils.mjs +1 -1
- package/dist/utils/NetworkUtils.cjs +1 -1
- package/dist/utils/NetworkUtils.mjs +1 -1
- package/package.json +2 -2
- package/src/cache/NodeStorage.ts +8 -2
- package/src/client/ClientApplication.ts +3 -1
- package/src/client/ClientCredentialClient.ts +65 -25
- package/src/client/ManagedIdentityApplication.ts +194 -0
- package/src/client/ManagedIdentityClient.ts +111 -0
- package/src/client/ManagedIdentitySources/AppService.ts +151 -0
- package/src/client/ManagedIdentitySources/AzureArc.ts +208 -0
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +169 -0
- package/src/client/ManagedIdentitySources/CloudShell.ts +19 -0
- package/src/client/ManagedIdentitySources/Imds.ts +112 -0
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +19 -0
- package/src/config/Configuration.ts +47 -1
- package/src/config/ManagedIdentityId.ts +73 -0
- package/src/config/ManagedIdentityRequestParameters.ts +53 -0
- package/src/error/ManagedIdentityError.ts +46 -0
- package/src/error/ManagedIdentityErrorCodes.ts +15 -0
- package/src/index.ts +3 -0
- package/src/network/HttpClient.ts +17 -5
- package/src/network/LoopbackClient.ts +1 -0
- package/src/packageMetadata.ts +1 -1
- package/src/request/ManagedIdentityRequest.ts +15 -0
- package/src/request/ManagedIdentityRequestParams.ts +14 -0
- package/src/response/ManagedIdentityTokenResponse.ts +33 -0
- package/src/utils/Constants.ts +27 -0
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import { HttpClient } from "../network/HttpClient.js";
|
|
19
19
|
import http from "http";
|
|
20
20
|
import https from "https";
|
|
21
|
+
import { ManagedIdentityId } from "./ManagedIdentityId.js";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* - clientId - Client id of the application.
|
|
@@ -107,6 +108,17 @@ export type Configuration = {
|
|
|
107
108
|
telemetry?: NodeTelemetryOptions;
|
|
108
109
|
};
|
|
109
110
|
|
|
111
|
+
export type ManagedIdentityIdParams = {
|
|
112
|
+
userAssignedClientId?: string;
|
|
113
|
+
userAssignedResourceId?: string;
|
|
114
|
+
userAssignedObjectId?: string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export type ManagedIdentityConfiguration = {
|
|
118
|
+
managedIdentityIdParams?: ManagedIdentityIdParams;
|
|
119
|
+
system?: NodeSystemOptions;
|
|
120
|
+
};
|
|
121
|
+
|
|
110
122
|
const DEFAULT_AUTH_OPTIONS: Required<NodeAuthOptions> = {
|
|
111
123
|
clientId: Constants.EMPTY_STRING,
|
|
112
124
|
authority: Constants.DEFAULT_AUTHORITY,
|
|
@@ -186,7 +198,10 @@ export function buildAppConfiguration({
|
|
|
186
198
|
...DEFAULT_SYSTEM_OPTIONS,
|
|
187
199
|
networkClient: new HttpClient(
|
|
188
200
|
system?.proxyUrl,
|
|
189
|
-
system?.customAgentOptions as
|
|
201
|
+
system?.customAgentOptions as
|
|
202
|
+
| http.AgentOptions
|
|
203
|
+
| https.AgentOptions,
|
|
204
|
+
false // Managed Identity
|
|
190
205
|
),
|
|
191
206
|
loggerOptions: system?.loggerOptions || DEFAULT_LOGGER_OPTIONS,
|
|
192
207
|
};
|
|
@@ -199,3 +214,34 @@ export function buildAppConfiguration({
|
|
|
199
214
|
telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...telemetry },
|
|
200
215
|
};
|
|
201
216
|
}
|
|
217
|
+
|
|
218
|
+
export type ManagedIdentityNodeConfiguration = {
|
|
219
|
+
managedIdentityId: ManagedIdentityId;
|
|
220
|
+
system: Required<NodeSystemOptions>;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export function buildManagedIdentityConfiguration({
|
|
224
|
+
managedIdentityIdParams,
|
|
225
|
+
system,
|
|
226
|
+
}: ManagedIdentityConfiguration): ManagedIdentityNodeConfiguration {
|
|
227
|
+
const managedIdentityId: ManagedIdentityId = new ManagedIdentityId(
|
|
228
|
+
managedIdentityIdParams
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const systemOptions: Required<NodeSystemOptions> = {
|
|
232
|
+
...DEFAULT_SYSTEM_OPTIONS,
|
|
233
|
+
loggerOptions: system?.loggerOptions || DEFAULT_LOGGER_OPTIONS,
|
|
234
|
+
networkClient: new HttpClient(
|
|
235
|
+
system?.proxyUrl,
|
|
236
|
+
system?.customAgentOptions as
|
|
237
|
+
| http.AgentOptions
|
|
238
|
+
| https.AgentOptions,
|
|
239
|
+
true // Managed Identity
|
|
240
|
+
),
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
managedIdentityId: managedIdentityId,
|
|
245
|
+
system: { ...systemOptions, ...system },
|
|
246
|
+
};
|
|
247
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ManagedIdentityErrorCodes,
|
|
8
|
+
createManagedIdentityError,
|
|
9
|
+
} from "../error/ManagedIdentityError";
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_MANAGED_IDENTITY_ID,
|
|
12
|
+
ManagedIdentityIdType,
|
|
13
|
+
} from "../utils/Constants";
|
|
14
|
+
import { ManagedIdentityIdParams } from "./Configuration";
|
|
15
|
+
|
|
16
|
+
export class ManagedIdentityId {
|
|
17
|
+
private _id: string;
|
|
18
|
+
public get id(): string {
|
|
19
|
+
return this._id;
|
|
20
|
+
}
|
|
21
|
+
private set id(value: string) {
|
|
22
|
+
this._id = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private _idType: ManagedIdentityIdType;
|
|
26
|
+
public get idType(): ManagedIdentityIdType {
|
|
27
|
+
return this._idType;
|
|
28
|
+
}
|
|
29
|
+
private set idType(value: ManagedIdentityIdType) {
|
|
30
|
+
this._idType = value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
constructor(managedIdentityIdParams?: ManagedIdentityIdParams) {
|
|
34
|
+
const userAssignedClientId =
|
|
35
|
+
managedIdentityIdParams?.userAssignedClientId;
|
|
36
|
+
const userAssignedResourceId =
|
|
37
|
+
managedIdentityIdParams?.userAssignedResourceId;
|
|
38
|
+
const userAssignedObjectId =
|
|
39
|
+
managedIdentityIdParams?.userAssignedObjectId;
|
|
40
|
+
|
|
41
|
+
if (userAssignedClientId) {
|
|
42
|
+
if (userAssignedResourceId || userAssignedObjectId) {
|
|
43
|
+
throw createManagedIdentityError(
|
|
44
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.id = userAssignedClientId;
|
|
49
|
+
this.idType = ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID;
|
|
50
|
+
} else if (userAssignedResourceId) {
|
|
51
|
+
if (userAssignedClientId || userAssignedObjectId) {
|
|
52
|
+
throw createManagedIdentityError(
|
|
53
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.id = userAssignedResourceId;
|
|
58
|
+
this.idType = ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID;
|
|
59
|
+
} else if (userAssignedObjectId) {
|
|
60
|
+
if (userAssignedClientId || userAssignedResourceId) {
|
|
61
|
+
throw createManagedIdentityError(
|
|
62
|
+
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.id = userAssignedObjectId;
|
|
67
|
+
this.idType = ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID;
|
|
68
|
+
} else {
|
|
69
|
+
this.id = DEFAULT_MANAGED_IDENTITY_ID;
|
|
70
|
+
this.idType = ManagedIdentityIdType.SYSTEM_ASSIGNED;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { RequestParameterBuilder, UrlString } from "@azure/msal-common";
|
|
7
|
+
import { HttpMethod } from "../utils/Constants";
|
|
8
|
+
|
|
9
|
+
export class ManagedIdentityRequestParameters {
|
|
10
|
+
private _baseEndpoint: string;
|
|
11
|
+
public httpMethod: HttpMethod;
|
|
12
|
+
public headers: Record<string, string>;
|
|
13
|
+
public bodyParameters: Record<string, string>;
|
|
14
|
+
public queryParameters: Record<string, string>;
|
|
15
|
+
|
|
16
|
+
constructor(httpMethod: HttpMethod, endpoint: string) {
|
|
17
|
+
this.httpMethod = httpMethod;
|
|
18
|
+
this._baseEndpoint = endpoint;
|
|
19
|
+
this.headers = {} as Record<string, string>;
|
|
20
|
+
this.bodyParameters = {} as Record<string, string>;
|
|
21
|
+
this.queryParameters = {} as Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public computeUri(): string {
|
|
25
|
+
const parameterBuilder = new RequestParameterBuilder();
|
|
26
|
+
|
|
27
|
+
if (this.queryParameters) {
|
|
28
|
+
parameterBuilder.addExtraQueryParameters(this.queryParameters);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const queryParametersString = parameterBuilder.createQueryString();
|
|
32
|
+
|
|
33
|
+
return UrlString.appendQueryString(
|
|
34
|
+
this._baseEndpoint,
|
|
35
|
+
queryParametersString
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public computeParametersBodyString(): string {
|
|
40
|
+
const parameterBuilder = new RequestParameterBuilder();
|
|
41
|
+
|
|
42
|
+
if (this.bodyParameters) {
|
|
43
|
+
parameterBuilder.addExtraQueryParameters(this.bodyParameters);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const bodyParametersString = parameterBuilder.createQueryString();
|
|
47
|
+
|
|
48
|
+
return UrlString.appendQueryString(
|
|
49
|
+
this._baseEndpoint,
|
|
50
|
+
bodyParametersString
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthError } from "@azure/msal-common";
|
|
7
|
+
import * as ManagedIdentityErrorCodes from "./ManagedIdentityErrorCodes";
|
|
8
|
+
export { ManagedIdentityErrorCodes };
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ManagedIdentityErrorMessage class containing string constants used by error codes and messages.
|
|
12
|
+
*/
|
|
13
|
+
export const ManagedIdentityErrorMessages = {
|
|
14
|
+
[ManagedIdentityErrorCodes.invalidManagedIdentityIdType]:
|
|
15
|
+
"More than one ManagedIdentityIdType was provided.",
|
|
16
|
+
[ManagedIdentityErrorCodes.invalidResource]:
|
|
17
|
+
"The supplied resource is an invalid URL.",
|
|
18
|
+
[ManagedIdentityErrorCodes.missingId]:
|
|
19
|
+
"A ManagedIdentityId id was not provided.",
|
|
20
|
+
[ManagedIdentityErrorCodes.unableToCreateAzureArc]:
|
|
21
|
+
"Azure Arc Managed Identities can only be system assigned.",
|
|
22
|
+
[ManagedIdentityErrorCodes.unableToCreateSource]:
|
|
23
|
+
"Unable to create a Managed Identity source based on environment variables.",
|
|
24
|
+
[ManagedIdentityErrorCodes.unableToReadSecretFile]:
|
|
25
|
+
"Unable to read the secret file.",
|
|
26
|
+
[ManagedIdentityErrorCodes.urlParseError]:
|
|
27
|
+
"The Managed Identity's 'IDENTITY_ENDPOINT' environment variable is malformed.",
|
|
28
|
+
[ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing]:
|
|
29
|
+
"A 401 response was received form the Azure Arc Managed Identity, but the www-authenticate header is missing.",
|
|
30
|
+
[ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat]:
|
|
31
|
+
"A 401 response was received form the Azure Arc Managed Identity, but the www-authenticate header is in an unsupported format.",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class ManagedIdentityError extends AuthError {
|
|
35
|
+
constructor(errorCode: string) {
|
|
36
|
+
super(errorCode, ManagedIdentityErrorMessages[errorCode]);
|
|
37
|
+
this.name = "ManagedIdentityError";
|
|
38
|
+
Object.setPrototypeOf(this, ManagedIdentityError.prototype);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createManagedIdentityError(
|
|
43
|
+
errorCode: string
|
|
44
|
+
): ManagedIdentityError {
|
|
45
|
+
return new ManagedIdentityError(errorCode);
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const invalidManagedIdentityIdType = "invalid_managed_identity_id_type";
|
|
7
|
+
export const invalidResource = "invalid_resource";
|
|
8
|
+
export const missingId = "missing_client_id";
|
|
9
|
+
export const unableToCreateAzureArc = "unable_to_create_azure_arc";
|
|
10
|
+
export const unableToCreateSource = "unable_to_create_source";
|
|
11
|
+
export const unableToReadSecretFile = "unable_to_read_secret_file";
|
|
12
|
+
export const urlParseError = "url_parse_error";
|
|
13
|
+
export const wwwAuthenticateHeaderMissing = "www_authenticate_header_missing";
|
|
14
|
+
export const wwwAuthenticateHeaderUnsupportedFormat =
|
|
15
|
+
"www_authenticate_header_unsupported_format";
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { ClientApplication } from "./client/ClientApplication.js";
|
|
|
31
31
|
export { ClientCredentialClient } from "./client/ClientCredentialClient.js";
|
|
32
32
|
export { DeviceCodeClient } from "./client/DeviceCodeClient.js";
|
|
33
33
|
export { OnBehalfOfClient } from "./client/OnBehalfOfClient.js";
|
|
34
|
+
export { ManagedIdentityApplication } from "./client/ManagedIdentityApplication.js";
|
|
34
35
|
export { UsernamePasswordClient } from "./client/UsernamePasswordClient.js";
|
|
35
36
|
|
|
36
37
|
export {
|
|
@@ -73,6 +74,7 @@ export type { RefreshTokenRequest } from "./request/RefreshTokenRequest.js";
|
|
|
73
74
|
export type { SilentFlowRequest } from "./request/SilentFlowRequest.js";
|
|
74
75
|
export type { InteractiveRequest } from "./request/InteractiveRequest.js";
|
|
75
76
|
export type { SignOutRequest } from "./request/SignOutRequest.js";
|
|
77
|
+
export type { ManagedIdentityRequestParams } from "./request/ManagedIdentityRequestParams.js";
|
|
76
78
|
|
|
77
79
|
// Common Object Formats
|
|
78
80
|
export {
|
|
@@ -120,6 +122,7 @@ export {
|
|
|
120
122
|
IAppTokenProvider,
|
|
121
123
|
AppTokenProviderParameters,
|
|
122
124
|
AppTokenProviderResult,
|
|
125
|
+
INativeBrokerPlugin,
|
|
123
126
|
} from "@azure/msal-common";
|
|
124
127
|
|
|
125
128
|
export { version } from "./packageMetadata.js";
|
|
@@ -20,13 +20,16 @@ import https from "https";
|
|
|
20
20
|
export class HttpClient implements INetworkModule {
|
|
21
21
|
private proxyUrl: string;
|
|
22
22
|
private customAgentOptions: http.AgentOptions | https.AgentOptions;
|
|
23
|
+
private managedIdentity: boolean;
|
|
23
24
|
|
|
24
25
|
constructor(
|
|
25
26
|
proxyUrl?: string,
|
|
26
|
-
customAgentOptions?: http.AgentOptions | https.AgentOptions
|
|
27
|
+
customAgentOptions?: http.AgentOptions | https.AgentOptions,
|
|
28
|
+
managedIdentity?: boolean
|
|
27
29
|
) {
|
|
28
30
|
this.proxyUrl = proxyUrl || "";
|
|
29
31
|
this.customAgentOptions = customAgentOptions || {};
|
|
32
|
+
this.managedIdentity = managedIdentity || false;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
/**
|
|
@@ -51,7 +54,9 @@ export class HttpClient implements INetworkModule {
|
|
|
51
54
|
url,
|
|
52
55
|
HttpMethod.GET,
|
|
53
56
|
options,
|
|
54
|
-
this.customAgentOptions as https.AgentOptions
|
|
57
|
+
this.customAgentOptions as https.AgentOptions,
|
|
58
|
+
undefined,
|
|
59
|
+
this.managedIdentity
|
|
55
60
|
);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
@@ -81,7 +86,8 @@ export class HttpClient implements INetworkModule {
|
|
|
81
86
|
HttpMethod.POST,
|
|
82
87
|
options,
|
|
83
88
|
this.customAgentOptions as https.AgentOptions,
|
|
84
|
-
cancellationToken
|
|
89
|
+
cancellationToken,
|
|
90
|
+
this.managedIdentity
|
|
85
91
|
);
|
|
86
92
|
}
|
|
87
93
|
}
|
|
@@ -277,7 +283,8 @@ const networkRequestViaHttps = <T>(
|
|
|
277
283
|
httpMethod: string,
|
|
278
284
|
options?: NetworkRequestOptions,
|
|
279
285
|
agentOptions?: https.AgentOptions,
|
|
280
|
-
timeout?: number
|
|
286
|
+
timeout?: number,
|
|
287
|
+
managedIdentity?: boolean
|
|
281
288
|
): Promise<NetworkResponse<T>> => {
|
|
282
289
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
283
290
|
const body: string = options?.body || "";
|
|
@@ -307,7 +314,12 @@ const networkRequestViaHttps = <T>(
|
|
|
307
314
|
}
|
|
308
315
|
|
|
309
316
|
return new Promise<NetworkResponse<T>>((resolve, reject) => {
|
|
310
|
-
|
|
317
|
+
let request: http.ClientRequest;
|
|
318
|
+
if (managedIdentity) {
|
|
319
|
+
request = http.request(customOptions);
|
|
320
|
+
} else {
|
|
321
|
+
request = https.request(customOptions);
|
|
322
|
+
}
|
|
311
323
|
|
|
312
324
|
if (timeout) {
|
|
313
325
|
request.on("timeout", () => {
|
package/src/packageMetadata.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CommonClientCredentialRequest } from "@azure/msal-common";
|
|
7
|
+
import { ManagedIdentityRequestParams } from "./ManagedIdentityRequestParams";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ManagedIdentityRequest
|
|
11
|
+
* - forceRefresh - forces managed identity requests to skip the cache and make network calls if true
|
|
12
|
+
* - resource - resource requested to access the protected API. It should be of the form "{ResourceIdUri}" or {ResourceIdUri/.default}. For instance https://management.azure.net or, for Microsoft Graph, https://graph.microsoft.com/.default
|
|
13
|
+
*/
|
|
14
|
+
export type ManagedIdentityRequest = ManagedIdentityRequestParams &
|
|
15
|
+
CommonClientCredentialRequest;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ManagedIdentityRequest
|
|
8
|
+
* - forceRefresh - forces managed identity requests to skip the cache and make network calls if true
|
|
9
|
+
* - resource - resource requested to access the protected API. It should be of the form "{ResourceIdUri}" or {ResourceIdUri/.default}. For instance https://management.azure.net or, for Microsoft Graph, https://graph.microsoft.com/.default
|
|
10
|
+
*/
|
|
11
|
+
export type ManagedIdentityRequestParams = {
|
|
12
|
+
forceRefresh?: boolean;
|
|
13
|
+
resource: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthenticationScheme } from "@azure/msal-common";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Deserialized response object from server managed identity request.
|
|
10
|
+
*
|
|
11
|
+
* In case of success:
|
|
12
|
+
* - access_token - The requested access token. When called via a secured REST API, the token is embedded in the Authorization request header field as a "bearer" token, allowing the API to authenticate the caller
|
|
13
|
+
* - client_id - A unique identifier generated by Azure AD for the Azure Resource. The Client ID is a GUID value that uniquely identifies the application and its configuration within the identity platform
|
|
14
|
+
* - expires_on - The timespan when the access token expires. The date is represented as the number of seconds from "1970-01-01T0:0:0Z UTC" (corresponds to the token's exp claim)
|
|
15
|
+
* - resource - The resource the access token was requested for. It matches the resource query string parameter of the request
|
|
16
|
+
* - token_type - The type of token returned by the Managed Identity endpoint. It's a "Bearer" access token, which means the resource can give access to the bearer of this token
|
|
17
|
+
*
|
|
18
|
+
* In case of error:
|
|
19
|
+
* - message: A specific error message that can help a developer identify the root cause of an authentication error.
|
|
20
|
+
* - correlationId: A unique identifier for the request that can help in diagnostics across components.
|
|
21
|
+
*/
|
|
22
|
+
export type ManagedIdentityTokenResponse = {
|
|
23
|
+
// success
|
|
24
|
+
access_token?: string;
|
|
25
|
+
client_id?: string;
|
|
26
|
+
expires_on?: number; // will be converted to expires_in
|
|
27
|
+
resource?: string; // equivalent to ServerAuthorizationTokenResponse's "scope" field
|
|
28
|
+
token_type?: AuthenticationScheme;
|
|
29
|
+
|
|
30
|
+
// error
|
|
31
|
+
message?: string; // will be converted to error
|
|
32
|
+
correlationId?: string; // will be converted to correlation_id
|
|
33
|
+
};
|
package/src/utils/Constants.ts
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
7
|
+
export const AUTHORIZATION_HEADER_NAME: string = "Authorization";
|
|
8
|
+
export const METADATA_HEADER_NAME: string = "Metadata";
|
|
9
|
+
export const SECRET_HEADER_NAME: string = "X-IDENTITY-HEADER";
|
|
10
|
+
|
|
11
|
+
export const MANAGED_IDENTITY_CLIENT_ID = "client_id";
|
|
12
|
+
export const MANAGED_IDENTITY_OBJECT_ID = "object_id";
|
|
13
|
+
export const MANAGED_IDENTITY_RESOURCE_ID = "mi_res_id";
|
|
14
|
+
export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
|
|
15
|
+
export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
|
|
16
|
+
export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
|
|
17
|
+
|
|
18
|
+
export const MANAGED_IDENTITY_TIMEOUT_ERROR: string =
|
|
19
|
+
"[Managed Identity] Authentication unavailable. The request to the managed identity endpoint timed out.";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Managed Identity Ids
|
|
23
|
+
*/
|
|
24
|
+
export const ManagedIdentityIdType = {
|
|
25
|
+
SYSTEM_ASSIGNED: "system-assigned",
|
|
26
|
+
USER_ASSIGNED_CLIENT_ID: "user-assigned-client-id",
|
|
27
|
+
USER_ASSIGNED_RESOURCE_ID: "user-assigned-resource-id",
|
|
28
|
+
USER_ASSIGNED_OBJECT_ID: "user-assigned-object-id",
|
|
29
|
+
} as const;
|
|
30
|
+
export type ManagedIdentityIdType =
|
|
31
|
+
(typeof ManagedIdentityIdType)[keyof typeof ManagedIdentityIdType];
|
|
32
|
+
|
|
6
33
|
/**
|
|
7
34
|
* http methods
|
|
8
35
|
*/
|