@azure/msal-node 2.7.0-alpha.0 → 2.7.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/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +423 -423
- package/dist/cache/NodeStorage.cjs.map +1 -1
- package/dist/cache/NodeStorage.d.ts +193 -193
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/NodeStorage.mjs +424 -424
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.cjs +265 -265
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.mjs +265 -265
- package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
- package/dist/cache/distributed/ICacheClient.d.ts +17 -17
- package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
- package/dist/cache/serializer/Deserializer.cjs +167 -170
- package/dist/cache/serializer/Deserializer.cjs.map +1 -1
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
- package/dist/cache/serializer/Deserializer.mjs +168 -171
- package/dist/cache/serializer/Deserializer.mjs.map +1 -1
- package/dist/cache/serializer/Serializer.cjs +137 -137
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.mjs +137 -137
- package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
- package/dist/client/ClientApplication.cjs +333 -333
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +142 -142
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +333 -333
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.cjs +116 -116
- package/dist/client/ClientAssertion.d.ts +46 -46
- package/dist/client/ClientAssertion.mjs +116 -116
- package/dist/client/ClientCredentialClient.cjs +194 -194
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.mjs +194 -194
- package/dist/client/ConfidentialClientApplication.cjs +163 -163
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.mjs +163 -163
- package/dist/client/DeviceCodeClient.cjs +207 -207
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.mjs +207 -207
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/ManagedIdentityApplication.cjs +79 -78
- package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
- package/dist/client/ManagedIdentityApplication.d.ts +23 -23
- package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
- package/dist/client/ManagedIdentityApplication.mjs +79 -78
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
- package/dist/client/ManagedIdentityClient.cjs +40 -36
- package/dist/client/ManagedIdentityClient.cjs.map +1 -1
- package/dist/client/ManagedIdentityClient.d.ts +19 -24
- package/dist/client/ManagedIdentityClient.d.ts.map +1 -1
- package/dist/client/ManagedIdentityClient.mjs +40 -36
- package/dist/client/ManagedIdentityClient.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.cjs +42 -69
- package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts +16 -16
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +43 -70
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +81 -92
- package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +18 -18
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +84 -95
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +112 -77
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -18
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +114 -80
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +47 -0
- package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +15 -6
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +45 -0
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -0
- package/dist/client/ManagedIdentitySources/Imds.cjs +43 -52
- package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +44 -53
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +61 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +16 -6
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +59 -0
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -0
- package/dist/client/OnBehalfOfClient.cjs +202 -202
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.mjs +202 -202
- package/dist/client/PublicClientApplication.cjs +229 -229
- package/dist/client/PublicClientApplication.d.ts +71 -71
- package/dist/client/PublicClientApplication.mjs +229 -229
- package/dist/client/UsernamePasswordClient.cjs +95 -95
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/config/Configuration.cjs +102 -86
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +123 -122
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +102 -86
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/config/ManagedIdentityId.cjs +48 -48
- package/dist/config/ManagedIdentityId.d.ts +11 -11
- package/dist/config/ManagedIdentityId.mjs +48 -48
- package/dist/config/ManagedIdentityRequestParameters.cjs +28 -29
- package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
- package/dist/config/ManagedIdentityRequestParameters.d.ts.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +28 -29
- package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -1
- package/dist/crypto/CryptoProvider.cjs +75 -75
- package/dist/crypto/CryptoProvider.d.ts +52 -52
- package/dist/crypto/CryptoProvider.mjs +75 -75
- package/dist/crypto/GuidGenerator.cjs +22 -22
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/HashUtils.cjs +13 -13
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/PkceGenerator.cjs +49 -49
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/error/ManagedIdentityError.cjs +39 -28
- package/dist/error/ManagedIdentityError.cjs.map +1 -1
- package/dist/error/ManagedIdentityError.d.ts +27 -21
- package/dist/error/ManagedIdentityError.d.ts.map +1 -1
- package/dist/error/ManagedIdentityError.mjs +40 -29
- package/dist/error/ManagedIdentityError.mjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.cjs +27 -14
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts +19 -9
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +24 -14
- package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
- package/dist/error/NodeAuthError.cjs +85 -85
- package/dist/error/NodeAuthError.d.ts +65 -65
- package/dist/error/NodeAuthError.mjs +85 -85
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +44 -44
- package/dist/index.mjs +1 -1
- package/dist/internals.cjs +8 -8
- package/dist/internals.d.ts +6 -6
- package/dist/internals.mjs +8 -8
- package/dist/network/HttpClient.cjs +283 -283
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +25 -26
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +283 -283
- 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/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.cjs +77 -77
- package/dist/network/LoopbackClient.d.ts +21 -21
- package/dist/network/LoopbackClient.mjs +77 -77
- package/dist/packageMetadata.cjs +4 -4
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +4 -4
- package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
- package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
- package/dist/request/ClientCredentialRequest.d.ts +14 -14
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- package/dist/request/ManagedIdentityRequest.d.ts +8 -8
- package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
- package/dist/request/OnBehalfOfRequest.d.ts +14 -14
- package/dist/request/RefreshTokenRequest.d.ts +17 -17
- package/dist/request/SignOutRequest.d.ts +5 -5
- package/dist/request/SilentFlowRequest.d.ts +16 -16
- package/dist/request/UsernamePasswordRequest.d.ts +19 -19
- package/dist/response/ManagedIdentityTokenResponse.d.ts +24 -24
- 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 +141 -103
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +131 -106
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +133 -100
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +44 -44
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/NetworkUtils.cjs +38 -38
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/package.json +5 -5
- package/src/cache/NodeStorage.ts +4 -9
- package/src/cache/serializer/Deserializer.ts +1 -5
- package/src/client/ClientApplication.ts +5 -4
- package/src/client/ManagedIdentityApplication.ts +3 -3
- package/src/client/ManagedIdentityClient.ts +23 -11
- package/src/client/ManagedIdentitySources/AppService.ts +68 -97
- package/src/client/ManagedIdentitySources/AzureArc.ts +59 -68
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +70 -2
- package/src/client/ManagedIdentitySources/CloudShell.ts +93 -8
- package/src/client/ManagedIdentitySources/Imds.ts +54 -40
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +126 -5
- package/src/config/Configuration.ts +44 -16
- package/src/config/ManagedIdentityRequestParameters.ts +1 -6
- package/src/error/ManagedIdentityError.ts +15 -2
- package/src/error/ManagedIdentityErrorCodes.ts +19 -0
- package/src/network/HttpClient.ts +6 -11
- package/src/network/HttpClientWithRetries.ts +80 -0
- package/src/packageMetadata.ts +1 -1
- package/src/retry/IHttpRetryPolicy.ts +18 -0
- package/src/retry/LinearRetryPolicy.ts +71 -0
- package/src/utils/Constants.ts +43 -7
|
@@ -3,17 +3,138 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { INetworkModule, Logger } from "@azure/msal-common";
|
|
6
7
|
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
7
8
|
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
8
9
|
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
10
|
+
import { NodeStorage } from "../../cache/NodeStorage";
|
|
11
|
+
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
12
|
+
import {
|
|
13
|
+
API_VERSION_QUERY_PARAMETER_NAME,
|
|
14
|
+
HttpMethod,
|
|
15
|
+
ManagedIdentityEnvironmentVariableNames,
|
|
16
|
+
ManagedIdentityIdType,
|
|
17
|
+
ManagedIdentitySourceNames,
|
|
18
|
+
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
19
|
+
SERVICE_FABRIC_SECRET_HEADER_NAME,
|
|
20
|
+
} from "../../utils/Constants";
|
|
9
21
|
|
|
22
|
+
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
23
|
+
const SERVICE_FABRIC_MSI_API_VERSION: string = "2019-07-01-preview";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ServiceFabricManagedIdentitySource.cs
|
|
27
|
+
*/
|
|
10
28
|
export class ServiceFabric extends BaseManagedIdentitySource {
|
|
29
|
+
private identityEndpoint: string;
|
|
30
|
+
private identityHeader: string;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
logger: Logger,
|
|
34
|
+
nodeStorage: NodeStorage,
|
|
35
|
+
networkClient: INetworkModule,
|
|
36
|
+
cryptoProvider: CryptoProvider,
|
|
37
|
+
identityEndpoint: string,
|
|
38
|
+
identityHeader: string
|
|
39
|
+
) {
|
|
40
|
+
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
41
|
+
|
|
42
|
+
this.identityEndpoint = identityEndpoint;
|
|
43
|
+
this.identityHeader = identityHeader;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static tryCreate(
|
|
47
|
+
logger: Logger,
|
|
48
|
+
nodeStorage: NodeStorage,
|
|
49
|
+
networkClient: INetworkModule,
|
|
50
|
+
cryptoProvider: CryptoProvider,
|
|
51
|
+
managedIdentityId: ManagedIdentityId
|
|
52
|
+
): ServiceFabric | null {
|
|
53
|
+
const identityEndpoint: string | undefined =
|
|
54
|
+
process.env[
|
|
55
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
|
56
|
+
];
|
|
57
|
+
const identityHeader: string | undefined =
|
|
58
|
+
process.env[
|
|
59
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER
|
|
60
|
+
];
|
|
61
|
+
const identityServerThumbprint: string | undefined =
|
|
62
|
+
process.env[
|
|
63
|
+
ManagedIdentityEnvironmentVariableNames
|
|
64
|
+
.IDENTITY_SERVER_THUMBPRINT
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* if either of the identity endpoint, identity header, or identity server thumbprint
|
|
69
|
+
* environment variables are undefined, this MSI provider is unavailable.
|
|
70
|
+
*/
|
|
71
|
+
if (!identityEndpoint || !identityHeader || !identityServerThumbprint) {
|
|
72
|
+
logger.info(
|
|
73
|
+
`[Managed Identity] ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity is unavailable because one or all of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}', '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' or '${ManagedIdentityEnvironmentVariableNames.IDENTITY_SERVER_THUMBPRINT}' environment variables are not defined.`
|
|
74
|
+
);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const validatedIdentityEndpoint: string =
|
|
79
|
+
ServiceFabric.getValidatedEnvVariableUrlString(
|
|
80
|
+
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
|
81
|
+
identityEndpoint,
|
|
82
|
+
ManagedIdentitySourceNames.SERVICE_FABRIC,
|
|
83
|
+
logger
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
logger.info(
|
|
87
|
+
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity.`
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
92
|
+
) {
|
|
93
|
+
logger.warning(
|
|
94
|
+
`[Managed Identity] ${ManagedIdentitySourceNames.SERVICE_FABRIC} user assigned managed identity is configured in the cluster, not during runtime. See also: https://learn.microsoft.com/en-us/azure/service-fabric/configure-existing-cluster-enable-managed-identity-token-service.`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return new ServiceFabric(
|
|
99
|
+
logger,
|
|
100
|
+
nodeStorage,
|
|
101
|
+
networkClient,
|
|
102
|
+
cryptoProvider,
|
|
103
|
+
identityEndpoint,
|
|
104
|
+
identityHeader
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
11
108
|
public createRequest(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
-
_managedIdentityId: ManagedIdentityId
|
|
109
|
+
resource: string,
|
|
110
|
+
managedIdentityId: ManagedIdentityId
|
|
16
111
|
): ManagedIdentityRequestParameters {
|
|
17
|
-
|
|
112
|
+
const request: ManagedIdentityRequestParameters =
|
|
113
|
+
new ManagedIdentityRequestParameters(
|
|
114
|
+
HttpMethod.GET,
|
|
115
|
+
this.identityEndpoint
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
request.headers[SERVICE_FABRIC_SECRET_HEADER_NAME] =
|
|
119
|
+
this.identityHeader;
|
|
120
|
+
|
|
121
|
+
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
122
|
+
SERVICE_FABRIC_MSI_API_VERSION;
|
|
123
|
+
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
124
|
+
resource;
|
|
125
|
+
|
|
126
|
+
if (
|
|
127
|
+
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
128
|
+
) {
|
|
129
|
+
request.queryParameters[
|
|
130
|
+
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
131
|
+
managedIdentityId.idType
|
|
132
|
+
)
|
|
133
|
+
] = managedIdentityId.id;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
137
|
+
|
|
138
|
+
return request;
|
|
18
139
|
}
|
|
19
140
|
}
|
|
@@ -19,6 +19,13 @@ import { HttpClient } from "../network/HttpClient.js";
|
|
|
19
19
|
import http from "http";
|
|
20
20
|
import https from "https";
|
|
21
21
|
import { ManagedIdentityId } from "./ManagedIdentityId.js";
|
|
22
|
+
import {
|
|
23
|
+
MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON,
|
|
24
|
+
MANAGED_IDENTITY_MAX_RETRIES,
|
|
25
|
+
MANAGED_IDENTITY_RETRY_DELAY,
|
|
26
|
+
} from "../utils/Constants.js";
|
|
27
|
+
import { LinearRetryPolicy } from "../retry/LinearRetryPolicy.js";
|
|
28
|
+
import { HttpClientWithRetries } from "../network/HttpClientWithRetries.js";
|
|
22
29
|
|
|
23
30
|
/**
|
|
24
31
|
* - clientId - Client id of the application.
|
|
@@ -84,6 +91,7 @@ export type NodeSystemOptions = {
|
|
|
84
91
|
networkClient?: INetworkModule;
|
|
85
92
|
proxyUrl?: string;
|
|
86
93
|
customAgentOptions?: http.AgentOptions | https.AgentOptions;
|
|
94
|
+
disableInternalRetries?: boolean;
|
|
87
95
|
};
|
|
88
96
|
|
|
89
97
|
export type NodeTelemetryOptions = {
|
|
@@ -158,6 +166,7 @@ const DEFAULT_SYSTEM_OPTIONS: Required<NodeSystemOptions> = {
|
|
|
158
166
|
networkClient: new HttpClient(),
|
|
159
167
|
proxyUrl: Constants.EMPTY_STRING,
|
|
160
168
|
customAgentOptions: {} as http.AgentOptions | https.AgentOptions,
|
|
169
|
+
disableInternalRetries: false,
|
|
161
170
|
};
|
|
162
171
|
|
|
163
172
|
const DEFAULT_TELEMETRY_OPTIONS: Required<NodeTelemetryOptions> = {
|
|
@@ -198,12 +207,10 @@ export function buildAppConfiguration({
|
|
|
198
207
|
...DEFAULT_SYSTEM_OPTIONS,
|
|
199
208
|
networkClient: new HttpClient(
|
|
200
209
|
system?.proxyUrl,
|
|
201
|
-
system?.customAgentOptions as
|
|
202
|
-
| http.AgentOptions
|
|
203
|
-
| https.AgentOptions,
|
|
204
|
-
false // Managed Identity
|
|
210
|
+
system?.customAgentOptions as http.AgentOptions | https.AgentOptions
|
|
205
211
|
),
|
|
206
212
|
loggerOptions: system?.loggerOptions || DEFAULT_LOGGER_OPTIONS,
|
|
213
|
+
disableInternalRetries: system?.disableInternalRetries || false,
|
|
207
214
|
};
|
|
208
215
|
|
|
209
216
|
return {
|
|
@@ -217,7 +224,9 @@ export function buildAppConfiguration({
|
|
|
217
224
|
|
|
218
225
|
export type ManagedIdentityNodeConfiguration = {
|
|
219
226
|
managedIdentityId: ManagedIdentityId;
|
|
220
|
-
system: Required<
|
|
227
|
+
system: Required<
|
|
228
|
+
Pick<NodeSystemOptions, "loggerOptions" | "networkClient">
|
|
229
|
+
>;
|
|
221
230
|
};
|
|
222
231
|
|
|
223
232
|
export function buildManagedIdentityConfiguration({
|
|
@@ -228,20 +237,39 @@ export function buildManagedIdentityConfiguration({
|
|
|
228
237
|
managedIdentityIdParams
|
|
229
238
|
);
|
|
230
239
|
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
240
|
+
const loggerOptions: LoggerOptions =
|
|
241
|
+
system?.loggerOptions || DEFAULT_LOGGER_OPTIONS;
|
|
242
|
+
|
|
243
|
+
let networkClient: INetworkModule;
|
|
244
|
+
// use developer provided network client if passed in
|
|
245
|
+
if (system?.networkClient) {
|
|
246
|
+
networkClient = system.networkClient;
|
|
247
|
+
// otherwise, create a new one
|
|
248
|
+
} else {
|
|
249
|
+
networkClient = new HttpClient(
|
|
235
250
|
system?.proxyUrl,
|
|
236
|
-
system?.customAgentOptions as
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
251
|
+
system?.customAgentOptions as http.AgentOptions | https.AgentOptions
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// wrap the network client with a retry policy if the developer has not disabled the option to do so
|
|
256
|
+
if (!system?.disableInternalRetries) {
|
|
257
|
+
const linearRetryPolicy: LinearRetryPolicy = new LinearRetryPolicy(
|
|
258
|
+
MANAGED_IDENTITY_MAX_RETRIES,
|
|
259
|
+
MANAGED_IDENTITY_RETRY_DELAY,
|
|
260
|
+
MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON
|
|
261
|
+
);
|
|
262
|
+
networkClient = new HttpClientWithRetries(
|
|
263
|
+
networkClient,
|
|
264
|
+
linearRetryPolicy
|
|
265
|
+
);
|
|
266
|
+
}
|
|
242
267
|
|
|
243
268
|
return {
|
|
244
269
|
managedIdentityId: managedIdentityId,
|
|
245
|
-
system: {
|
|
270
|
+
system: {
|
|
271
|
+
loggerOptions,
|
|
272
|
+
networkClient,
|
|
273
|
+
},
|
|
246
274
|
};
|
|
247
275
|
}
|
|
@@ -43,11 +43,6 @@ export class ManagedIdentityRequestParameters {
|
|
|
43
43
|
parameterBuilder.addExtraQueryParameters(this.bodyParameters);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return UrlString.appendQueryString(
|
|
49
|
-
this._baseEndpoint,
|
|
50
|
-
bodyParametersString
|
|
51
|
-
);
|
|
46
|
+
return parameterBuilder.createQueryString();
|
|
52
47
|
}
|
|
53
48
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { AuthError } from "@azure/msal-common";
|
|
7
7
|
import * as ManagedIdentityErrorCodes from "./ManagedIdentityErrorCodes";
|
|
8
|
+
import { ManagedIdentityEnvironmentVariableNames } from "../utils/Constants";
|
|
8
9
|
export { ManagedIdentityErrorCodes };
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -17,14 +18,26 @@ export const ManagedIdentityErrorMessages = {
|
|
|
17
18
|
"The supplied resource is an invalid URL.",
|
|
18
19
|
[ManagedIdentityErrorCodes.missingId]:
|
|
19
20
|
"A ManagedIdentityId id was not provided.",
|
|
21
|
+
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
|
22
|
+
.AZURE_POD_IDENTITY_AUTHORITY_HOST]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST}' environment variable is malformed.`,
|
|
23
|
+
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
|
24
|
+
.IDENTITY_ENDPOINT]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' environment variable is malformed.`,
|
|
25
|
+
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
|
26
|
+
.IMDS_ENDPOINT]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT}' environment variable is malformed.`,
|
|
27
|
+
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
|
28
|
+
.MSI_ENDPOINT]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT}' environment variable is malformed.`,
|
|
29
|
+
[ManagedIdentityErrorCodes.networkUnavailable]:
|
|
30
|
+
"Authentication unavailable. The request to the managed identity endpoint timed out.",
|
|
20
31
|
[ManagedIdentityErrorCodes.unableToCreateAzureArc]:
|
|
21
32
|
"Azure Arc Managed Identities can only be system assigned.",
|
|
33
|
+
[ManagedIdentityErrorCodes.unableToCreateCloudShell]:
|
|
34
|
+
"Cloud Shell Managed Identities can only be system assigned.",
|
|
22
35
|
[ManagedIdentityErrorCodes.unableToCreateSource]:
|
|
23
36
|
"Unable to create a Managed Identity source based on environment variables.",
|
|
24
37
|
[ManagedIdentityErrorCodes.unableToReadSecretFile]:
|
|
25
38
|
"Unable to read the secret file.",
|
|
26
|
-
[ManagedIdentityErrorCodes.
|
|
27
|
-
"
|
|
39
|
+
[ManagedIdentityErrorCodes.userAssignedNotAvailableAtRuntime]:
|
|
40
|
+
"Service Fabric user assigned managed identity ClientId or ResourceId is not configurable at runtime.",
|
|
28
41
|
[ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing]:
|
|
29
42
|
"A 401 response was received form the Azure Arc Managed Identity, but the www-authenticate header is missing.",
|
|
30
43
|
[ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat]:
|
|
@@ -3,13 +3,32 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { ManagedIdentityEnvironmentVariableNames } from "../utils/Constants";
|
|
7
|
+
|
|
6
8
|
export const invalidManagedIdentityIdType = "invalid_managed_identity_id_type";
|
|
7
9
|
export const invalidResource = "invalid_resource";
|
|
8
10
|
export const missingId = "missing_client_id";
|
|
11
|
+
export const networkUnavailable = "network_unavailable";
|
|
9
12
|
export const unableToCreateAzureArc = "unable_to_create_azure_arc";
|
|
13
|
+
export const unableToCreateCloudShell = "unable_to_create_cloud_shell";
|
|
10
14
|
export const unableToCreateSource = "unable_to_create_source";
|
|
11
15
|
export const unableToReadSecretFile = "unable_to_read_secret_file";
|
|
12
16
|
export const urlParseError = "url_parse_error";
|
|
17
|
+
export const userAssignedNotAvailableAtRuntime =
|
|
18
|
+
"user_assigned_not_available_at_runtime";
|
|
13
19
|
export const wwwAuthenticateHeaderMissing = "www_authenticate_header_missing";
|
|
14
20
|
export const wwwAuthenticateHeaderUnsupportedFormat =
|
|
15
21
|
"www_authenticate_header_unsupported_format";
|
|
22
|
+
|
|
23
|
+
export const MsiEnvironmentVariableUrlMalformedErrorCodes = {
|
|
24
|
+
[ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST]:
|
|
25
|
+
"azure_pod_identity_authority_host_url_malformed",
|
|
26
|
+
[ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT]:
|
|
27
|
+
"identity_endpoint_url_malformed",
|
|
28
|
+
[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT]:
|
|
29
|
+
"imds_endpoint_url_malformed",
|
|
30
|
+
[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT]:
|
|
31
|
+
"msi_endpoint_url_malformed",
|
|
32
|
+
} as const;
|
|
33
|
+
export type MsiEnvironmentVariableErrorCodes =
|
|
34
|
+
(typeof MsiEnvironmentVariableUrlMalformedErrorCodes)[keyof typeof MsiEnvironmentVariableUrlMalformedErrorCodes];
|
|
@@ -20,16 +20,13 @@ 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;
|
|
24
23
|
|
|
25
24
|
constructor(
|
|
26
25
|
proxyUrl?: string,
|
|
27
|
-
customAgentOptions?: http.AgentOptions | https.AgentOptions
|
|
28
|
-
managedIdentity?: boolean
|
|
26
|
+
customAgentOptions?: http.AgentOptions | https.AgentOptions
|
|
29
27
|
) {
|
|
30
28
|
this.proxyUrl = proxyUrl || "";
|
|
31
29
|
this.customAgentOptions = customAgentOptions || {};
|
|
32
|
-
this.managedIdentity = managedIdentity || false;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
/**
|
|
@@ -55,8 +52,7 @@ export class HttpClient implements INetworkModule {
|
|
|
55
52
|
HttpMethod.GET,
|
|
56
53
|
options,
|
|
57
54
|
this.customAgentOptions as https.AgentOptions,
|
|
58
|
-
undefined
|
|
59
|
-
this.managedIdentity
|
|
55
|
+
undefined
|
|
60
56
|
);
|
|
61
57
|
}
|
|
62
58
|
}
|
|
@@ -86,8 +82,7 @@ export class HttpClient implements INetworkModule {
|
|
|
86
82
|
HttpMethod.POST,
|
|
87
83
|
options,
|
|
88
84
|
this.customAgentOptions as https.AgentOptions,
|
|
89
|
-
cancellationToken
|
|
90
|
-
this.managedIdentity
|
|
85
|
+
cancellationToken
|
|
91
86
|
);
|
|
92
87
|
}
|
|
93
88
|
}
|
|
@@ -283,8 +278,7 @@ const networkRequestViaHttps = <T>(
|
|
|
283
278
|
httpMethod: string,
|
|
284
279
|
options?: NetworkRequestOptions,
|
|
285
280
|
agentOptions?: https.AgentOptions,
|
|
286
|
-
timeout?: number
|
|
287
|
-
managedIdentity?: boolean
|
|
281
|
+
timeout?: number
|
|
288
282
|
): Promise<NetworkResponse<T>> => {
|
|
289
283
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
290
284
|
const body: string = options?.body || "";
|
|
@@ -315,7 +309,8 @@ const networkRequestViaHttps = <T>(
|
|
|
315
309
|
|
|
316
310
|
return new Promise<NetworkResponse<T>>((resolve, reject) => {
|
|
317
311
|
let request: http.ClientRequest;
|
|
318
|
-
|
|
312
|
+
// managed identity sources use http instead of https
|
|
313
|
+
if (customOptions.protocol === "http:") {
|
|
319
314
|
request = http.request(customOptions);
|
|
320
315
|
} else {
|
|
321
316
|
request = https.request(customOptions);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
HeaderNames,
|
|
8
|
+
INetworkModule,
|
|
9
|
+
NetworkRequestOptions,
|
|
10
|
+
NetworkResponse,
|
|
11
|
+
} from "@azure/msal-common";
|
|
12
|
+
import { IHttpRetryPolicy } from "../retry/IHttpRetryPolicy";
|
|
13
|
+
import { HttpMethod } from "../utils/Constants";
|
|
14
|
+
|
|
15
|
+
export class HttpClientWithRetries implements INetworkModule {
|
|
16
|
+
private httpClientNoRetries: INetworkModule;
|
|
17
|
+
private retryPolicy: IHttpRetryPolicy;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
httpClientNoRetries: INetworkModule,
|
|
21
|
+
retryPolicy: IHttpRetryPolicy
|
|
22
|
+
) {
|
|
23
|
+
this.httpClientNoRetries = httpClientNoRetries;
|
|
24
|
+
this.retryPolicy = retryPolicy;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async sendNetworkRequestAsyncHelper<T>(
|
|
28
|
+
httpMethod: HttpMethod,
|
|
29
|
+
url: string,
|
|
30
|
+
options?: NetworkRequestOptions
|
|
31
|
+
): Promise<NetworkResponse<T>> {
|
|
32
|
+
if (httpMethod === HttpMethod.GET) {
|
|
33
|
+
return this.httpClientNoRetries.sendGetRequestAsync(url, options);
|
|
34
|
+
} else {
|
|
35
|
+
return this.httpClientNoRetries.sendPostRequestAsync(url, options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private async sendNetworkRequestAsync<T>(
|
|
40
|
+
httpMethod: HttpMethod,
|
|
41
|
+
url: string,
|
|
42
|
+
options?: NetworkRequestOptions
|
|
43
|
+
): Promise<NetworkResponse<T>> {
|
|
44
|
+
// the underlying network module (custom or HttpClient) will make the call
|
|
45
|
+
let response: NetworkResponse<T> =
|
|
46
|
+
await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
|
|
47
|
+
|
|
48
|
+
let currentRetry: number = 0;
|
|
49
|
+
while (
|
|
50
|
+
await this.retryPolicy.pauseForRetry(
|
|
51
|
+
response.status,
|
|
52
|
+
currentRetry,
|
|
53
|
+
response.headers[HeaderNames.RETRY_AFTER]
|
|
54
|
+
)
|
|
55
|
+
) {
|
|
56
|
+
response = await this.sendNetworkRequestAsyncHelper(
|
|
57
|
+
httpMethod,
|
|
58
|
+
url,
|
|
59
|
+
options
|
|
60
|
+
);
|
|
61
|
+
currentRetry++;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async sendGetRequestAsync<T>(
|
|
68
|
+
url: string,
|
|
69
|
+
options?: NetworkRequestOptions
|
|
70
|
+
): Promise<NetworkResponse<T>> {
|
|
71
|
+
return this.sendNetworkRequestAsync(HttpMethod.GET, url, options);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public async sendPostRequestAsync<T>(
|
|
75
|
+
url: string,
|
|
76
|
+
options?: NetworkRequestOptions
|
|
77
|
+
): Promise<NetworkResponse<T>> {
|
|
78
|
+
return this.sendNetworkRequestAsync(HttpMethod.POST, url, options);
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/packageMetadata.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import http from "http";
|
|
7
|
+
|
|
8
|
+
export interface IHttpRetryPolicy {
|
|
9
|
+
/*
|
|
10
|
+
* if retry conditions occur, pauses and returns true
|
|
11
|
+
* otherwise return false
|
|
12
|
+
*/
|
|
13
|
+
pauseForRetry(
|
|
14
|
+
httpStatusCode: number,
|
|
15
|
+
currentRetry: number,
|
|
16
|
+
retryAfterHeader: http.IncomingHttpHeaders["retry-after"]
|
|
17
|
+
): Promise<boolean>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import http from "http";
|
|
7
|
+
import { IHttpRetryPolicy } from "./IHttpRetryPolicy";
|
|
8
|
+
|
|
9
|
+
export class LinearRetryPolicy implements IHttpRetryPolicy {
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
retryDelay: number;
|
|
12
|
+
httpStatusCodesToRetryOn: Array<number>;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
maxRetries: number,
|
|
16
|
+
retryDelay: number,
|
|
17
|
+
httpStatusCodesToRetryOn: Array<number>
|
|
18
|
+
) {
|
|
19
|
+
this.maxRetries = maxRetries;
|
|
20
|
+
this.retryDelay = retryDelay;
|
|
21
|
+
this.httpStatusCodesToRetryOn = httpStatusCodesToRetryOn;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private retryAfterMillisecondsToSleep(
|
|
25
|
+
retryHeader: http.IncomingHttpHeaders["retry-after"]
|
|
26
|
+
): number {
|
|
27
|
+
if (!retryHeader) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// retry-after header is in seconds
|
|
32
|
+
let millisToSleep = Math.round(parseFloat(retryHeader) * 1000);
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* retry-after header is in HTTP Date format
|
|
36
|
+
* <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
|
|
37
|
+
*/
|
|
38
|
+
if (isNaN(millisToSleep)) {
|
|
39
|
+
millisToSleep = Math.max(
|
|
40
|
+
0,
|
|
41
|
+
// .valueOf() is needed to subtract dates in TypeScript
|
|
42
|
+
new Date(retryHeader).valueOf() - new Date().valueOf()
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return millisToSleep;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async pauseForRetry(
|
|
50
|
+
httpStatusCode: number,
|
|
51
|
+
currentRetry: number,
|
|
52
|
+
retryAfterHeader: http.IncomingHttpHeaders["retry-after"]
|
|
53
|
+
): Promise<boolean> {
|
|
54
|
+
if (
|
|
55
|
+
this.httpStatusCodesToRetryOn.includes(httpStatusCode) &&
|
|
56
|
+
currentRetry < this.maxRetries
|
|
57
|
+
) {
|
|
58
|
+
const retryAfterDelay: number =
|
|
59
|
+
this.retryAfterMillisecondsToSleep(retryAfterHeader);
|
|
60
|
+
|
|
61
|
+
await new Promise((resolve) => {
|
|
62
|
+
// retryAfterHeader value of 0 evaluates to false, and this.retryDelay will be used
|
|
63
|
+
return setTimeout(resolve, retryAfterDelay || this.retryDelay);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/utils/Constants.ts
CHANGED
|
@@ -3,20 +3,45 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { HttpStatus } from "@azure/msal-common";
|
|
7
|
+
|
|
6
8
|
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
7
9
|
export const AUTHORIZATION_HEADER_NAME: string = "Authorization";
|
|
8
10
|
export const METADATA_HEADER_NAME: string = "Metadata";
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
13
|
-
export const MANAGED_IDENTITY_RESOURCE_ID = "mi_res_id";
|
|
11
|
+
export const APP_SERVICE_SECRET_HEADER_NAME: string = "X-IDENTITY-HEADER";
|
|
12
|
+
export const SERVICE_FABRIC_SECRET_HEADER_NAME: string = "secret";
|
|
13
|
+
export const API_VERSION_QUERY_PARAMETER_NAME: string = "api-version";
|
|
14
|
+
export const RESOURCE_BODY_OR_QUERY_PARAMETER_NAME: string = "resource";
|
|
14
15
|
export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
|
|
15
16
|
export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
|
|
16
17
|
export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Managed Identity Environment Variable Names
|
|
21
|
+
*/
|
|
22
|
+
export 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
|
+
} as const;
|
|
30
|
+
export type ManagedIdentityEnvironmentVariableNames =
|
|
31
|
+
(typeof ManagedIdentityEnvironmentVariableNames)[keyof typeof ManagedIdentityEnvironmentVariableNames];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Managed Identity Source Names
|
|
35
|
+
*/
|
|
36
|
+
export const ManagedIdentitySourceNames = {
|
|
37
|
+
APP_SERVICE: "App Service",
|
|
38
|
+
AZURE_ARC: "Azure Arc",
|
|
39
|
+
CLOUD_SHELL: "Cloud Shell",
|
|
40
|
+
IMDS: "IMDS",
|
|
41
|
+
SERVICE_FABRIC: "Service Fabric",
|
|
42
|
+
} as const;
|
|
43
|
+
export type ManagedIdentitySourceNames =
|
|
44
|
+
(typeof ManagedIdentitySourceNames)[keyof typeof ManagedIdentitySourceNames];
|
|
20
45
|
|
|
21
46
|
/**
|
|
22
47
|
* Managed Identity Ids
|
|
@@ -128,3 +153,14 @@ export const LOOPBACK_SERVER_CONSTANTS = {
|
|
|
128
153
|
INTERVAL_MS: 100,
|
|
129
154
|
TIMEOUT_MS: 5000,
|
|
130
155
|
};
|
|
156
|
+
|
|
157
|
+
export const MANAGED_IDENTITY_MAX_RETRIES = 3;
|
|
158
|
+
export const MANAGED_IDENTITY_RETRY_DELAY = 1000;
|
|
159
|
+
export const MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON = [
|
|
160
|
+
HttpStatus.NOT_FOUND,
|
|
161
|
+
HttpStatus.REQUEST_TIMEOUT,
|
|
162
|
+
HttpStatus.TOO_MANY_REQUESTS,
|
|
163
|
+
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
164
|
+
HttpStatus.SERVICE_UNAVAILABLE,
|
|
165
|
+
HttpStatus.GATEWAY_TIMEOUT,
|
|
166
|
+
];
|