@azure/msal-node 5.0.0-alpha.0 → 5.0.1
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/CacheHelpers.mjs +1 -1
- package/dist/cache/NodeStorage.mjs +1 -1
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
- package/dist/cache/serializer/Deserializer.mjs +1 -1
- package/dist/cache/serializer/Deserializer.mjs.map +1 -1
- package/dist/cache/serializer/Serializer.mjs +1 -1
- package/dist/cache/serializer/Serializer.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +42 -0
- package/dist/client/BaseClient.d.ts.map +1 -0
- package/dist/client/BaseClient.mjs +68 -0
- package/dist/client/BaseClient.mjs.map +1 -0
- package/dist/client/ClientApplication.mjs +1 -1
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.mjs +1 -1
- package/dist/client/ClientAssertion.mjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +2 -1
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +4 -3
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +1 -1
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.d.ts +2 -1
- package/dist/client/DeviceCodeClient.d.ts.map +1 -1
- package/dist/client/DeviceCodeClient.mjs +6 -5
- package/dist/client/DeviceCodeClient.mjs.map +1 -1
- package/dist/client/ManagedIdentityApplication.mjs +1 -1
- package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
- package/dist/client/ManagedIdentityClient.mjs +1 -1
- package/dist/client/ManagedIdentityClient.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts +54 -0
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +55 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +82 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +81 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +55 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +44 -22
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +44 -22
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
- package/dist/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs +66 -1
- package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +57 -23
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts +2 -1
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.mjs +4 -3
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.mjs +21 -5
- package/dist/client/PublicClientApplication.mjs.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts +2 -1
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.mjs +4 -3
- package/dist/client/UsernamePasswordClient.mjs.map +1 -1
- package/dist/config/Configuration.d.ts +0 -6
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +3 -5
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/config/ManagedIdentityId.mjs +1 -1
- package/dist/config/ManagedIdentityId.mjs.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +3 -3
- package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -1
- package/dist/crypto/CryptoProvider.mjs +1 -1
- package/dist/crypto/CryptoProvider.mjs.map +1 -1
- package/dist/crypto/GuidGenerator.mjs +1 -1
- package/dist/crypto/GuidGenerator.mjs.map +1 -1
- package/dist/crypto/HashUtils.mjs +1 -1
- package/dist/crypto/HashUtils.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/error/ClientAuthErrorCodes.mjs +1 -1
- package/dist/error/ManagedIdentityError.mjs +1 -1
- package/dist/error/ManagedIdentityError.mjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +1 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
- package/dist/error/NodeAuthError.d.ts +8 -0
- package/dist/error/NodeAuthError.d.ts.map +1 -1
- package/dist/error/NodeAuthError.mjs +11 -1
- package/dist/error/NodeAuthError.mjs.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -7
- package/dist/index.mjs.map +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/network/HttpClient.d.ts +54 -14
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +140 -262
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/HttpClientWithRetries.mjs +1 -1
- package/dist/network/HttpClientWithRetries.mjs.map +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/protocol/Authorize.mjs +2 -2
- package/dist/protocol/Authorize.mjs.map +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts +12 -10
- package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/AuthorizationUrlRequest.d.ts +6 -24
- package/dist/request/AuthorizationUrlRequest.d.ts.map +1 -1
- package/dist/request/ClientCredentialRequest.d.ts +3 -6
- package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/CommonClientCredentialRequest.d.ts +10 -7
- package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/CommonDeviceCodeRequest.d.ts +13 -10
- package/dist/request/CommonDeviceCodeRequest.d.ts.map +1 -1
- package/dist/request/CommonOnBehalfOfRequest.d.ts +8 -7
- package/dist/request/CommonOnBehalfOfRequest.d.ts.map +1 -1
- package/dist/request/CommonUsernamePasswordRequest.d.ts +6 -8
- package/dist/request/CommonUsernamePasswordRequest.d.ts.map +1 -1
- package/dist/request/DeviceCodeRequest.d.ts +6 -6
- package/dist/request/DeviceCodeRequest.d.ts.map +1 -1
- package/dist/request/InteractiveRequest.d.ts +19 -8
- package/dist/request/InteractiveRequest.d.ts.map +1 -1
- package/dist/request/ManagedIdentityRequest.d.ts +6 -2
- package/dist/request/ManagedIdentityRequest.d.ts.map +1 -1
- package/dist/request/ManagedIdentityRequestParams.d.ts +9 -3
- package/dist/request/ManagedIdentityRequestParams.d.ts.map +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts +7 -6
- package/dist/request/OnBehalfOfRequest.d.ts.map +1 -1
- package/dist/request/RefreshTokenRequest.d.ts +9 -7
- package/dist/request/RefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/SilentFlowRequest.d.ts +6 -7
- package/dist/request/SilentFlowRequest.d.ts.map +1 -1
- package/dist/request/UsernamePasswordRequest.d.ts +9 -8
- package/dist/request/UsernamePasswordRequest.d.ts.map +1 -1
- package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs +1 -1
- package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs.map +1 -1
- package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
- package/dist/retry/ExponentialRetryStrategy.mjs.map +1 -1
- package/dist/retry/ImdsRetryPolicy.mjs +1 -1
- package/dist/retry/ImdsRetryPolicy.mjs.map +1 -1
- package/dist/retry/LinearRetryStrategy.mjs +1 -1
- package/dist/retry/LinearRetryStrategy.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +2 -9
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +4 -12
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.mjs +1 -1
- package/dist/utils/EncodingUtils.mjs.map +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs.map +1 -1
- package/lib/msal-node.cjs +5788 -5371
- package/lib/msal-node.cjs.map +1 -1
- package/lib/types/client/BaseClient.d.ts +42 -0
- package/lib/types/client/BaseClient.d.ts.map +1 -0
- package/lib/types/client/ClientCredentialClient.d.ts +2 -1
- package/lib/types/client/ClientCredentialClient.d.ts.map +1 -1
- package/lib/types/client/DeviceCodeClient.d.ts +2 -1
- package/lib/types/client/DeviceCodeClient.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/AppService.d.ts +54 -0
- package/lib/types/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts +81 -0
- package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +93 -2
- package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts +54 -0
- package/lib/types/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/Imds.d.ts +44 -22
- package/lib/types/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts +65 -0
- package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
- package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts +56 -22
- package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
- package/lib/types/client/OnBehalfOfClient.d.ts +2 -1
- package/lib/types/client/OnBehalfOfClient.d.ts.map +1 -1
- package/lib/types/client/PublicClientApplication.d.ts.map +1 -1
- package/lib/types/client/UsernamePasswordClient.d.ts +2 -1
- package/lib/types/client/UsernamePasswordClient.d.ts.map +1 -1
- package/lib/types/config/Configuration.d.ts +0 -6
- package/lib/types/config/Configuration.d.ts.map +1 -1
- package/lib/types/error/NodeAuthError.d.ts +8 -0
- package/lib/types/error/NodeAuthError.d.ts.map +1 -1
- package/lib/types/index.d.ts +0 -6
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/network/HttpClient.d.ts +54 -14
- package/lib/types/network/HttpClient.d.ts.map +1 -1
- package/lib/types/packageMetadata.d.ts +1 -1
- package/lib/types/packageMetadata.d.ts.map +1 -1
- package/lib/types/request/AuthorizationCodeRequest.d.ts +12 -10
- package/lib/types/request/AuthorizationCodeRequest.d.ts.map +1 -1
- package/lib/types/request/AuthorizationUrlRequest.d.ts +6 -24
- package/lib/types/request/AuthorizationUrlRequest.d.ts.map +1 -1
- package/lib/types/request/ClientCredentialRequest.d.ts +3 -6
- package/lib/types/request/ClientCredentialRequest.d.ts.map +1 -1
- package/lib/types/request/CommonClientCredentialRequest.d.ts +10 -7
- package/lib/types/request/CommonClientCredentialRequest.d.ts.map +1 -1
- package/lib/types/request/CommonDeviceCodeRequest.d.ts +13 -10
- package/lib/types/request/CommonDeviceCodeRequest.d.ts.map +1 -1
- package/lib/types/request/CommonOnBehalfOfRequest.d.ts +8 -7
- package/lib/types/request/CommonOnBehalfOfRequest.d.ts.map +1 -1
- package/lib/types/request/CommonUsernamePasswordRequest.d.ts +6 -8
- package/lib/types/request/CommonUsernamePasswordRequest.d.ts.map +1 -1
- package/lib/types/request/DeviceCodeRequest.d.ts +6 -6
- package/lib/types/request/DeviceCodeRequest.d.ts.map +1 -1
- package/lib/types/request/InteractiveRequest.d.ts +19 -8
- package/lib/types/request/InteractiveRequest.d.ts.map +1 -1
- package/lib/types/request/ManagedIdentityRequest.d.ts +6 -2
- package/lib/types/request/ManagedIdentityRequest.d.ts.map +1 -1
- package/lib/types/request/ManagedIdentityRequestParams.d.ts +9 -3
- package/lib/types/request/ManagedIdentityRequestParams.d.ts.map +1 -1
- package/lib/types/request/OnBehalfOfRequest.d.ts +7 -6
- package/lib/types/request/OnBehalfOfRequest.d.ts.map +1 -1
- package/lib/types/request/RefreshTokenRequest.d.ts +9 -7
- package/lib/types/request/RefreshTokenRequest.d.ts.map +1 -1
- package/lib/types/request/SilentFlowRequest.d.ts +6 -7
- package/lib/types/request/SilentFlowRequest.d.ts.map +1 -1
- package/lib/types/request/UsernamePasswordRequest.d.ts +9 -8
- package/lib/types/request/UsernamePasswordRequest.d.ts.map +1 -1
- package/lib/types/utils/Constants.d.ts +2 -9
- package/lib/types/utils/Constants.d.ts.map +1 -1
- package/package.json +88 -88
- package/src/client/BaseClient.ts +158 -0
- package/src/client/ClientCredentialClient.ts +2 -3
- package/src/client/DeviceCodeClient.ts +4 -5
- package/src/client/ManagedIdentitySources/AppService.ts +54 -0
- package/src/client/ManagedIdentitySources/AzureArc.ts +81 -0
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +92 -2
- package/src/client/ManagedIdentitySources/CloudShell.ts +54 -0
- package/src/client/ManagedIdentitySources/Imds.ts +43 -21
- package/src/client/ManagedIdentitySources/MachineLearning.ts +65 -0
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +56 -22
- package/src/client/OnBehalfOfClient.ts +2 -3
- package/src/client/PublicClientApplication.ts +22 -4
- package/src/client/UsernamePasswordClient.ts +2 -3
- package/src/config/Configuration.ts +2 -14
- package/src/config/ManagedIdentityRequestParameters.ts +2 -2
- package/src/error/NodeAuthError.ts +14 -0
- package/src/index.ts +0 -8
- package/src/network/HttpClient.ts +166 -372
- package/src/packageMetadata.ts +1 -1
- package/src/protocol/Authorize.ts +1 -1
- package/src/request/AuthorizationCodeRequest.ts +12 -10
- package/src/request/AuthorizationUrlRequest.ts +6 -24
- package/src/request/ClientCredentialRequest.ts +3 -6
- package/src/request/CommonClientCredentialRequest.ts +13 -7
- package/src/request/CommonDeviceCodeRequest.ts +13 -14
- package/src/request/CommonOnBehalfOfRequest.ts +11 -7
- package/src/request/CommonUsernamePasswordRequest.ts +6 -8
- package/src/request/DeviceCodeRequest.ts +6 -6
- package/src/request/InteractiveRequest.ts +19 -11
- package/src/request/ManagedIdentityRequest.ts +6 -2
- package/src/request/ManagedIdentityRequestParams.ts +9 -3
- package/src/request/OnBehalfOfRequest.ts +7 -6
- package/src/request/RefreshTokenRequest.ts +9 -7
- package/src/request/SilentFlowRequest.ts +6 -7
- package/src/request/UsernamePasswordRequest.ts +9 -8
- package/src/utils/Constants.ts +2 -11
- package/dist/utils/NetworkUtils.mjs +0 -43
- package/dist/utils/NetworkUtils.mjs.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ClientConfiguration,
|
|
8
|
+
buildClientConfiguration,
|
|
9
|
+
CommonClientConfiguration,
|
|
10
|
+
INetworkModule,
|
|
11
|
+
NetworkRequestOptions,
|
|
12
|
+
Logger,
|
|
13
|
+
ICrypto,
|
|
14
|
+
CacheManager,
|
|
15
|
+
ServerTelemetryManager,
|
|
16
|
+
Authority,
|
|
17
|
+
CcsCredential,
|
|
18
|
+
TokenProtocol,
|
|
19
|
+
RequestThumbprint,
|
|
20
|
+
ServerAuthorizationTokenResponse,
|
|
21
|
+
NetworkResponse,
|
|
22
|
+
BaseAuthRequest,
|
|
23
|
+
StubPerformanceClient,
|
|
24
|
+
} from "@azure/msal-common/node";
|
|
25
|
+
import { version, name } from "../packageMetadata.js";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export abstract class BaseClient {
|
|
32
|
+
// Logger object
|
|
33
|
+
public logger: Logger;
|
|
34
|
+
|
|
35
|
+
// Application config
|
|
36
|
+
protected config: CommonClientConfiguration;
|
|
37
|
+
|
|
38
|
+
// Crypto Interface
|
|
39
|
+
protected cryptoUtils: ICrypto;
|
|
40
|
+
|
|
41
|
+
// Storage Interface
|
|
42
|
+
protected cacheManager: CacheManager;
|
|
43
|
+
|
|
44
|
+
// Network Interface
|
|
45
|
+
protected networkClient: INetworkModule;
|
|
46
|
+
|
|
47
|
+
// Server Telemetry Manager
|
|
48
|
+
protected serverTelemetryManager: ServerTelemetryManager | null;
|
|
49
|
+
|
|
50
|
+
// Default authority object
|
|
51
|
+
public authority: Authority;
|
|
52
|
+
|
|
53
|
+
protected performanceClient: StubPerformanceClient;
|
|
54
|
+
|
|
55
|
+
protected constructor(configuration: ClientConfiguration) {
|
|
56
|
+
// Set the configuration
|
|
57
|
+
this.config = buildClientConfiguration(configuration);
|
|
58
|
+
|
|
59
|
+
// Initialize the logger
|
|
60
|
+
this.logger = new Logger(this.config.loggerOptions, name, version);
|
|
61
|
+
|
|
62
|
+
// Initialize crypto
|
|
63
|
+
this.cryptoUtils = this.config.cryptoInterface;
|
|
64
|
+
|
|
65
|
+
// Initialize storage interface
|
|
66
|
+
this.cacheManager = this.config.storageInterface;
|
|
67
|
+
|
|
68
|
+
// Set the network interface
|
|
69
|
+
this.networkClient = this.config.networkInterface;
|
|
70
|
+
|
|
71
|
+
// Set TelemetryManager
|
|
72
|
+
this.serverTelemetryManager = this.config.serverTelemetryManager;
|
|
73
|
+
|
|
74
|
+
// set Authority
|
|
75
|
+
this.authority = this.config.authOptions.authority;
|
|
76
|
+
|
|
77
|
+
this.performanceClient = new StubPerformanceClient();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Creates default headers for requests to token endpoint
|
|
82
|
+
*/
|
|
83
|
+
protected createTokenRequestHeaders(
|
|
84
|
+
ccsCred?: CcsCredential
|
|
85
|
+
): Record<string, string> {
|
|
86
|
+
return TokenProtocol.createTokenRequestHeaders(
|
|
87
|
+
this.logger,
|
|
88
|
+
false,
|
|
89
|
+
ccsCred
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Http post to token endpoint
|
|
95
|
+
* @param tokenEndpoint
|
|
96
|
+
* @param queryString
|
|
97
|
+
* @param headers
|
|
98
|
+
* @param thumbprint
|
|
99
|
+
*/
|
|
100
|
+
protected async executePostToTokenEndpoint(
|
|
101
|
+
tokenEndpoint: string,
|
|
102
|
+
queryString: string,
|
|
103
|
+
headers: Record<string, string>,
|
|
104
|
+
thumbprint: RequestThumbprint,
|
|
105
|
+
correlationId: string
|
|
106
|
+
): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {
|
|
107
|
+
return TokenProtocol.executePostToTokenEndpoint(
|
|
108
|
+
tokenEndpoint,
|
|
109
|
+
queryString,
|
|
110
|
+
headers,
|
|
111
|
+
thumbprint,
|
|
112
|
+
correlationId,
|
|
113
|
+
this.cacheManager,
|
|
114
|
+
this.networkClient,
|
|
115
|
+
this.logger,
|
|
116
|
+
this.performanceClient,
|
|
117
|
+
this.serverTelemetryManager
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Wraps sendPostRequestAsync with necessary preflight and postflight logic
|
|
123
|
+
* @param thumbprint - Request thumbprint for throttling
|
|
124
|
+
* @param tokenEndpoint - Endpoint to make the POST to
|
|
125
|
+
* @param options - Body and Headers to include on the POST request
|
|
126
|
+
* @param correlationId - CorrelationId for telemetry
|
|
127
|
+
*/
|
|
128
|
+
async sendPostRequest<T extends ServerAuthorizationTokenResponse>(
|
|
129
|
+
thumbprint: RequestThumbprint,
|
|
130
|
+
tokenEndpoint: string,
|
|
131
|
+
options: NetworkRequestOptions,
|
|
132
|
+
correlationId: string
|
|
133
|
+
): Promise<NetworkResponse<T>> {
|
|
134
|
+
return TokenProtocol.sendPostRequest<T>(
|
|
135
|
+
thumbprint,
|
|
136
|
+
tokenEndpoint,
|
|
137
|
+
options,
|
|
138
|
+
correlationId,
|
|
139
|
+
this.cacheManager,
|
|
140
|
+
this.networkClient,
|
|
141
|
+
this.logger,
|
|
142
|
+
this.performanceClient
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Creates query string for the /token request
|
|
148
|
+
* @param request
|
|
149
|
+
*/
|
|
150
|
+
createTokenQueryParameters(request: BaseAuthRequest): string {
|
|
151
|
+
return TokenProtocol.createTokenQueryParameters(
|
|
152
|
+
request,
|
|
153
|
+
this.config.authOptions.clientId,
|
|
154
|
+
this.config.authOptions.redirectUri,
|
|
155
|
+
this.performanceClient
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
AccessTokenEntity,
|
|
8
8
|
AuthenticationResult,
|
|
9
9
|
Authority,
|
|
10
|
-
BaseClient,
|
|
11
10
|
CacheManager,
|
|
12
11
|
ClientAuthErrorCodes,
|
|
13
12
|
ClientConfiguration,
|
|
@@ -29,13 +28,13 @@ import {
|
|
|
29
28
|
ClientAssertion,
|
|
30
29
|
getClientAssertion,
|
|
31
30
|
UrlUtils,
|
|
32
|
-
StubPerformanceClient,
|
|
33
31
|
} from "@azure/msal-common/node";
|
|
34
32
|
import {
|
|
35
33
|
ManagedIdentityConfiguration,
|
|
36
34
|
ManagedIdentityNodeConfiguration,
|
|
37
35
|
} from "../config/Configuration.js";
|
|
38
36
|
import { CommonClientCredentialRequest } from "../request/CommonClientCredentialRequest.js";
|
|
37
|
+
import { BaseClient } from "./BaseClient.js";
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* OAuth2.0 client credential grant
|
|
@@ -48,7 +47,7 @@ export class ClientCredentialClient extends BaseClient {
|
|
|
48
47
|
configuration: ClientConfiguration,
|
|
49
48
|
appTokenProvider?: IAppTokenProvider
|
|
50
49
|
) {
|
|
51
|
-
super(configuration
|
|
50
|
+
super(configuration);
|
|
52
51
|
this.appTokenProvider = appTokenProvider;
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import {
|
|
7
7
|
AuthErrorCodes,
|
|
8
8
|
AuthenticationResult,
|
|
9
|
-
BaseClient,
|
|
10
9
|
ClientConfiguration,
|
|
11
10
|
DeviceCodeResponse,
|
|
12
11
|
RequestParameterBuilder,
|
|
@@ -21,10 +20,10 @@ import {
|
|
|
21
20
|
createAuthError,
|
|
22
21
|
createClientAuthError,
|
|
23
22
|
Constants,
|
|
24
|
-
StubPerformanceClient,
|
|
25
23
|
} from "@azure/msal-common/node";
|
|
26
24
|
import { CommonDeviceCodeRequest } from "../request/CommonDeviceCodeRequest.js";
|
|
27
25
|
import * as NodeClientAuthErrorCodes from "../error/ClientAuthErrorCodes.js";
|
|
26
|
+
import { BaseClient } from "./BaseClient.js";
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* OAuth2.0 Device code client
|
|
@@ -32,7 +31,7 @@ import * as NodeClientAuthErrorCodes from "../error/ClientAuthErrorCodes.js";
|
|
|
32
31
|
*/
|
|
33
32
|
export class DeviceCodeClient extends BaseClient {
|
|
34
33
|
constructor(configuration: ClientConfiguration) {
|
|
35
|
-
super(configuration
|
|
34
|
+
super(configuration);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
/**
|
|
@@ -116,7 +115,7 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
116
115
|
const parameters = new Map<string, string>();
|
|
117
116
|
|
|
118
117
|
if (request.extraQueryParameters) {
|
|
119
|
-
RequestParameterBuilder.
|
|
118
|
+
RequestParameterBuilder.addExtraParameters(
|
|
120
119
|
parameters,
|
|
121
120
|
request.extraQueryParameters
|
|
122
121
|
);
|
|
@@ -183,7 +182,7 @@ export class DeviceCodeClient extends BaseClient {
|
|
|
183
182
|
);
|
|
184
183
|
|
|
185
184
|
if (request.extraQueryParameters) {
|
|
186
|
-
RequestParameterBuilder.
|
|
185
|
+
RequestParameterBuilder.addExtraParameters(
|
|
187
186
|
parameters,
|
|
188
187
|
request.extraQueryParameters
|
|
189
188
|
);
|
|
@@ -22,12 +22,29 @@ import { NodeStorage } from "../../cache/NodeStorage.js";
|
|
|
22
22
|
const APP_SERVICE_MSI_API_VERSION: string = "2019-08-01";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
+
* Azure App Service Managed Identity Source implementation.
|
|
26
|
+
*
|
|
27
|
+
* This class provides managed identity authentication for applications running in Azure App Service.
|
|
28
|
+
* It uses the local metadata service endpoint available within App Service environments to obtain
|
|
29
|
+
* access tokens without requiring explicit credentials.
|
|
30
|
+
*
|
|
25
31
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AppServiceManagedIdentitySource.cs
|
|
26
32
|
*/
|
|
27
33
|
export class AppService extends BaseManagedIdentitySource {
|
|
28
34
|
private identityEndpoint: string;
|
|
29
35
|
private identityHeader: string;
|
|
30
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new instance of the AppService managed identity source.
|
|
39
|
+
*
|
|
40
|
+
* @param logger - Logger instance for diagnostic output
|
|
41
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
42
|
+
* @param networkClient - Network client for making HTTP requests
|
|
43
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
44
|
+
* @param disableInternalRetries - Whether to disable internal retry logic
|
|
45
|
+
* @param identityEndpoint - The App Service identity endpoint URL
|
|
46
|
+
* @param identityHeader - The secret header value required for authentication
|
|
47
|
+
*/
|
|
31
48
|
constructor(
|
|
32
49
|
logger: Logger,
|
|
33
50
|
nodeStorage: NodeStorage,
|
|
@@ -49,6 +66,16 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
49
66
|
this.identityHeader = identityHeader;
|
|
50
67
|
}
|
|
51
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves the required environment variables for App Service managed identity.
|
|
71
|
+
*
|
|
72
|
+
* App Service managed identity requires two environment variables:
|
|
73
|
+
* - IDENTITY_ENDPOINT: The URL of the local metadata service
|
|
74
|
+
* - IDENTITY_HEADER: A secret header value for authentication
|
|
75
|
+
*
|
|
76
|
+
* @returns An array containing [identityEndpoint, identityHeader] values from environment variables.
|
|
77
|
+
* Either value may be undefined if the environment variable is not set.
|
|
78
|
+
*/
|
|
52
79
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
53
80
|
const identityEndpoint: string | undefined =
|
|
54
81
|
process.env[
|
|
@@ -62,6 +89,21 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
62
89
|
return [identityEndpoint, identityHeader];
|
|
63
90
|
}
|
|
64
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Attempts to create an AppService managed identity source if the environment supports it.
|
|
94
|
+
*
|
|
95
|
+
* This method checks for the presence of required environment variables and validates
|
|
96
|
+
* the identity endpoint URL. If the environment is not suitable for App Service managed
|
|
97
|
+
* identity (missing environment variables or invalid endpoint), it returns null.
|
|
98
|
+
*
|
|
99
|
+
* @param logger - Logger instance for diagnostic output
|
|
100
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
101
|
+
* @param networkClient - Network client for making HTTP requests
|
|
102
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
103
|
+
* @param disableInternalRetries - Whether to disable internal retry logic
|
|
104
|
+
*
|
|
105
|
+
* @returns A new AppService instance if the environment is suitable, null otherwise
|
|
106
|
+
*/
|
|
65
107
|
public static tryCreate(
|
|
66
108
|
logger: Logger,
|
|
67
109
|
nodeStorage: NodeStorage,
|
|
@@ -105,6 +147,18 @@ export class AppService extends BaseManagedIdentitySource {
|
|
|
105
147
|
);
|
|
106
148
|
}
|
|
107
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Creates a managed identity token request for the App Service environment.
|
|
152
|
+
*
|
|
153
|
+
* This method constructs an HTTP GET request to the App Service identity endpoint
|
|
154
|
+
* with the required headers, query parameters, and managed identity configuration.
|
|
155
|
+
* The request includes the secret header for authentication and appropriate API version.
|
|
156
|
+
*
|
|
157
|
+
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
|
158
|
+
* @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
|
|
159
|
+
*
|
|
160
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
161
|
+
*/
|
|
108
162
|
public createRequest(
|
|
109
163
|
resource: string,
|
|
110
164
|
managedIdentityId: ManagedIdentityId
|
|
@@ -62,11 +62,27 @@ export const AZURE_ARC_FILE_DETECTION: FilePathMap = {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
+
* Azure Arc managed identity source implementation for acquiring tokens from Azure Arc-enabled servers.
|
|
66
|
+
*
|
|
67
|
+
* This class provides managed identity authentication for applications running on Azure Arc-enabled servers
|
|
68
|
+
* by communicating with the local Hybrid Instance Metadata Service (HIMDS). It supports both environment
|
|
69
|
+
* variable-based configuration and automatic detection through the HIMDS executable.
|
|
70
|
+
*
|
|
65
71
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
|
|
66
72
|
*/
|
|
67
73
|
export class AzureArc extends BaseManagedIdentitySource {
|
|
68
74
|
private identityEndpoint: string;
|
|
69
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new instance of the AzureArc managed identity source.
|
|
78
|
+
*
|
|
79
|
+
* @param logger - Logger instance for capturing telemetry and diagnostic information
|
|
80
|
+
* @param nodeStorage - Storage implementation for caching tokens and metadata
|
|
81
|
+
* @param networkClient - Network client for making HTTP requests to the identity endpoint
|
|
82
|
+
* @param cryptoProvider - Cryptographic operations provider for token validation and encryption
|
|
83
|
+
* @param disableInternalRetries - Flag to disable automatic retry logic for failed requests
|
|
84
|
+
* @param identityEndpoint - The Azure Arc identity endpoint URL for token requests
|
|
85
|
+
*/
|
|
70
86
|
constructor(
|
|
71
87
|
logger: Logger,
|
|
72
88
|
nodeStorage: NodeStorage,
|
|
@@ -86,6 +102,17 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
86
102
|
this.identityEndpoint = identityEndpoint;
|
|
87
103
|
}
|
|
88
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves and validates Azure Arc environment variables for managed identity configuration.
|
|
107
|
+
*
|
|
108
|
+
* This method checks for IDENTITY_ENDPOINT and IMDS_ENDPOINT environment variables.
|
|
109
|
+
* If either is missing, it attempts to detect the Azure Arc environment by checking for
|
|
110
|
+
* the HIMDS executable at platform-specific paths. On successful detection, it returns
|
|
111
|
+
* the default identity endpoint and a helper string indicating file-based detection.
|
|
112
|
+
*
|
|
113
|
+
* @returns An array containing [identityEndpoint, imdsEndpoint] where both values are
|
|
114
|
+
* strings if Azure Arc is available, or undefined if not available.
|
|
115
|
+
*/
|
|
89
116
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
90
117
|
let identityEndpoint: string | undefined =
|
|
91
118
|
process.env[
|
|
@@ -122,6 +149,25 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
122
149
|
return [identityEndpoint, imdsEndpoint];
|
|
123
150
|
}
|
|
124
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Attempts to create an AzureArc managed identity source instance.
|
|
154
|
+
*
|
|
155
|
+
* Validates the Azure Arc environment by checking environment variables
|
|
156
|
+
* and performing file-based detection. It ensures that only system-assigned managed identities
|
|
157
|
+
* are supported for Azure Arc scenarios. The method performs comprehensive validation of
|
|
158
|
+
* endpoint URLs and logs detailed information about the detection process.
|
|
159
|
+
*
|
|
160
|
+
* @param logger - Logger instance for capturing creation and validation steps
|
|
161
|
+
* @param nodeStorage - Storage implementation for the managed identity source
|
|
162
|
+
* @param networkClient - Network client for HTTP communication
|
|
163
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
164
|
+
* @param disableInternalRetries - Whether to disable automatic retry mechanisms
|
|
165
|
+
* @param managedIdentityId - The managed identity configuration, must be system-assigned
|
|
166
|
+
*
|
|
167
|
+
* @returns AzureArc instance if the environment supports Azure Arc managed identity, null otherwise
|
|
168
|
+
*
|
|
169
|
+
* @throws {ManagedIdentityError} When a user-assigned managed identity is specified (not supported for Azure Arc)
|
|
170
|
+
*/
|
|
125
171
|
public static tryCreate(
|
|
126
172
|
logger: Logger,
|
|
127
173
|
nodeStorage: NodeStorage,
|
|
@@ -195,6 +241,17 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
195
241
|
);
|
|
196
242
|
}
|
|
197
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Creates a properly formatted HTTP request for acquiring tokens from the Azure Arc identity endpoint.
|
|
246
|
+
*
|
|
247
|
+
* This method constructs a GET request to the Azure Arc HIMDS endpoint with the required metadata header
|
|
248
|
+
* and query parameters. The endpoint URL is normalized to use 127.0.0.1 instead of localhost for
|
|
249
|
+
* consistency. Additional body parameters are calculated by the base class during token acquisition.
|
|
250
|
+
*
|
|
251
|
+
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
|
252
|
+
*
|
|
253
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
254
|
+
*/
|
|
198
255
|
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
199
256
|
const request: ManagedIdentityRequestParameters =
|
|
200
257
|
new ManagedIdentityRequestParameters(
|
|
@@ -214,6 +271,30 @@ export class AzureArc extends BaseManagedIdentitySource {
|
|
|
214
271
|
return request;
|
|
215
272
|
}
|
|
216
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Processes the server response and handles Azure Arc-specific authentication challenges.
|
|
276
|
+
*
|
|
277
|
+
* This method implements the Azure Arc authentication flow which may require reading a secret file
|
|
278
|
+
* for authorization. When the initial request returns HTTP 401 Unauthorized, it extracts the file
|
|
279
|
+
* path from the WWW-Authenticate header, validates the file location and size, reads the secret,
|
|
280
|
+
* and retries the request with Basic authentication. The method includes comprehensive security
|
|
281
|
+
* validations to prevent path traversal and ensure file integrity.
|
|
282
|
+
*
|
|
283
|
+
* @param originalResponse - The initial HTTP response from the identity endpoint
|
|
284
|
+
* @param networkClient - Network client for making the retry request if needed
|
|
285
|
+
* @param networkRequest - The original request parameters (modified with auth header for retry)
|
|
286
|
+
* @param networkRequestOptions - Additional options for network requests
|
|
287
|
+
*
|
|
288
|
+
* @returns A promise that resolves to the server token response with access token and metadata
|
|
289
|
+
*
|
|
290
|
+
* @throws {ManagedIdentityError} When:
|
|
291
|
+
* - WWW-Authenticate header is missing or has unsupported format
|
|
292
|
+
* - Platform is not supported (not Windows or Linux)
|
|
293
|
+
* - Secret file has invalid extension (not .key)
|
|
294
|
+
* - Secret file path doesn't match expected platform path
|
|
295
|
+
* - Secret file cannot be read or is too large (>4096 bytes)
|
|
296
|
+
* @throws {ClientAuthError} When network errors occur during retry request
|
|
297
|
+
*/
|
|
217
298
|
public async getServerTokenResponseAsync(
|
|
218
299
|
originalResponse: NetworkResponse<ManagedIdentityTokenResponse>,
|
|
219
300
|
networkClient: INetworkModule,
|
|
@@ -51,6 +51,14 @@ export const ManagedIdentityUserAssignedIdQueryParameterNames = {
|
|
|
51
51
|
export type ManagedIdentityUserAssignedIdQueryParameterNames =
|
|
52
52
|
(typeof ManagedIdentityUserAssignedIdQueryParameterNames)[keyof typeof ManagedIdentityUserAssignedIdQueryParameterNames];
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Base class for all Managed Identity sources. Provides common functionality for
|
|
56
|
+
* authenticating with Azure Managed Identity endpoints across different Azure services
|
|
57
|
+
* including IMDS, App Service, Azure Arc, Service Fabric, Cloud Shell, and Machine Learning.
|
|
58
|
+
*
|
|
59
|
+
* This abstract class handles token acquisition, response processing, and network communication
|
|
60
|
+
* while allowing concrete implementations to define source-specific request creation logic.
|
|
61
|
+
*/
|
|
54
62
|
export abstract class BaseManagedIdentitySource {
|
|
55
63
|
protected logger: Logger;
|
|
56
64
|
private nodeStorage: NodeStorage;
|
|
@@ -58,6 +66,15 @@ export abstract class BaseManagedIdentitySource {
|
|
|
58
66
|
private cryptoProvider: CryptoProvider;
|
|
59
67
|
private disableInternalRetries: boolean;
|
|
60
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance of BaseManagedIdentitySource.
|
|
71
|
+
*
|
|
72
|
+
* @param logger - Logger instance for diagnostic information
|
|
73
|
+
* @param nodeStorage - Storage interface for caching tokens
|
|
74
|
+
* @param networkClient - Network client for making HTTP requests
|
|
75
|
+
* @param cryptoProvider - Cryptographic provider for token operations
|
|
76
|
+
* @param disableInternalRetries - Whether to disable automatic retry logic
|
|
77
|
+
*/
|
|
61
78
|
constructor(
|
|
62
79
|
logger: Logger,
|
|
63
80
|
nodeStorage: NodeStorage,
|
|
@@ -72,11 +89,33 @@ export abstract class BaseManagedIdentitySource {
|
|
|
72
89
|
this.disableInternalRetries = disableInternalRetries;
|
|
73
90
|
}
|
|
74
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Creates a managed identity request with source-specific parameters.
|
|
94
|
+
* This method must be implemented by concrete managed identity sources to define
|
|
95
|
+
* how requests are constructed for their specific endpoint requirements.
|
|
96
|
+
*
|
|
97
|
+
* @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
|
|
98
|
+
* @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
|
|
99
|
+
*
|
|
100
|
+
* @returns Request parameters configured for the specific managed identity source
|
|
101
|
+
*/
|
|
75
102
|
abstract createRequest(
|
|
76
|
-
|
|
103
|
+
resource: string,
|
|
77
104
|
managedIdentityId: ManagedIdentityId
|
|
78
105
|
): ManagedIdentityRequestParameters;
|
|
79
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Processes the network response and converts it to a standardized server token response.
|
|
109
|
+
* This async version allows for source-specific response processing logic while maintaining
|
|
110
|
+
* backward compatibility with the synchronous version.
|
|
111
|
+
*
|
|
112
|
+
* @param response - The network response containing the managed identity token
|
|
113
|
+
* @param _networkClient - Network client used for the request (unused in base implementation)
|
|
114
|
+
* @param _networkRequest - The original network request parameters (unused in base implementation)
|
|
115
|
+
* @param _networkRequestOptions - The network request options (unused in base implementation)
|
|
116
|
+
*
|
|
117
|
+
* @returns Promise resolving to a standardized server authorization token response
|
|
118
|
+
*/
|
|
80
119
|
public async getServerTokenResponseAsync(
|
|
81
120
|
response: NetworkResponse<ManagedIdentityTokenResponse>,
|
|
82
121
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -89,6 +128,15 @@ export abstract class BaseManagedIdentitySource {
|
|
|
89
128
|
return this.getServerTokenResponse(response);
|
|
90
129
|
}
|
|
91
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Converts a managed identity token response to a standardized server authorization token response.
|
|
133
|
+
* Handles time format conversion, expiration calculation, and error mapping to ensure
|
|
134
|
+
* compatibility with the MSAL response handling pipeline.
|
|
135
|
+
*
|
|
136
|
+
* @param response - The network response containing the managed identity token
|
|
137
|
+
*
|
|
138
|
+
* @returns Standardized server authorization token response with normalized fields
|
|
139
|
+
*/
|
|
92
140
|
public getServerTokenResponse(
|
|
93
141
|
response: NetworkResponse<ManagedIdentityTokenResponse>
|
|
94
142
|
): ServerAuthorizationTokenResponse {
|
|
@@ -138,6 +186,21 @@ export abstract class BaseManagedIdentitySource {
|
|
|
138
186
|
return serverTokenResponse;
|
|
139
187
|
}
|
|
140
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Acquires an access token using the managed identity endpoint for the specified resource.
|
|
191
|
+
* This is the primary method for token acquisition, handling the complete flow from
|
|
192
|
+
* request creation through response processing and token caching.
|
|
193
|
+
*
|
|
194
|
+
* @param managedIdentityRequest - The managed identity request containing resource and optional parameters
|
|
195
|
+
* @param managedIdentityId - The managed identity configuration (system or user-assigned)
|
|
196
|
+
* @param fakeAuthority - Authority instance used for token caching (managed identity uses a placeholder authority)
|
|
197
|
+
* @param refreshAccessToken - Whether this is a token refresh operation
|
|
198
|
+
*
|
|
199
|
+
* @returns Promise resolving to an authentication result containing the access token and metadata
|
|
200
|
+
*
|
|
201
|
+
* @throws {AuthError} When network requests fail or token validation fails
|
|
202
|
+
* @throws {ClientAuthError} When network errors occur during the request
|
|
203
|
+
*/
|
|
141
204
|
public async acquireTokenWithManagedIdentity(
|
|
142
205
|
managedIdentityRequest: ManagedIdentityRequest,
|
|
143
206
|
managedIdentityId: ManagedIdentityId,
|
|
@@ -258,6 +321,19 @@ export abstract class BaseManagedIdentitySource {
|
|
|
258
321
|
);
|
|
259
322
|
}
|
|
260
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Determines the appropriate query parameter name for user-assigned managed identity
|
|
326
|
+
* based on the identity type, API version, and endpoint characteristics.
|
|
327
|
+
* Different Azure services and API versions use different parameter names for the same identity types.
|
|
328
|
+
*
|
|
329
|
+
* @param managedIdentityIdType - The type of user-assigned managed identity (client ID, object ID, or resource ID)
|
|
330
|
+
* @param isImds - Whether the request is being made to the IMDS (Instance Metadata Service) endpoint
|
|
331
|
+
* @param usesApi2017 - Whether the endpoint uses the 2017-09-01 API version (affects client ID parameter name)
|
|
332
|
+
*
|
|
333
|
+
* @returns The correct query parameter name for the specified identity type and endpoint
|
|
334
|
+
*
|
|
335
|
+
* @throws {ManagedIdentityError} When an invalid managed identity ID type is provided
|
|
336
|
+
*/
|
|
261
337
|
public getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
262
338
|
managedIdentityIdType: ManagedIdentityIdType,
|
|
263
339
|
isImds?: boolean,
|
|
@@ -298,8 +374,22 @@ export abstract class BaseManagedIdentitySource {
|
|
|
298
374
|
}
|
|
299
375
|
}
|
|
300
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Validates and normalizes an environment variable containing a URL string.
|
|
379
|
+
* This static utility method ensures that environment variables used for managed identity
|
|
380
|
+
* endpoints contain properly formatted URLs and provides informative error messages when validation fails.
|
|
381
|
+
*
|
|
382
|
+
* @param envVariableStringName - The name of the environment variable being validated (for error reporting)
|
|
383
|
+
* @param envVariable - The environment variable value containing the URL string
|
|
384
|
+
* @param sourceName - The name of the managed identity source (for error reporting)
|
|
385
|
+
* @param logger - Logger instance for diagnostic information
|
|
386
|
+
*
|
|
387
|
+
* @returns The validated and normalized URL string
|
|
388
|
+
*
|
|
389
|
+
* @throws {ManagedIdentityError} When the environment variable contains a malformed URL
|
|
390
|
+
*/
|
|
301
391
|
public static getValidatedEnvVariableUrlString = (
|
|
302
|
-
envVariableStringName:
|
|
392
|
+
envVariableStringName: keyof typeof ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes,
|
|
303
393
|
envVariable: string,
|
|
304
394
|
sourceName: string,
|
|
305
395
|
logger: Logger
|
|
@@ -23,11 +23,27 @@ import {
|
|
|
23
23
|
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
+
* Azure Cloud Shell managed identity source implementation.
|
|
27
|
+
*
|
|
28
|
+
* This class handles authentication for applications running in Azure Cloud Shell environment.
|
|
29
|
+
* Cloud Shell provides a browser-accessible shell for managing Azure resources and includes
|
|
30
|
+
* a pre-configured managed identity for authentication.
|
|
31
|
+
*
|
|
26
32
|
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/CloudShellManagedIdentitySource.cs
|
|
27
33
|
*/
|
|
28
34
|
export class CloudShell extends BaseManagedIdentitySource {
|
|
29
35
|
private msiEndpoint: string;
|
|
30
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new CloudShell managed identity source instance.
|
|
39
|
+
*
|
|
40
|
+
* @param logger - Logger instance for diagnostic logging
|
|
41
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
42
|
+
* @param networkClient - HTTP client for making requests to the managed identity endpoint
|
|
43
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
44
|
+
* @param disableInternalRetries - Whether to disable automatic retry logic for failed requests
|
|
45
|
+
* @param msiEndpoint - The MSI endpoint URL obtained from environment variables
|
|
46
|
+
*/
|
|
31
47
|
constructor(
|
|
32
48
|
logger: Logger,
|
|
33
49
|
nodeStorage: NodeStorage,
|
|
@@ -47,6 +63,14 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
47
63
|
this.msiEndpoint = msiEndpoint;
|
|
48
64
|
}
|
|
49
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the required environment variables for Cloud Shell managed identity.
|
|
68
|
+
*
|
|
69
|
+
* Cloud Shell requires the MSI_ENDPOINT environment variable to be set, which
|
|
70
|
+
* contains the URL of the managed identity service endpoint.
|
|
71
|
+
*
|
|
72
|
+
* @returns An array containing the MSI_ENDPOINT environment variable value (or undefined if not set)
|
|
73
|
+
*/
|
|
50
74
|
public static getEnvironmentVariables(): Array<string | undefined> {
|
|
51
75
|
const msiEndpoint: string | undefined =
|
|
52
76
|
process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
|
|
@@ -54,6 +78,25 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
54
78
|
return [msiEndpoint];
|
|
55
79
|
}
|
|
56
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Attempts to create a CloudShell managed identity source instance.
|
|
83
|
+
*
|
|
84
|
+
* This method validates that the required environment variables are present and
|
|
85
|
+
* creates a CloudShell instance if the environment is properly configured.
|
|
86
|
+
* Cloud Shell only supports system-assigned managed identities.
|
|
87
|
+
*
|
|
88
|
+
* @param logger - Logger instance for diagnostic logging
|
|
89
|
+
* @param nodeStorage - Node.js storage implementation for caching
|
|
90
|
+
* @param networkClient - HTTP client for making requests
|
|
91
|
+
* @param cryptoProvider - Cryptographic operations provider
|
|
92
|
+
* @param disableInternalRetries - Whether to disable automatic retry logic
|
|
93
|
+
* @param managedIdentityId - The managed identity configuration (must be system-assigned)
|
|
94
|
+
*
|
|
95
|
+
* @returns A CloudShell instance if the environment is valid, null otherwise
|
|
96
|
+
*
|
|
97
|
+
* @throws {ManagedIdentityError} When a user-assigned managed identity is requested,
|
|
98
|
+
* as Cloud Shell only supports system-assigned identities
|
|
99
|
+
*/
|
|
57
100
|
public static tryCreate(
|
|
58
101
|
logger: Logger,
|
|
59
102
|
nodeStorage: NodeStorage,
|
|
@@ -104,6 +147,17 @@ export class CloudShell extends BaseManagedIdentitySource {
|
|
|
104
147
|
);
|
|
105
148
|
}
|
|
106
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Creates an HTTP request to acquire an access token from the Cloud Shell managed identity endpoint.
|
|
152
|
+
*
|
|
153
|
+
* This method constructs a POST request to the MSI endpoint with the required headers and
|
|
154
|
+
* body parameters for Cloud Shell authentication. The request includes the target resource
|
|
155
|
+
* for which the access token is being requested.
|
|
156
|
+
*
|
|
157
|
+
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
|
158
|
+
*
|
|
159
|
+
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
|
160
|
+
*/
|
|
107
161
|
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
108
162
|
const request: ManagedIdentityRequestParameters =
|
|
109
163
|
new ManagedIdentityRequestParameters(
|