@azure/msal-node 2.6.3 → 2.6.5-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 +1 -1
- package/dist/cache/NodeStorage.mjs +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 +1 -1
- package/dist/client/ClientApplication.mjs +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 +97 -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 +95 -0
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -0
- package/dist/client/ManagedIdentityClient.cjs +53 -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 +51 -0
- package/dist/client/ManagedIdentityClient.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/AppService.cjs +52 -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 +50 -0
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +96 -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 +93 -0
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +122 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +31 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +119 -0
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +47 -0
- package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +16 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +45 -0
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/Imds.cjs +54 -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 +52 -0
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +61 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +17 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +59 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.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 +36 -2
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +16 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +36 -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 +37 -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 +35 -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 +51 -0
- package/dist/error/ManagedIdentityError.cjs.map +1 -0
- package/dist/error/ManagedIdentityError.d.ts +28 -0
- package/dist/error/ManagedIdentityError.d.ts.map +1 -0
- package/dist/error/ManagedIdentityError.mjs +47 -0
- package/dist/error/ManagedIdentityError.mjs.map +1 -0
- package/dist/error/ManagedIdentityErrorCodes.cjs +41 -0
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -0
- package/dist/error/ManagedIdentityErrorCodes.d.ts +20 -0
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -0
- package/dist/error/ManagedIdentityErrorCodes.mjs +28 -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/HttpClientWithRetries.cjs +44 -0
- package/dist/network/HttpClientWithRetries.cjs.map +1 -0
- package/dist/network/HttpClientWithRetries.d.ts +12 -0
- package/dist/network/HttpClientWithRetries.d.ts.map +1 -0
- package/dist/network/HttpClientWithRetries.mjs +42 -0
- package/dist/network/HttpClientWithRetries.mjs.map +1 -0
- package/dist/network/LoopbackClient.cjs +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/packageMetadata.cjs +2 -2
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- 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/retry/IHttpRetryPolicy.d.ts +6 -0
- package/dist/retry/IHttpRetryPolicy.d.ts.map +1 -0
- package/dist/retry/LinearRetryPolicy.cjs +47 -0
- package/dist/retry/LinearRetryPolicy.cjs.map +1 -0
- package/dist/retry/LinearRetryPolicy.d.ts +12 -0
- package/dist/retry/LinearRetryPolicy.d.ts.map +1 -0
- package/dist/retry/LinearRetryPolicy.mjs +45 -0
- package/dist/retry/LinearRetryPolicy.mjs.map +1 -0
- package/dist/utils/Constants.cjs +68 -1
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +45 -0
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +54 -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/client/ClientCredentialClient.ts +65 -25
- package/src/client/ManagedIdentityApplication.ts +194 -0
- package/src/client/ManagedIdentityClient.ts +128 -0
- package/src/client/ManagedIdentitySources/AppService.ts +122 -0
- package/src/client/ManagedIdentitySources/AzureArc.ts +199 -0
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +237 -0
- package/src/client/ManagedIdentitySources/CloudShell.ts +104 -0
- package/src/client/ManagedIdentitySources/Imds.ts +126 -0
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +140 -0
- package/src/config/Configuration.ts +81 -1
- package/src/config/ManagedIdentityId.ts +73 -0
- package/src/config/ManagedIdentityRequestParameters.ts +48 -0
- package/src/error/ManagedIdentityError.ts +59 -0
- package/src/error/ManagedIdentityErrorCodes.ts +34 -0
- package/src/index.ts +4 -0
- package/src/network/HttpClient.ts +17 -5
- package/src/network/HttpClientWithRetries.ts +80 -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/retry/IHttpRetryPolicy.ts +18 -0
- package/src/retry/LinearRetryPolicy.ts +71 -0
- package/src/utils/Constants.ts +63 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/utils/Constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/utils/Constants.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,yBAAyB,EAAE,MAAwB,CAAC;AACjE,eAAO,MAAM,oBAAoB,EAAE,MAAmB,CAAC;AACvD,eAAO,MAAM,8BAA8B,EAAE,MAA4B,CAAC;AAC1E,eAAO,MAAM,iCAAiC,EAAE,MAAiB,CAAC;AAClE,eAAO,MAAM,gCAAgC,EAAE,MAAsB,CAAC;AACtE,eAAO,MAAM,qCAAqC,EAAE,MAAmB,CAAC;AACxE,eAAO,MAAM,2BAA2B,qCAAqC,CAAC;AAC9E,eAAO,MAAM,+BAA+B,qBAAqB,CAAC;AAClE,eAAO,MAAM,sCAA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G;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;CAWxB,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;CAGrC,CAAC;AAEF,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,8CAA8C,uCAO1D,CAAC"}
|
package/dist/utils/Constants.mjs
CHANGED
|
@@ -1,9 +1,51 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.6.
|
|
1
|
+
/*! @azure/msal-node v2.6.5-alpha.0 2024-03-04 */
|
|
2
2
|
'use strict';
|
|
3
|
+
import { HttpStatus } from '@azure/msal-common';
|
|
4
|
+
|
|
3
5
|
/*
|
|
4
6
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
7
|
* Licensed under the MIT License.
|
|
6
8
|
*/
|
|
9
|
+
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
10
|
+
const AUTHORIZATION_HEADER_NAME = "Authorization";
|
|
11
|
+
const METADATA_HEADER_NAME = "Metadata";
|
|
12
|
+
const APP_SERVICE_SECRET_HEADER_NAME = "X-IDENTITY-HEADER";
|
|
13
|
+
const SERVICE_FABRIC_SECRET_HEADER_NAME = "secret";
|
|
14
|
+
const API_VERSION_QUERY_PARAMETER_NAME = "api-version";
|
|
15
|
+
const RESOURCE_BODY_OR_QUERY_PARAMETER_NAME = "resource";
|
|
16
|
+
const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
|
|
17
|
+
const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
|
|
18
|
+
const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
|
|
19
|
+
/**
|
|
20
|
+
* Managed Identity Environment Variable Names
|
|
21
|
+
*/
|
|
22
|
+
const ManagedIdentityEnvironmentVariableNames = {
|
|
23
|
+
AZURE_POD_IDENTITY_AUTHORITY_HOST: "AZURE_POD_IDENTITY_AUTHORITY_HOST",
|
|
24
|
+
IDENTITY_ENDPOINT: "IDENTITY_ENDPOINT",
|
|
25
|
+
IDENTITY_HEADER: "IDENTITY_HEADER",
|
|
26
|
+
IDENTITY_SERVER_THUMBPRINT: "IDENTITY_SERVER_THUMBPRINT",
|
|
27
|
+
IMDS_ENDPOINT: "IMDS_ENDPOINT",
|
|
28
|
+
MSI_ENDPOINT: "MSI_ENDPOINT",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Managed Identity Source Names
|
|
32
|
+
*/
|
|
33
|
+
const ManagedIdentitySourceNames = {
|
|
34
|
+
APP_SERVICE: "App Service",
|
|
35
|
+
AZURE_ARC: "Azure Arc",
|
|
36
|
+
CLOUD_SHELL: "Cloud Shell",
|
|
37
|
+
IMDS: "IMDS",
|
|
38
|
+
SERVICE_FABRIC: "Service Fabric",
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Managed Identity Ids
|
|
42
|
+
*/
|
|
43
|
+
const ManagedIdentityIdType = {
|
|
44
|
+
SYSTEM_ASSIGNED: "system-assigned",
|
|
45
|
+
USER_ASSIGNED_CLIENT_ID: "user-assigned-client-id",
|
|
46
|
+
USER_ASSIGNED_RESOURCE_ID: "user-assigned-resource-id",
|
|
47
|
+
USER_ASSIGNED_OBJECT_ID: "user-assigned-object-id",
|
|
48
|
+
};
|
|
7
49
|
/**
|
|
8
50
|
* http methods
|
|
9
51
|
*/
|
|
@@ -80,6 +122,16 @@ const LOOPBACK_SERVER_CONSTANTS = {
|
|
|
80
122
|
INTERVAL_MS: 100,
|
|
81
123
|
TIMEOUT_MS: 5000,
|
|
82
124
|
};
|
|
125
|
+
const MANAGED_IDENTITY_MAX_RETRIES = 1;
|
|
126
|
+
const MANAGED_IDENTITY_RETRY_DELAY = 1000;
|
|
127
|
+
const MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON = [
|
|
128
|
+
HttpStatus.NOT_FOUND,
|
|
129
|
+
HttpStatus.REQUEST_TIMEOUT,
|
|
130
|
+
HttpStatus.TOO_MANY_REQUESTS,
|
|
131
|
+
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
132
|
+
HttpStatus.SERVICE_UNAVAILABLE,
|
|
133
|
+
HttpStatus.GATEWAY_TIMEOUT,
|
|
134
|
+
];
|
|
83
135
|
|
|
84
|
-
export { ApiId, CharSet, Constants, Hash, HttpMethod, JwtConstants, LOOPBACK_SERVER_CONSTANTS, ProxyStatus, RANDOM_OCTET_SIZE, REGION_ENVIRONMENT_VARIABLE };
|
|
136
|
+
export { API_VERSION_QUERY_PARAMETER_NAME, APP_SERVICE_SECRET_HEADER_NAME, AUTHORIZATION_HEADER_NAME, ApiId, CharSet, Constants, DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY, DEFAULT_MANAGED_IDENTITY_ID, Hash, HttpMethod, JwtConstants, LOOPBACK_SERVER_CONSTANTS, MANAGED_IDENTITY_DEFAULT_TENANT, MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON, MANAGED_IDENTITY_MAX_RETRIES, MANAGED_IDENTITY_RETRY_DELAY, METADATA_HEADER_NAME, ManagedIdentityEnvironmentVariableNames, ManagedIdentityIdType, ManagedIdentitySourceNames, ProxyStatus, RANDOM_OCTET_SIZE, REGION_ENVIRONMENT_VARIABLE, RESOURCE_BODY_OR_QUERY_PARAMETER_NAME, SERVICE_FABRIC_SECRET_HEADER_NAME };
|
|
85
137
|
//# sourceMappingURL=Constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.mjs","sources":["../../src/utils/Constants.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Constants.mjs","sources":["../../src/utils/Constants.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;AAGG;AAIH;AACO,MAAM,yBAAyB,GAAW,gBAAgB;AAC1D,MAAM,oBAAoB,GAAW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ChC,IAAA,UAAU,CAAC,mBAAmB;AAC9B,IAAA,UAAU,CAAC,eAAe;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@azure/msal-node",
|
|
4
|
-
"version": "2.6.
|
|
4
|
+
"version": "2.6.5-alpha.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Microsoft",
|
|
7
7
|
"email": "nugetaad@microsoft.com",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"yargs": "^17.3.1"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@azure/msal-common": "14.7.0",
|
|
80
|
+
"@azure/msal-common": "14.7.2-alpha.0",
|
|
81
81
|
"jsonwebtoken": "^9.0.0",
|
|
82
82
|
"uuid": "^8.3.0"
|
|
83
83
|
},
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
AuthenticationScheme,
|
|
10
10
|
Authority,
|
|
11
11
|
BaseClient,
|
|
12
|
+
CacheManager,
|
|
12
13
|
CacheOutcome,
|
|
13
14
|
ClientAuthErrorCodes,
|
|
14
15
|
ClientConfiguration,
|
|
@@ -16,25 +17,31 @@ import {
|
|
|
16
17
|
Constants,
|
|
17
18
|
CredentialFilter,
|
|
18
19
|
CredentialType,
|
|
20
|
+
DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
|
|
19
21
|
GrantType,
|
|
20
22
|
IAppTokenProvider,
|
|
23
|
+
ICrypto,
|
|
21
24
|
RequestParameterBuilder,
|
|
22
25
|
RequestThumbprint,
|
|
23
26
|
ResponseHandler,
|
|
24
27
|
ScopeSet,
|
|
25
28
|
ServerAuthorizationTokenResponse,
|
|
29
|
+
ServerTelemetryManager,
|
|
26
30
|
StringUtils,
|
|
27
31
|
TimeUtils,
|
|
28
32
|
TokenCacheContext,
|
|
29
33
|
UrlString,
|
|
30
34
|
createClientAuthError,
|
|
31
35
|
} from "@azure/msal-common";
|
|
36
|
+
import {
|
|
37
|
+
ManagedIdentityConfiguration,
|
|
38
|
+
ManagedIdentityNodeConfiguration,
|
|
39
|
+
} from "../config/Configuration";
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
42
|
* OAuth2.0 client credential grant
|
|
35
43
|
*/
|
|
36
44
|
export class ClientCredentialClient extends BaseClient {
|
|
37
|
-
private scopeSet: ScopeSet;
|
|
38
45
|
private readonly appTokenProvider?: IAppTokenProvider;
|
|
39
46
|
|
|
40
47
|
constructor(
|
|
@@ -52,14 +59,19 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
52
59
|
public async acquireToken(
|
|
53
60
|
request: CommonClientCredentialRequest
|
|
54
61
|
): Promise<AuthenticationResult | null> {
|
|
55
|
-
this.scopeSet = new ScopeSet(request.scopes || []);
|
|
56
|
-
|
|
57
62
|
if (request.skipCache) {
|
|
58
63
|
return this.executeTokenRequest(request, this.authority);
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
const [cachedAuthenticationResult, lastCacheOutcome] =
|
|
62
|
-
await this.getCachedAuthenticationResult(
|
|
67
|
+
await this.getCachedAuthenticationResult(
|
|
68
|
+
request,
|
|
69
|
+
this.config,
|
|
70
|
+
this.cryptoUtils,
|
|
71
|
+
this.authority,
|
|
72
|
+
this.cacheManager,
|
|
73
|
+
this.serverTelemetryManager
|
|
74
|
+
);
|
|
63
75
|
|
|
64
76
|
if (cachedAuthenticationResult) {
|
|
65
77
|
// if the token is not expired but must be refreshed; get a new one in the background
|
|
@@ -87,34 +99,56 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
87
99
|
/**
|
|
88
100
|
* looks up cache if the tokens are cached already
|
|
89
101
|
*/
|
|
90
|
-
|
|
91
|
-
request: CommonClientCredentialRequest
|
|
102
|
+
public async getCachedAuthenticationResult(
|
|
103
|
+
request: CommonClientCredentialRequest,
|
|
104
|
+
config: ClientConfiguration | ManagedIdentityConfiguration,
|
|
105
|
+
cryptoUtils: ICrypto,
|
|
106
|
+
authority: Authority,
|
|
107
|
+
cacheManager: CacheManager,
|
|
108
|
+
serverTelemetryManager?: ServerTelemetryManager | null
|
|
92
109
|
): Promise<[AuthenticationResult | null, CacheOutcome]> {
|
|
110
|
+
const clientConfiguration = config as ClientConfiguration;
|
|
111
|
+
const managedIdentityConfiguration =
|
|
112
|
+
config as ManagedIdentityNodeConfiguration;
|
|
113
|
+
|
|
93
114
|
let lastCacheOutcome: CacheOutcome = CacheOutcome.NOT_APPLICABLE;
|
|
94
115
|
|
|
95
116
|
// read the user-supplied cache into memory, if applicable
|
|
96
117
|
let cacheContext;
|
|
97
|
-
if (
|
|
118
|
+
if (
|
|
119
|
+
clientConfiguration.serializableCache &&
|
|
120
|
+
clientConfiguration.persistencePlugin
|
|
121
|
+
) {
|
|
98
122
|
cacheContext = new TokenCacheContext(
|
|
99
|
-
|
|
123
|
+
clientConfiguration.serializableCache,
|
|
100
124
|
false
|
|
101
125
|
);
|
|
102
|
-
await
|
|
126
|
+
await clientConfiguration.persistencePlugin.beforeCacheAccess(
|
|
127
|
+
cacheContext
|
|
128
|
+
);
|
|
103
129
|
}
|
|
104
130
|
|
|
105
|
-
const cachedAccessToken = this.readAccessTokenFromCache(
|
|
131
|
+
const cachedAccessToken = this.readAccessTokenFromCache(
|
|
132
|
+
authority,
|
|
133
|
+
managedIdentityConfiguration.managedIdentityId?.id ||
|
|
134
|
+
clientConfiguration.authOptions.clientId,
|
|
135
|
+
new ScopeSet(request.scopes || []),
|
|
136
|
+
cacheManager
|
|
137
|
+
);
|
|
106
138
|
|
|
107
139
|
if (
|
|
108
|
-
|
|
109
|
-
|
|
140
|
+
clientConfiguration.serializableCache &&
|
|
141
|
+
clientConfiguration.persistencePlugin &&
|
|
110
142
|
cacheContext
|
|
111
143
|
) {
|
|
112
|
-
await
|
|
144
|
+
await clientConfiguration.persistencePlugin.afterCacheAccess(
|
|
145
|
+
cacheContext
|
|
146
|
+
);
|
|
113
147
|
}
|
|
114
148
|
|
|
115
149
|
// must refresh due to non-existent access_token
|
|
116
150
|
if (!cachedAccessToken) {
|
|
117
|
-
|
|
151
|
+
serverTelemetryManager?.setCacheOutcome(
|
|
118
152
|
CacheOutcome.NO_CACHED_ACCESS_TOKEN
|
|
119
153
|
);
|
|
120
154
|
return [null, CacheOutcome.NO_CACHED_ACCESS_TOKEN];
|
|
@@ -124,10 +158,11 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
124
158
|
if (
|
|
125
159
|
TimeUtils.isTokenExpired(
|
|
126
160
|
cachedAccessToken.expiresOn,
|
|
127
|
-
|
|
161
|
+
clientConfiguration.systemOptions?.tokenRenewalOffsetSeconds ||
|
|
162
|
+
DEFAULT_TOKEN_RENEWAL_OFFSET_SEC
|
|
128
163
|
)
|
|
129
164
|
) {
|
|
130
|
-
|
|
165
|
+
serverTelemetryManager?.setCacheOutcome(
|
|
131
166
|
CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED
|
|
132
167
|
);
|
|
133
168
|
return [null, CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
|
|
@@ -139,15 +174,15 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
139
174
|
TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)
|
|
140
175
|
) {
|
|
141
176
|
lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
|
|
142
|
-
|
|
177
|
+
serverTelemetryManager?.setCacheOutcome(
|
|
143
178
|
CacheOutcome.PROACTIVELY_REFRESHED
|
|
144
179
|
);
|
|
145
180
|
}
|
|
146
181
|
|
|
147
182
|
return [
|
|
148
183
|
await ResponseHandler.generateAuthenticationResult(
|
|
149
|
-
|
|
150
|
-
|
|
184
|
+
cryptoUtils,
|
|
185
|
+
authority,
|
|
151
186
|
{
|
|
152
187
|
account: null,
|
|
153
188
|
idToken: null,
|
|
@@ -165,19 +200,24 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
165
200
|
/**
|
|
166
201
|
* Reads access token from the cache
|
|
167
202
|
*/
|
|
168
|
-
private readAccessTokenFromCache(
|
|
203
|
+
private readAccessTokenFromCache(
|
|
204
|
+
authority: Authority,
|
|
205
|
+
id: string,
|
|
206
|
+
scopeSet: ScopeSet,
|
|
207
|
+
cacheManager: CacheManager
|
|
208
|
+
): AccessTokenEntity | null {
|
|
169
209
|
const accessTokenFilter: CredentialFilter = {
|
|
170
210
|
homeAccountId: Constants.EMPTY_STRING,
|
|
171
211
|
environment:
|
|
172
|
-
|
|
212
|
+
authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
173
213
|
credentialType: CredentialType.ACCESS_TOKEN,
|
|
174
|
-
clientId:
|
|
175
|
-
realm:
|
|
176
|
-
target: ScopeSet.createSearchScopes(
|
|
214
|
+
clientId: id,
|
|
215
|
+
realm: authority.tenant,
|
|
216
|
+
target: ScopeSet.createSearchScopes(scopeSet.asArray()),
|
|
177
217
|
};
|
|
178
218
|
|
|
179
219
|
const accessTokens =
|
|
180
|
-
|
|
220
|
+
cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
181
221
|
if (accessTokens.length < 1) {
|
|
182
222
|
return null;
|
|
183
223
|
} else if (accessTokens.length > 1) {
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AuthOptions,
|
|
8
|
+
Authority,
|
|
9
|
+
AuthorityOptions,
|
|
10
|
+
CacheOutcome,
|
|
11
|
+
ClientConfiguration,
|
|
12
|
+
Constants,
|
|
13
|
+
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
14
|
+
INetworkModule,
|
|
15
|
+
Logger,
|
|
16
|
+
ProtocolMode,
|
|
17
|
+
StaticAuthorityOptions,
|
|
18
|
+
AuthenticationResult,
|
|
19
|
+
UrlString,
|
|
20
|
+
} from "@azure/msal-common";
|
|
21
|
+
import {
|
|
22
|
+
ManagedIdentityConfiguration,
|
|
23
|
+
ManagedIdentityNodeConfiguration,
|
|
24
|
+
buildManagedIdentityConfiguration,
|
|
25
|
+
} from "../config/Configuration";
|
|
26
|
+
import { version, name } from "../packageMetadata.js";
|
|
27
|
+
import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest";
|
|
28
|
+
import { CryptoProvider } from "../crypto/CryptoProvider";
|
|
29
|
+
import { ClientCredentialClient } from "./ClientCredentialClient";
|
|
30
|
+
import { ManagedIdentityClient } from "./ManagedIdentityClient";
|
|
31
|
+
import { ManagedIdentityRequestParams } from "../request/ManagedIdentityRequestParams";
|
|
32
|
+
import { NodeStorage } from "../cache/NodeStorage";
|
|
33
|
+
import { DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY } from "../utils/Constants";
|
|
34
|
+
import {
|
|
35
|
+
ManagedIdentityErrorCodes,
|
|
36
|
+
createManagedIdentityError,
|
|
37
|
+
} from "../error/ManagedIdentityError";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Class to initialize a managed identity and identify the service
|
|
41
|
+
*/
|
|
42
|
+
export class ManagedIdentityApplication {
|
|
43
|
+
private config: ManagedIdentityNodeConfiguration;
|
|
44
|
+
|
|
45
|
+
private logger: Logger;
|
|
46
|
+
private static nodeStorage: NodeStorage | undefined;
|
|
47
|
+
private networkClient: INetworkModule;
|
|
48
|
+
private cryptoProvider: CryptoProvider;
|
|
49
|
+
|
|
50
|
+
// authority needs to be faked to re-use existing functionality in msal-common: caching in responseHandler, etc.
|
|
51
|
+
private fakeAuthority: Authority;
|
|
52
|
+
|
|
53
|
+
// the ClientCredentialClient class needs to be faked to call it's getCachedAuthenticationResult method
|
|
54
|
+
private fakeClientCredentialClient: ClientCredentialClient;
|
|
55
|
+
|
|
56
|
+
private managedIdentityClient: ManagedIdentityClient;
|
|
57
|
+
|
|
58
|
+
constructor(configuration?: ManagedIdentityConfiguration) {
|
|
59
|
+
// undefined config means the managed identity is system-assigned
|
|
60
|
+
this.config = buildManagedIdentityConfiguration(configuration || {});
|
|
61
|
+
|
|
62
|
+
this.logger = new Logger(
|
|
63
|
+
this.config.system.loggerOptions,
|
|
64
|
+
name,
|
|
65
|
+
version
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const fakeStatusAuthorityOptions: StaticAuthorityOptions = {
|
|
69
|
+
canonicalAuthority: Constants.DEFAULT_AUTHORITY,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (!ManagedIdentityApplication.nodeStorage) {
|
|
73
|
+
ManagedIdentityApplication.nodeStorage = new NodeStorage(
|
|
74
|
+
this.logger,
|
|
75
|
+
this.config.managedIdentityId.id,
|
|
76
|
+
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
77
|
+
fakeStatusAuthorityOptions
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.networkClient = this.config.system.networkClient;
|
|
82
|
+
|
|
83
|
+
this.cryptoProvider = new CryptoProvider();
|
|
84
|
+
|
|
85
|
+
const fakeAuthorityOptions: AuthorityOptions = {
|
|
86
|
+
protocolMode: ProtocolMode.AAD,
|
|
87
|
+
knownAuthorities: [DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY],
|
|
88
|
+
cloudDiscoveryMetadata: "",
|
|
89
|
+
authorityMetadata: "",
|
|
90
|
+
};
|
|
91
|
+
this.fakeAuthority = new Authority(
|
|
92
|
+
DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY,
|
|
93
|
+
this.networkClient,
|
|
94
|
+
ManagedIdentityApplication.nodeStorage as NodeStorage,
|
|
95
|
+
fakeAuthorityOptions,
|
|
96
|
+
this.logger,
|
|
97
|
+
this.cryptoProvider.createNewGuid(), // correlationID
|
|
98
|
+
undefined,
|
|
99
|
+
true
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
this.fakeClientCredentialClient = new ClientCredentialClient({
|
|
103
|
+
authOptions: {
|
|
104
|
+
clientId: this.config.managedIdentityId.id,
|
|
105
|
+
authority: this.fakeAuthority,
|
|
106
|
+
} as AuthOptions,
|
|
107
|
+
} as ClientConfiguration);
|
|
108
|
+
|
|
109
|
+
this.managedIdentityClient = new ManagedIdentityClient(
|
|
110
|
+
this.logger,
|
|
111
|
+
ManagedIdentityApplication.nodeStorage as NodeStorage,
|
|
112
|
+
this.networkClient,
|
|
113
|
+
this.cryptoProvider
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Acquire an access token from the cache or the managed identity
|
|
119
|
+
* @param managedIdentityRequest
|
|
120
|
+
* @returns the access token
|
|
121
|
+
*/
|
|
122
|
+
public async acquireToken(
|
|
123
|
+
managedIdentityRequestParams: ManagedIdentityRequestParams
|
|
124
|
+
): Promise<AuthenticationResult> {
|
|
125
|
+
const resourceUrlString = new UrlString(
|
|
126
|
+
managedIdentityRequestParams.resource.replace("/.default", "")
|
|
127
|
+
);
|
|
128
|
+
try {
|
|
129
|
+
resourceUrlString.validateAsUri();
|
|
130
|
+
} catch (e) {
|
|
131
|
+
throw createManagedIdentityError(
|
|
132
|
+
ManagedIdentityErrorCodes.invalidResource
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const managedIdentityRequest: ManagedIdentityRequest = {
|
|
137
|
+
forceRefresh: managedIdentityRequestParams.forceRefresh,
|
|
138
|
+
resource: managedIdentityRequestParams.resource.replace(
|
|
139
|
+
"/.default",
|
|
140
|
+
""
|
|
141
|
+
),
|
|
142
|
+
scopes: [
|
|
143
|
+
managedIdentityRequestParams.resource.replace("/.default", ""),
|
|
144
|
+
],
|
|
145
|
+
authority: this.fakeAuthority.canonicalAuthority,
|
|
146
|
+
correlationId: this.cryptoProvider.createNewGuid(),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
if (managedIdentityRequest.forceRefresh) {
|
|
150
|
+
// make a network call to the managed identity source
|
|
151
|
+
return this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
|
152
|
+
managedIdentityRequest,
|
|
153
|
+
this.config.managedIdentityId,
|
|
154
|
+
this.fakeAuthority
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const [cachedAuthenticationResult, lastCacheOutcome] =
|
|
159
|
+
await this.fakeClientCredentialClient.getCachedAuthenticationResult(
|
|
160
|
+
managedIdentityRequest,
|
|
161
|
+
this.config,
|
|
162
|
+
this.cryptoProvider,
|
|
163
|
+
this.fakeAuthority,
|
|
164
|
+
ManagedIdentityApplication.nodeStorage as NodeStorage
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
if (cachedAuthenticationResult) {
|
|
168
|
+
// if the token is not expired but must be refreshed; get a new one in the background
|
|
169
|
+
if (lastCacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
|
|
170
|
+
this.logger.info(
|
|
171
|
+
"ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed."
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// make a network call to the managed identity source; refresh the access token in the background
|
|
175
|
+
const refreshAccessToken = true;
|
|
176
|
+
await this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
|
177
|
+
managedIdentityRequest,
|
|
178
|
+
this.config.managedIdentityId,
|
|
179
|
+
this.fakeAuthority,
|
|
180
|
+
refreshAccessToken
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return cachedAuthenticationResult;
|
|
185
|
+
} else {
|
|
186
|
+
// make a network call to the managed identity source
|
|
187
|
+
return this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
|
188
|
+
managedIdentityRequest,
|
|
189
|
+
this.config.managedIdentityId,
|
|
190
|
+
this.fakeAuthority
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Authority,
|
|
8
|
+
INetworkModule,
|
|
9
|
+
Logger,
|
|
10
|
+
AuthenticationResult,
|
|
11
|
+
} from "@azure/msal-common";
|
|
12
|
+
import { AppService } from "./ManagedIdentitySources/AppService";
|
|
13
|
+
import { AzureArc } from "./ManagedIdentitySources/AzureArc";
|
|
14
|
+
import { CloudShell } from "./ManagedIdentitySources/CloudShell";
|
|
15
|
+
import { Imds } from "./ManagedIdentitySources/Imds";
|
|
16
|
+
import { ServiceFabric } from "./ManagedIdentitySources/ServiceFabric";
|
|
17
|
+
import { CryptoProvider } from "../crypto/CryptoProvider";
|
|
18
|
+
import {
|
|
19
|
+
ManagedIdentityErrorCodes,
|
|
20
|
+
createManagedIdentityError,
|
|
21
|
+
} from "../error/ManagedIdentityError";
|
|
22
|
+
import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest";
|
|
23
|
+
import { ManagedIdentityId } from "../config/ManagedIdentityId";
|
|
24
|
+
import { NodeStorage } from "../cache/NodeStorage";
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Class to initialize a managed identity and identify the service.
|
|
28
|
+
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ManagedIdentityClient.cs
|
|
29
|
+
*/
|
|
30
|
+
export class ManagedIdentityClient {
|
|
31
|
+
private logger: Logger;
|
|
32
|
+
private nodeStorage: NodeStorage;
|
|
33
|
+
private networkClient: INetworkModule;
|
|
34
|
+
private cryptoProvider: CryptoProvider;
|
|
35
|
+
|
|
36
|
+
static identitySource:
|
|
37
|
+
| ServiceFabric
|
|
38
|
+
| AppService
|
|
39
|
+
| CloudShell
|
|
40
|
+
| AzureArc
|
|
41
|
+
| Imds
|
|
42
|
+
| undefined;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
logger: Logger,
|
|
46
|
+
nodeStorage: NodeStorage,
|
|
47
|
+
networkClient: INetworkModule,
|
|
48
|
+
cryptoProvider: CryptoProvider
|
|
49
|
+
) {
|
|
50
|
+
this.logger = logger;
|
|
51
|
+
this.nodeStorage = nodeStorage;
|
|
52
|
+
this.networkClient = networkClient;
|
|
53
|
+
this.cryptoProvider = cryptoProvider;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public async sendManagedIdentityTokenRequest(
|
|
57
|
+
managedIdentityRequest: ManagedIdentityRequest,
|
|
58
|
+
managedIdentityId: ManagedIdentityId,
|
|
59
|
+
fakeAuthority: Authority,
|
|
60
|
+
refreshAccessToken?: boolean
|
|
61
|
+
): Promise<AuthenticationResult> {
|
|
62
|
+
if (!ManagedIdentityClient.identitySource) {
|
|
63
|
+
ManagedIdentityClient.identitySource =
|
|
64
|
+
this.selectManagedIdentitySource(
|
|
65
|
+
this.logger,
|
|
66
|
+
this.nodeStorage,
|
|
67
|
+
this.networkClient,
|
|
68
|
+
this.cryptoProvider,
|
|
69
|
+
managedIdentityId
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return ManagedIdentityClient.identitySource.acquireTokenWithManagedIdentity(
|
|
74
|
+
managedIdentityRequest,
|
|
75
|
+
managedIdentityId,
|
|
76
|
+
fakeAuthority,
|
|
77
|
+
refreshAccessToken
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Tries to create a managed identity source for all sources
|
|
83
|
+
* @returns the managed identity Source
|
|
84
|
+
*/
|
|
85
|
+
private selectManagedIdentitySource(
|
|
86
|
+
logger: Logger,
|
|
87
|
+
nodeStorage: NodeStorage,
|
|
88
|
+
networkClient: INetworkModule,
|
|
89
|
+
cryptoProvider: CryptoProvider,
|
|
90
|
+
managedIdentityId: ManagedIdentityId
|
|
91
|
+
): ServiceFabric | AppService | CloudShell | AzureArc | Imds {
|
|
92
|
+
const source =
|
|
93
|
+
ServiceFabric.tryCreate(
|
|
94
|
+
logger,
|
|
95
|
+
nodeStorage,
|
|
96
|
+
networkClient,
|
|
97
|
+
cryptoProvider,
|
|
98
|
+
managedIdentityId
|
|
99
|
+
) ||
|
|
100
|
+
AppService.tryCreate(
|
|
101
|
+
logger,
|
|
102
|
+
nodeStorage,
|
|
103
|
+
networkClient,
|
|
104
|
+
cryptoProvider
|
|
105
|
+
) ||
|
|
106
|
+
CloudShell.tryCreate(
|
|
107
|
+
logger,
|
|
108
|
+
nodeStorage,
|
|
109
|
+
networkClient,
|
|
110
|
+
cryptoProvider,
|
|
111
|
+
managedIdentityId
|
|
112
|
+
) ||
|
|
113
|
+
AzureArc.tryCreate(
|
|
114
|
+
logger,
|
|
115
|
+
nodeStorage,
|
|
116
|
+
networkClient,
|
|
117
|
+
cryptoProvider,
|
|
118
|
+
managedIdentityId
|
|
119
|
+
) ||
|
|
120
|
+
Imds.tryCreate(logger, nodeStorage, networkClient, cryptoProvider);
|
|
121
|
+
if (!source) {
|
|
122
|
+
throw createManagedIdentityError(
|
|
123
|
+
ManagedIdentityErrorCodes.unableToCreateSource
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return source;
|
|
127
|
+
}
|
|
128
|
+
}
|