@azure/msal-node 2.6.6 → 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/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 +20 -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 +33 -1
- 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 +33 -2
- 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 +10 -3
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +10 -3
- 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.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 +4 -4
- package/src/client/ClientCredentialClient.ts +65 -25
- package/src/client/ManagedIdentityApplication.ts +194 -0
- package/src/client/ManagedIdentityClient.ts +123 -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 +74 -0
- 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 +9 -2
- 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
|
@@ -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,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
|
+
};
|
|
@@ -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,6 +3,58 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { HttpStatus } from "@azure/msal-common";
|
|
7
|
+
|
|
8
|
+
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
9
|
+
export const AUTHORIZATION_HEADER_NAME: string = "Authorization";
|
|
10
|
+
export const METADATA_HEADER_NAME: string = "Metadata";
|
|
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";
|
|
15
|
+
export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
|
|
16
|
+
export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
|
|
17
|
+
export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
|
|
18
|
+
|
|
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];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Managed Identity Ids
|
|
48
|
+
*/
|
|
49
|
+
export const ManagedIdentityIdType = {
|
|
50
|
+
SYSTEM_ASSIGNED: "system-assigned",
|
|
51
|
+
USER_ASSIGNED_CLIENT_ID: "user-assigned-client-id",
|
|
52
|
+
USER_ASSIGNED_RESOURCE_ID: "user-assigned-resource-id",
|
|
53
|
+
USER_ASSIGNED_OBJECT_ID: "user-assigned-object-id",
|
|
54
|
+
} as const;
|
|
55
|
+
export type ManagedIdentityIdType =
|
|
56
|
+
(typeof ManagedIdentityIdType)[keyof typeof ManagedIdentityIdType];
|
|
57
|
+
|
|
6
58
|
/**
|
|
7
59
|
* http methods
|
|
8
60
|
*/
|
|
@@ -101,3 +153,14 @@ export const LOOPBACK_SERVER_CONSTANTS = {
|
|
|
101
153
|
INTERVAL_MS: 100,
|
|
102
154
|
TIMEOUT_MS: 5000,
|
|
103
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
|
+
];
|