@azure/msal-node 2.6.5-alpha.0 → 2.6.6
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 +23 -27
- 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 +24 -28
- 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/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 +2 -36
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +0 -16
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +3 -36
- package/dist/config/Configuration.mjs.map +1 -1
- 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/NodeAuthError.cjs +1 -1
- package/dist/error/NodeAuthError.mjs +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/network/HttpClient.cjs +6 -13
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +1 -2
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +6 -13
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/LoopbackClient.cjs +1 -1
- package/dist/network/LoopbackClient.mjs +1 -1
- package/dist/packageMetadata.cjs +2 -2
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/utils/Constants.cjs +1 -68
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +0 -45
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +2 -54
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +1 -1
- package/dist/utils/EncodingUtils.mjs +1 -1
- package/dist/utils/NetworkUtils.cjs +1 -1
- package/dist/utils/NetworkUtils.mjs +1 -1
- package/package.json +2 -2
- package/src/client/ClientCredentialClient.ts +25 -65
- package/src/config/Configuration.ts +1 -81
- package/src/index.ts +0 -4
- package/src/network/HttpClient.ts +5 -17
- package/src/packageMetadata.ts +1 -1
- package/src/utils/Constants.ts +0 -63
- package/dist/client/ManagedIdentityApplication.cjs +0 -97
- package/dist/client/ManagedIdentityApplication.cjs.map +0 -1
- package/dist/client/ManagedIdentityApplication.d.ts +0 -24
- package/dist/client/ManagedIdentityApplication.d.ts.map +0 -1
- package/dist/client/ManagedIdentityApplication.mjs +0 -95
- package/dist/client/ManagedIdentityApplication.mjs.map +0 -1
- package/dist/client/ManagedIdentityClient.cjs +0 -53
- package/dist/client/ManagedIdentityClient.cjs.map +0 -1
- package/dist/client/ManagedIdentityClient.d.ts +0 -25
- package/dist/client/ManagedIdentityClient.d.ts.map +0 -1
- package/dist/client/ManagedIdentityClient.mjs +0 -51
- package/dist/client/ManagedIdentityClient.mjs.map +0 -1
- package/dist/client/ManagedIdentitySources/AppService.cjs +0 -52
- package/dist/client/ManagedIdentitySources/AppService.cjs.map +0 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts +0 -17
- package/dist/client/ManagedIdentitySources/AppService.d.ts.map +0 -1
- package/dist/client/ManagedIdentitySources/AppService.mjs +0 -50
- package/dist/client/ManagedIdentitySources/AppService.mjs.map +0 -1
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +0 -96
- package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +0 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +0 -19
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +0 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +0 -93
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +0 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +0 -122
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +0 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +0 -31
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +0 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +0 -119
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +0 -1
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +0 -47
- package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +0 -1
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +0 -16
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +0 -1
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +0 -45
- package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +0 -1
- package/dist/client/ManagedIdentitySources/Imds.cjs +0 -54
- package/dist/client/ManagedIdentitySources/Imds.cjs.map +0 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +0 -13
- package/dist/client/ManagedIdentitySources/Imds.d.ts.map +0 -1
- package/dist/client/ManagedIdentitySources/Imds.mjs +0 -52
- package/dist/client/ManagedIdentitySources/Imds.mjs.map +0 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +0 -61
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +0 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +0 -17
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +0 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +0 -59
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +0 -1
- package/dist/config/ManagedIdentityId.cjs +0 -59
- package/dist/config/ManagedIdentityId.cjs.map +0 -1
- package/dist/config/ManagedIdentityId.d.ts +0 -12
- package/dist/config/ManagedIdentityId.d.ts.map +0 -1
- package/dist/config/ManagedIdentityId.mjs +0 -57
- package/dist/config/ManagedIdentityId.mjs.map +0 -1
- package/dist/config/ManagedIdentityRequestParameters.cjs +0 -37
- package/dist/config/ManagedIdentityRequestParameters.cjs.map +0 -1
- package/dist/config/ManagedIdentityRequestParameters.d.ts +0 -12
- package/dist/config/ManagedIdentityRequestParameters.d.ts.map +0 -1
- package/dist/config/ManagedIdentityRequestParameters.mjs +0 -35
- package/dist/config/ManagedIdentityRequestParameters.mjs.map +0 -1
- package/dist/error/ManagedIdentityError.cjs +0 -51
- package/dist/error/ManagedIdentityError.cjs.map +0 -1
- package/dist/error/ManagedIdentityError.d.ts +0 -28
- package/dist/error/ManagedIdentityError.d.ts.map +0 -1
- package/dist/error/ManagedIdentityError.mjs +0 -47
- package/dist/error/ManagedIdentityError.mjs.map +0 -1
- package/dist/error/ManagedIdentityErrorCodes.cjs +0 -41
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +0 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts +0 -20
- package/dist/error/ManagedIdentityErrorCodes.d.ts.map +0 -1
- package/dist/error/ManagedIdentityErrorCodes.mjs +0 -28
- package/dist/error/ManagedIdentityErrorCodes.mjs.map +0 -1
- package/dist/network/HttpClientWithRetries.cjs +0 -44
- package/dist/network/HttpClientWithRetries.cjs.map +0 -1
- package/dist/network/HttpClientWithRetries.d.ts +0 -12
- package/dist/network/HttpClientWithRetries.d.ts.map +0 -1
- package/dist/network/HttpClientWithRetries.mjs +0 -42
- package/dist/network/HttpClientWithRetries.mjs.map +0 -1
- package/dist/request/ManagedIdentityRequest.d.ts +0 -9
- package/dist/request/ManagedIdentityRequest.d.ts.map +0 -1
- package/dist/request/ManagedIdentityRequestParams.d.ts +0 -10
- package/dist/request/ManagedIdentityRequestParams.d.ts.map +0 -1
- package/dist/response/ManagedIdentityTokenResponse.d.ts +0 -25
- package/dist/response/ManagedIdentityTokenResponse.d.ts.map +0 -1
- package/dist/retry/IHttpRetryPolicy.d.ts +0 -6
- package/dist/retry/IHttpRetryPolicy.d.ts.map +0 -1
- package/dist/retry/LinearRetryPolicy.cjs +0 -47
- package/dist/retry/LinearRetryPolicy.cjs.map +0 -1
- package/dist/retry/LinearRetryPolicy.d.ts +0 -12
- package/dist/retry/LinearRetryPolicy.d.ts.map +0 -1
- package/dist/retry/LinearRetryPolicy.mjs +0 -45
- package/dist/retry/LinearRetryPolicy.mjs.map +0 -1
- package/src/client/ManagedIdentityApplication.ts +0 -194
- package/src/client/ManagedIdentityClient.ts +0 -128
- package/src/client/ManagedIdentitySources/AppService.ts +0 -122
- package/src/client/ManagedIdentitySources/AzureArc.ts +0 -199
- package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +0 -237
- package/src/client/ManagedIdentitySources/CloudShell.ts +0 -104
- package/src/client/ManagedIdentitySources/Imds.ts +0 -126
- package/src/client/ManagedIdentitySources/ServiceFabric.ts +0 -140
- package/src/config/ManagedIdentityId.ts +0 -73
- package/src/config/ManagedIdentityRequestParameters.ts +0 -48
- package/src/error/ManagedIdentityError.ts +0 -59
- package/src/error/ManagedIdentityErrorCodes.ts +0 -34
- package/src/network/HttpClientWithRetries.ts +0 -80
- package/src/request/ManagedIdentityRequest.ts +0 -15
- package/src/request/ManagedIdentityRequestParams.ts +0 -14
- package/src/response/ManagedIdentityTokenResponse.ts +0 -33
- package/src/retry/IHttpRetryPolicy.ts +0 -18
- package/src/retry/LinearRetryPolicy.ts +0 -71
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
AuthError,
|
|
8
|
-
Authority,
|
|
9
|
-
ClientAuthErrorCodes,
|
|
10
|
-
Constants,
|
|
11
|
-
HeaderNames,
|
|
12
|
-
INetworkModule,
|
|
13
|
-
Logger,
|
|
14
|
-
NetworkRequestOptions,
|
|
15
|
-
NetworkResponse,
|
|
16
|
-
ResponseHandler,
|
|
17
|
-
ServerAuthorizationTokenResponse,
|
|
18
|
-
TimeUtils,
|
|
19
|
-
createClientAuthError,
|
|
20
|
-
AuthenticationResult,
|
|
21
|
-
UrlString,
|
|
22
|
-
} from "@azure/msal-common";
|
|
23
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
24
|
-
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
25
|
-
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
26
|
-
import { ManagedIdentityRequest } from "../../request/ManagedIdentityRequest";
|
|
27
|
-
import { HttpMethod, ManagedIdentityIdType } from "../../utils/Constants";
|
|
28
|
-
import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse";
|
|
29
|
-
import { NodeStorage } from "../../cache/NodeStorage";
|
|
30
|
-
import {
|
|
31
|
-
ManagedIdentityErrorCodes,
|
|
32
|
-
createManagedIdentityError,
|
|
33
|
-
} from "../../error/ManagedIdentityError";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Managed Identity User Assigned Id Query Parameter Names
|
|
37
|
-
*/
|
|
38
|
-
export const ManagedIdentityUserAssignedIdQueryParameterNames = {
|
|
39
|
-
MANAGED_IDENTITY_CLIENT_ID: "client_id",
|
|
40
|
-
MANAGED_IDENTITY_OBJECT_ID: "object_id",
|
|
41
|
-
MANAGED_IDENTITY_RESOURCE_ID: "mi_res_id",
|
|
42
|
-
} as const;
|
|
43
|
-
export type ManagedIdentityUserAssignedIdQueryParameterNames =
|
|
44
|
-
(typeof ManagedIdentityUserAssignedIdQueryParameterNames)[keyof typeof ManagedIdentityUserAssignedIdQueryParameterNames];
|
|
45
|
-
|
|
46
|
-
export abstract class BaseManagedIdentitySource {
|
|
47
|
-
protected logger: Logger;
|
|
48
|
-
private nodeStorage: NodeStorage;
|
|
49
|
-
private networkClient: INetworkModule;
|
|
50
|
-
private cryptoProvider: CryptoProvider;
|
|
51
|
-
|
|
52
|
-
constructor(
|
|
53
|
-
logger: Logger,
|
|
54
|
-
nodeStorage: NodeStorage,
|
|
55
|
-
networkClient: INetworkModule,
|
|
56
|
-
cryptoProvider: CryptoProvider
|
|
57
|
-
) {
|
|
58
|
-
this.logger = logger;
|
|
59
|
-
this.nodeStorage = nodeStorage;
|
|
60
|
-
this.networkClient = networkClient;
|
|
61
|
-
this.cryptoProvider = cryptoProvider;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
abstract createRequest(
|
|
65
|
-
request: string,
|
|
66
|
-
managedIdentityId: ManagedIdentityId
|
|
67
|
-
): ManagedIdentityRequestParameters;
|
|
68
|
-
|
|
69
|
-
public async getServerTokenResponseAsync(
|
|
70
|
-
response: NetworkResponse<ManagedIdentityTokenResponse>,
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
-
_networkClient: INetworkModule,
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
74
|
-
_networkRequest: ManagedIdentityRequestParameters,
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
76
|
-
_networkRequestOptions: NetworkRequestOptions
|
|
77
|
-
): Promise<ServerAuthorizationTokenResponse> {
|
|
78
|
-
return this.getServerTokenResponse(response);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public getServerTokenResponse(
|
|
82
|
-
response: NetworkResponse<ManagedIdentityTokenResponse>
|
|
83
|
-
): ServerAuthorizationTokenResponse {
|
|
84
|
-
const serverTokenResponse: ServerAuthorizationTokenResponse = {
|
|
85
|
-
status: response.status,
|
|
86
|
-
|
|
87
|
-
// success
|
|
88
|
-
access_token: response.body.access_token,
|
|
89
|
-
expires_in: response.body.expires_on,
|
|
90
|
-
scope: response.body.resource,
|
|
91
|
-
token_type: response.body.token_type,
|
|
92
|
-
|
|
93
|
-
// error
|
|
94
|
-
error: response.body.message,
|
|
95
|
-
correlation_id: response.body.correlationId,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// compute refresh_in as 1/2 of expires_in, but only if expires_in > 2h
|
|
99
|
-
if (
|
|
100
|
-
serverTokenResponse.expires_in &&
|
|
101
|
-
serverTokenResponse.expires_in > 2 * 3600
|
|
102
|
-
) {
|
|
103
|
-
serverTokenResponse.refresh_in = serverTokenResponse.expires_in / 2;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return serverTokenResponse;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public async acquireTokenWithManagedIdentity(
|
|
110
|
-
managedIdentityRequest: ManagedIdentityRequest,
|
|
111
|
-
managedIdentityId: ManagedIdentityId,
|
|
112
|
-
fakeAuthority: Authority,
|
|
113
|
-
refreshAccessToken?: boolean
|
|
114
|
-
): Promise<AuthenticationResult> {
|
|
115
|
-
const networkRequest: ManagedIdentityRequestParameters =
|
|
116
|
-
this.createRequest(
|
|
117
|
-
managedIdentityRequest.resource,
|
|
118
|
-
managedIdentityId
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const headers: Record<string, string> = networkRequest.headers;
|
|
122
|
-
headers[HeaderNames.CONTENT_TYPE] = Constants.URL_FORM_CONTENT_TYPE;
|
|
123
|
-
|
|
124
|
-
const networkRequestOptions: NetworkRequestOptions = { headers };
|
|
125
|
-
|
|
126
|
-
if (Object.keys(networkRequest.bodyParameters).length) {
|
|
127
|
-
networkRequestOptions.body =
|
|
128
|
-
networkRequest.computeParametersBodyString();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const reqTimestamp = TimeUtils.nowSeconds();
|
|
132
|
-
let response: NetworkResponse<ManagedIdentityTokenResponse>;
|
|
133
|
-
try {
|
|
134
|
-
// Sources that send POST requests: Cloud Shell
|
|
135
|
-
if (networkRequest.httpMethod === HttpMethod.POST) {
|
|
136
|
-
response =
|
|
137
|
-
await this.networkClient.sendPostRequestAsync<ManagedIdentityTokenResponse>(
|
|
138
|
-
networkRequest.computeUri(),
|
|
139
|
-
networkRequestOptions
|
|
140
|
-
);
|
|
141
|
-
// Sources that send GET requests: App Service, Azure Arc, IMDS, Service Fabric
|
|
142
|
-
} else {
|
|
143
|
-
response =
|
|
144
|
-
await this.networkClient.sendGetRequestAsync<ManagedIdentityTokenResponse>(
|
|
145
|
-
networkRequest.computeUri(),
|
|
146
|
-
networkRequestOptions
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
} catch (error) {
|
|
150
|
-
if (error instanceof AuthError) {
|
|
151
|
-
throw error;
|
|
152
|
-
} else {
|
|
153
|
-
throw createClientAuthError(ClientAuthErrorCodes.networkError);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const responseHandler = new ResponseHandler(
|
|
158
|
-
managedIdentityId.id,
|
|
159
|
-
this.nodeStorage,
|
|
160
|
-
this.cryptoProvider,
|
|
161
|
-
this.logger,
|
|
162
|
-
null,
|
|
163
|
-
null
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
const serverTokenResponse: ServerAuthorizationTokenResponse =
|
|
167
|
-
await this.getServerTokenResponseAsync(
|
|
168
|
-
response,
|
|
169
|
-
this.networkClient,
|
|
170
|
-
networkRequest,
|
|
171
|
-
networkRequestOptions
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
responseHandler.validateTokenResponse(
|
|
175
|
-
serverTokenResponse,
|
|
176
|
-
refreshAccessToken
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
// caches the token
|
|
180
|
-
return responseHandler.handleServerTokenResponse(
|
|
181
|
-
serverTokenResponse,
|
|
182
|
-
fakeAuthority,
|
|
183
|
-
reqTimestamp,
|
|
184
|
-
managedIdentityRequest
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
189
|
-
managedIdentityIdType: ManagedIdentityIdType
|
|
190
|
-
): string {
|
|
191
|
-
switch (managedIdentityIdType) {
|
|
192
|
-
case ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID:
|
|
193
|
-
this.logger.info(
|
|
194
|
-
"[Managed Identity] Adding user assigned client id to the request."
|
|
195
|
-
);
|
|
196
|
-
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_CLIENT_ID;
|
|
197
|
-
|
|
198
|
-
case ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID:
|
|
199
|
-
this.logger.info(
|
|
200
|
-
"[Managed Identity] Adding user assigned resource id to the request."
|
|
201
|
-
);
|
|
202
|
-
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_RESOURCE_ID;
|
|
203
|
-
|
|
204
|
-
case ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID:
|
|
205
|
-
this.logger.info(
|
|
206
|
-
"[Managed Identity] Adding user assigned object id to the request."
|
|
207
|
-
);
|
|
208
|
-
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_OBJECT_ID;
|
|
209
|
-
default:
|
|
210
|
-
throw createManagedIdentityError(
|
|
211
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
static getValidatedEnvVariableUrlString = (
|
|
217
|
-
envVariableStringName: string,
|
|
218
|
-
envVariable: string,
|
|
219
|
-
sourceName: string,
|
|
220
|
-
logger: Logger
|
|
221
|
-
): string => {
|
|
222
|
-
try {
|
|
223
|
-
return new UrlString(envVariable).urlString;
|
|
224
|
-
} catch (error) {
|
|
225
|
-
logger.info(
|
|
226
|
-
`[Managed Identity] ${sourceName} managed identity is unavailable because the '${envVariableStringName}' environment variable is malformed.`
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
throw createManagedIdentityError(
|
|
230
|
-
ManagedIdentityErrorCodes
|
|
231
|
-
.MsiEnvironmentVariableUrlMalformedErrorCodes[
|
|
232
|
-
envVariableStringName
|
|
233
|
-
]
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { INetworkModule, Logger } from "@azure/msal-common";
|
|
7
|
-
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
8
|
-
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
9
|
-
import { NodeStorage } from "../../cache/NodeStorage";
|
|
10
|
-
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
11
|
-
import {
|
|
12
|
-
HttpMethod,
|
|
13
|
-
METADATA_HEADER_NAME,
|
|
14
|
-
ManagedIdentityEnvironmentVariableNames,
|
|
15
|
-
ManagedIdentityIdType,
|
|
16
|
-
ManagedIdentitySourceNames,
|
|
17
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
18
|
-
} from "../../utils/Constants";
|
|
19
|
-
import {
|
|
20
|
-
ManagedIdentityErrorCodes,
|
|
21
|
-
createManagedIdentityError,
|
|
22
|
-
} from "../../error/ManagedIdentityError";
|
|
23
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/CloudShellManagedIdentitySource.cs
|
|
27
|
-
*/
|
|
28
|
-
export class CloudShell extends BaseManagedIdentitySource {
|
|
29
|
-
private msiEndpoint: string;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
logger: Logger,
|
|
33
|
-
nodeStorage: NodeStorage,
|
|
34
|
-
networkClient: INetworkModule,
|
|
35
|
-
cryptoProvider: CryptoProvider,
|
|
36
|
-
msiEndpoint: string
|
|
37
|
-
) {
|
|
38
|
-
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
39
|
-
|
|
40
|
-
this.msiEndpoint = msiEndpoint;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static tryCreate(
|
|
44
|
-
logger: Logger,
|
|
45
|
-
nodeStorage: NodeStorage,
|
|
46
|
-
networkClient: INetworkModule,
|
|
47
|
-
cryptoProvider: CryptoProvider,
|
|
48
|
-
managedIdentityId: ManagedIdentityId
|
|
49
|
-
): CloudShell | null {
|
|
50
|
-
const msiEndpoint: string | undefined =
|
|
51
|
-
process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
|
|
52
|
-
|
|
53
|
-
// if the msi endpoint environment variable is undefined, this MSI provider is unavailable.
|
|
54
|
-
if (!msiEndpoint) {
|
|
55
|
-
logger.info(
|
|
56
|
-
`[Managed Identity] ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity is unavailable because the '${ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT} environment variable is not defined.`
|
|
57
|
-
);
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const validatedMsiEndpoint: string =
|
|
62
|
-
CloudShell.getValidatedEnvVariableUrlString(
|
|
63
|
-
ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT,
|
|
64
|
-
msiEndpoint,
|
|
65
|
-
ManagedIdentitySourceNames.CLOUD_SHELL,
|
|
66
|
-
logger
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
logger.info(
|
|
70
|
-
`[Managed Identity] Environment variable validation passed for ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity. Endpoint URI: ${validatedMsiEndpoint}. Creating ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity.`
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
75
|
-
) {
|
|
76
|
-
throw createManagedIdentityError(
|
|
77
|
-
ManagedIdentityErrorCodes.unableToCreateCloudShell
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return new CloudShell(
|
|
82
|
-
logger,
|
|
83
|
-
nodeStorage,
|
|
84
|
-
networkClient,
|
|
85
|
-
cryptoProvider,
|
|
86
|
-
msiEndpoint
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
91
|
-
const request: ManagedIdentityRequestParameters =
|
|
92
|
-
new ManagedIdentityRequestParameters(
|
|
93
|
-
HttpMethod.POST,
|
|
94
|
-
this.msiEndpoint
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
request.headers[METADATA_HEADER_NAME] = "true";
|
|
98
|
-
|
|
99
|
-
request.bodyParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
100
|
-
resource;
|
|
101
|
-
|
|
102
|
-
return request;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { INetworkModule, Logger } from "@azure/msal-common";
|
|
7
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
8
|
-
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
9
|
-
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
10
|
-
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
11
|
-
import {
|
|
12
|
-
API_VERSION_QUERY_PARAMETER_NAME,
|
|
13
|
-
HttpMethod,
|
|
14
|
-
METADATA_HEADER_NAME,
|
|
15
|
-
ManagedIdentityEnvironmentVariableNames,
|
|
16
|
-
ManagedIdentityIdType,
|
|
17
|
-
ManagedIdentitySourceNames,
|
|
18
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
19
|
-
} from "../../utils/Constants";
|
|
20
|
-
import { NodeStorage } from "../../cache/NodeStorage";
|
|
21
|
-
|
|
22
|
-
// IMDS constants. Docs for IMDS are available here https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
|
|
23
|
-
const IMDS_TOKEN_PATH: string = "/metadata/identity/oauth2/token";
|
|
24
|
-
const DEFAULT_IMDS_ENDPOINT: string = `http://169.254.169.254${IMDS_TOKEN_PATH}`;
|
|
25
|
-
|
|
26
|
-
const IMDS_API_VERSION: string = "2018-02-01";
|
|
27
|
-
|
|
28
|
-
// Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
|
|
29
|
-
export class Imds extends BaseManagedIdentitySource {
|
|
30
|
-
private identityEndpoint: string;
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
logger: Logger,
|
|
34
|
-
nodeStorage: NodeStorage,
|
|
35
|
-
networkClient: INetworkModule,
|
|
36
|
-
cryptoProvider: CryptoProvider,
|
|
37
|
-
identityEndpoint: string
|
|
38
|
-
) {
|
|
39
|
-
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
40
|
-
|
|
41
|
-
this.identityEndpoint = identityEndpoint;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static tryCreate(
|
|
45
|
-
logger: Logger,
|
|
46
|
-
nodeStorage: NodeStorage,
|
|
47
|
-
networkClient: INetworkModule,
|
|
48
|
-
cryptoProvider: CryptoProvider
|
|
49
|
-
): Imds {
|
|
50
|
-
let validatedIdentityEndpoint: string;
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
process.env[
|
|
54
|
-
ManagedIdentityEnvironmentVariableNames
|
|
55
|
-
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
56
|
-
]
|
|
57
|
-
) {
|
|
58
|
-
logger.info(
|
|
59
|
-
`[Managed Identity] Environment variable ${
|
|
60
|
-
ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
61
|
-
} for ${ManagedIdentitySourceNames.IMDS} returned endpoint: ${
|
|
62
|
-
process.env[
|
|
63
|
-
ManagedIdentityEnvironmentVariableNames
|
|
64
|
-
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
65
|
-
]
|
|
66
|
-
}`
|
|
67
|
-
);
|
|
68
|
-
validatedIdentityEndpoint = Imds.getValidatedEnvVariableUrlString(
|
|
69
|
-
ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST,
|
|
70
|
-
`${
|
|
71
|
-
process.env[
|
|
72
|
-
ManagedIdentityEnvironmentVariableNames
|
|
73
|
-
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
|
74
|
-
]
|
|
75
|
-
}${IMDS_TOKEN_PATH}`,
|
|
76
|
-
ManagedIdentitySourceNames.IMDS,
|
|
77
|
-
logger
|
|
78
|
-
);
|
|
79
|
-
} else {
|
|
80
|
-
logger.info(
|
|
81
|
-
`[Managed Identity] Unable to find ${ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST} environment variable for ${ManagedIdentitySourceNames.IMDS}, using the default endpoint.`
|
|
82
|
-
);
|
|
83
|
-
validatedIdentityEndpoint = DEFAULT_IMDS_ENDPOINT;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return new Imds(
|
|
87
|
-
logger,
|
|
88
|
-
nodeStorage,
|
|
89
|
-
networkClient,
|
|
90
|
-
cryptoProvider,
|
|
91
|
-
validatedIdentityEndpoint
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public createRequest(
|
|
96
|
-
resource: string,
|
|
97
|
-
managedIdentityId: ManagedIdentityId
|
|
98
|
-
): ManagedIdentityRequestParameters {
|
|
99
|
-
const request: ManagedIdentityRequestParameters =
|
|
100
|
-
new ManagedIdentityRequestParameters(
|
|
101
|
-
HttpMethod.GET,
|
|
102
|
-
this.identityEndpoint
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
request.headers[METADATA_HEADER_NAME] = "true";
|
|
106
|
-
|
|
107
|
-
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
108
|
-
IMDS_API_VERSION;
|
|
109
|
-
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
110
|
-
resource;
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
114
|
-
) {
|
|
115
|
-
request.queryParameters[
|
|
116
|
-
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
117
|
-
managedIdentityId.idType
|
|
118
|
-
)
|
|
119
|
-
] = managedIdentityId.id;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
123
|
-
|
|
124
|
-
return request;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { INetworkModule, Logger } from "@azure/msal-common";
|
|
7
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
8
|
-
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
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";
|
|
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
|
-
*/
|
|
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
|
-
|
|
108
|
-
public createRequest(
|
|
109
|
-
resource: string,
|
|
110
|
-
managedIdentityId: ManagedIdentityId
|
|
111
|
-
): ManagedIdentityRequestParameters {
|
|
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;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
ManagedIdentityErrorCodes,
|
|
8
|
-
createManagedIdentityError,
|
|
9
|
-
} from "../error/ManagedIdentityError";
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_MANAGED_IDENTITY_ID,
|
|
12
|
-
ManagedIdentityIdType,
|
|
13
|
-
} from "../utils/Constants";
|
|
14
|
-
import { ManagedIdentityIdParams } from "./Configuration";
|
|
15
|
-
|
|
16
|
-
export class ManagedIdentityId {
|
|
17
|
-
private _id: string;
|
|
18
|
-
public get id(): string {
|
|
19
|
-
return this._id;
|
|
20
|
-
}
|
|
21
|
-
private set id(value: string) {
|
|
22
|
-
this._id = value;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private _idType: ManagedIdentityIdType;
|
|
26
|
-
public get idType(): ManagedIdentityIdType {
|
|
27
|
-
return this._idType;
|
|
28
|
-
}
|
|
29
|
-
private set idType(value: ManagedIdentityIdType) {
|
|
30
|
-
this._idType = value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
constructor(managedIdentityIdParams?: ManagedIdentityIdParams) {
|
|
34
|
-
const userAssignedClientId =
|
|
35
|
-
managedIdentityIdParams?.userAssignedClientId;
|
|
36
|
-
const userAssignedResourceId =
|
|
37
|
-
managedIdentityIdParams?.userAssignedResourceId;
|
|
38
|
-
const userAssignedObjectId =
|
|
39
|
-
managedIdentityIdParams?.userAssignedObjectId;
|
|
40
|
-
|
|
41
|
-
if (userAssignedClientId) {
|
|
42
|
-
if (userAssignedResourceId || userAssignedObjectId) {
|
|
43
|
-
throw createManagedIdentityError(
|
|
44
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.id = userAssignedClientId;
|
|
49
|
-
this.idType = ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID;
|
|
50
|
-
} else if (userAssignedResourceId) {
|
|
51
|
-
if (userAssignedClientId || userAssignedObjectId) {
|
|
52
|
-
throw createManagedIdentityError(
|
|
53
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.id = userAssignedResourceId;
|
|
58
|
-
this.idType = ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID;
|
|
59
|
-
} else if (userAssignedObjectId) {
|
|
60
|
-
if (userAssignedClientId || userAssignedResourceId) {
|
|
61
|
-
throw createManagedIdentityError(
|
|
62
|
-
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.id = userAssignedObjectId;
|
|
67
|
-
this.idType = ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID;
|
|
68
|
-
} else {
|
|
69
|
-
this.id = DEFAULT_MANAGED_IDENTITY_ID;
|
|
70
|
-
this.idType = ManagedIdentityIdType.SYSTEM_ASSIGNED;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|