@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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LinearRetryPolicy.mjs","sources":["../../src/retry/LinearRetryPolicy.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;MAKU,iBAAiB,CAAA;AAK1B,IAAA,WAAA,CACI,UAAkB,EAClB,UAAkB,EAClB,wBAAuC,EAAA;AAEvC,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AAC7B,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AAC7B,QAAA,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;KAC5D;AAEO,IAAA,6BAA6B,CACjC,WAAoD,EAAA;QAEpD,IAAI,CAAC,WAAW,EAAE;AACd,YAAA,OAAO,CAAC,CAAC;AACZ,SAAA;;AAGD,QAAA,IAAI,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;AAE/D;;;AAGG;AACH,QAAA,IAAI,KAAK,CAAC,aAAa,CAAC,EAAE;AACtB,YAAA,aAAa,GAAG,IAAI,CAAC,GAAG,CACpB,CAAC;;AAED,YAAA,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CACzD,CAAC;AACL,SAAA;AAED,QAAA,OAAO,aAAa,CAAC;KACxB;AAED,IAAA,MAAM,aAAa,CACf,cAAsB,EACtB,YAAoB,EACpB,gBAAyD,EAAA;AAEzD,QAAA,IACI,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,cAAc,CAAC;AACtD,YAAA,YAAY,GAAG,IAAI,CAAC,UAAU,EAChC;YACE,MAAM,eAAe,GACjB,IAAI,CAAC,6BAA6B,CAAC,gBAAgB,CAAC,CAAC;AAEzD,YAAA,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;;gBAE1B,OAAO,UAAU,CAAC,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AACnE,aAAC,CAAC,CAAC;AAEH,YAAA,OAAO,IAAI,CAAC;AACf,SAAA;AAED,QAAA,OAAO,KAAK,CAAC;KAChB;AACJ;;;;"}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
AuthOptions,
|
|
8
|
-
Authority,
|
|
9
|
-
AuthorityOptions,
|
|
10
|
-
CacheOutcome,
|
|
11
|
-
ClientConfiguration,
|
|
12
|
-
Constants,
|
|
13
|
-
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
14
|
-
INetworkModule,
|
|
15
|
-
Logger,
|
|
16
|
-
ProtocolMode,
|
|
17
|
-
StaticAuthorityOptions,
|
|
18
|
-
AuthenticationResult,
|
|
19
|
-
UrlString,
|
|
20
|
-
} from "@azure/msal-common";
|
|
21
|
-
import {
|
|
22
|
-
ManagedIdentityConfiguration,
|
|
23
|
-
ManagedIdentityNodeConfiguration,
|
|
24
|
-
buildManagedIdentityConfiguration,
|
|
25
|
-
} from "../config/Configuration";
|
|
26
|
-
import { version, name } from "../packageMetadata.js";
|
|
27
|
-
import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest";
|
|
28
|
-
import { CryptoProvider } from "../crypto/CryptoProvider";
|
|
29
|
-
import { ClientCredentialClient } from "./ClientCredentialClient";
|
|
30
|
-
import { ManagedIdentityClient } from "./ManagedIdentityClient";
|
|
31
|
-
import { ManagedIdentityRequestParams } from "../request/ManagedIdentityRequestParams";
|
|
32
|
-
import { NodeStorage } from "../cache/NodeStorage";
|
|
33
|
-
import { DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY } from "../utils/Constants";
|
|
34
|
-
import {
|
|
35
|
-
ManagedIdentityErrorCodes,
|
|
36
|
-
createManagedIdentityError,
|
|
37
|
-
} from "../error/ManagedIdentityError";
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Class to initialize a managed identity and identify the service
|
|
41
|
-
*/
|
|
42
|
-
export class ManagedIdentityApplication {
|
|
43
|
-
private config: ManagedIdentityNodeConfiguration;
|
|
44
|
-
|
|
45
|
-
private logger: Logger;
|
|
46
|
-
private static nodeStorage: NodeStorage | undefined;
|
|
47
|
-
private networkClient: INetworkModule;
|
|
48
|
-
private cryptoProvider: CryptoProvider;
|
|
49
|
-
|
|
50
|
-
// authority needs to be faked to re-use existing functionality in msal-common: caching in responseHandler, etc.
|
|
51
|
-
private fakeAuthority: Authority;
|
|
52
|
-
|
|
53
|
-
// the ClientCredentialClient class needs to be faked to call it's getCachedAuthenticationResult method
|
|
54
|
-
private fakeClientCredentialClient: ClientCredentialClient;
|
|
55
|
-
|
|
56
|
-
private managedIdentityClient: ManagedIdentityClient;
|
|
57
|
-
|
|
58
|
-
constructor(configuration?: ManagedIdentityConfiguration) {
|
|
59
|
-
// undefined config means the managed identity is system-assigned
|
|
60
|
-
this.config = buildManagedIdentityConfiguration(configuration || {});
|
|
61
|
-
|
|
62
|
-
this.logger = new Logger(
|
|
63
|
-
this.config.system.loggerOptions,
|
|
64
|
-
name,
|
|
65
|
-
version
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const fakeStatusAuthorityOptions: StaticAuthorityOptions = {
|
|
69
|
-
canonicalAuthority: Constants.DEFAULT_AUTHORITY,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
if (!ManagedIdentityApplication.nodeStorage) {
|
|
73
|
-
ManagedIdentityApplication.nodeStorage = new NodeStorage(
|
|
74
|
-
this.logger,
|
|
75
|
-
this.config.managedIdentityId.id,
|
|
76
|
-
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
77
|
-
fakeStatusAuthorityOptions
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.networkClient = this.config.system.networkClient;
|
|
82
|
-
|
|
83
|
-
this.cryptoProvider = new CryptoProvider();
|
|
84
|
-
|
|
85
|
-
const fakeAuthorityOptions: AuthorityOptions = {
|
|
86
|
-
protocolMode: ProtocolMode.AAD,
|
|
87
|
-
knownAuthorities: [DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY],
|
|
88
|
-
cloudDiscoveryMetadata: "",
|
|
89
|
-
authorityMetadata: "",
|
|
90
|
-
};
|
|
91
|
-
this.fakeAuthority = new Authority(
|
|
92
|
-
DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY,
|
|
93
|
-
this.networkClient,
|
|
94
|
-
ManagedIdentityApplication.nodeStorage as NodeStorage,
|
|
95
|
-
fakeAuthorityOptions,
|
|
96
|
-
this.logger,
|
|
97
|
-
this.cryptoProvider.createNewGuid(), // correlationID
|
|
98
|
-
undefined,
|
|
99
|
-
true
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
this.fakeClientCredentialClient = new ClientCredentialClient({
|
|
103
|
-
authOptions: {
|
|
104
|
-
clientId: this.config.managedIdentityId.id,
|
|
105
|
-
authority: this.fakeAuthority,
|
|
106
|
-
} as AuthOptions,
|
|
107
|
-
} as ClientConfiguration);
|
|
108
|
-
|
|
109
|
-
this.managedIdentityClient = new ManagedIdentityClient(
|
|
110
|
-
this.logger,
|
|
111
|
-
ManagedIdentityApplication.nodeStorage as NodeStorage,
|
|
112
|
-
this.networkClient,
|
|
113
|
-
this.cryptoProvider
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Acquire an access token from the cache or the managed identity
|
|
119
|
-
* @param managedIdentityRequest
|
|
120
|
-
* @returns the access token
|
|
121
|
-
*/
|
|
122
|
-
public async acquireToken(
|
|
123
|
-
managedIdentityRequestParams: ManagedIdentityRequestParams
|
|
124
|
-
): Promise<AuthenticationResult> {
|
|
125
|
-
const resourceUrlString = new UrlString(
|
|
126
|
-
managedIdentityRequestParams.resource.replace("/.default", "")
|
|
127
|
-
);
|
|
128
|
-
try {
|
|
129
|
-
resourceUrlString.validateAsUri();
|
|
130
|
-
} catch (e) {
|
|
131
|
-
throw createManagedIdentityError(
|
|
132
|
-
ManagedIdentityErrorCodes.invalidResource
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const managedIdentityRequest: ManagedIdentityRequest = {
|
|
137
|
-
forceRefresh: managedIdentityRequestParams.forceRefresh,
|
|
138
|
-
resource: managedIdentityRequestParams.resource.replace(
|
|
139
|
-
"/.default",
|
|
140
|
-
""
|
|
141
|
-
),
|
|
142
|
-
scopes: [
|
|
143
|
-
managedIdentityRequestParams.resource.replace("/.default", ""),
|
|
144
|
-
],
|
|
145
|
-
authority: this.fakeAuthority.canonicalAuthority,
|
|
146
|
-
correlationId: this.cryptoProvider.createNewGuid(),
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
if (managedIdentityRequest.forceRefresh) {
|
|
150
|
-
// make a network call to the managed identity source
|
|
151
|
-
return this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
|
152
|
-
managedIdentityRequest,
|
|
153
|
-
this.config.managedIdentityId,
|
|
154
|
-
this.fakeAuthority
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const [cachedAuthenticationResult, lastCacheOutcome] =
|
|
159
|
-
await this.fakeClientCredentialClient.getCachedAuthenticationResult(
|
|
160
|
-
managedIdentityRequest,
|
|
161
|
-
this.config,
|
|
162
|
-
this.cryptoProvider,
|
|
163
|
-
this.fakeAuthority,
|
|
164
|
-
ManagedIdentityApplication.nodeStorage as NodeStorage
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
if (cachedAuthenticationResult) {
|
|
168
|
-
// if the token is not expired but must be refreshed; get a new one in the background
|
|
169
|
-
if (lastCacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
|
|
170
|
-
this.logger.info(
|
|
171
|
-
"ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed."
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
// make a network call to the managed identity source; refresh the access token in the background
|
|
175
|
-
const refreshAccessToken = true;
|
|
176
|
-
await this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
|
177
|
-
managedIdentityRequest,
|
|
178
|
-
this.config.managedIdentityId,
|
|
179
|
-
this.fakeAuthority,
|
|
180
|
-
refreshAccessToken
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return cachedAuthenticationResult;
|
|
185
|
-
} else {
|
|
186
|
-
// make a network call to the managed identity source
|
|
187
|
-
return this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
|
188
|
-
managedIdentityRequest,
|
|
189
|
-
this.config.managedIdentityId,
|
|
190
|
-
this.fakeAuthority
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
Authority,
|
|
8
|
-
INetworkModule,
|
|
9
|
-
Logger,
|
|
10
|
-
AuthenticationResult,
|
|
11
|
-
} from "@azure/msal-common";
|
|
12
|
-
import { AppService } from "./ManagedIdentitySources/AppService";
|
|
13
|
-
import { AzureArc } from "./ManagedIdentitySources/AzureArc";
|
|
14
|
-
import { CloudShell } from "./ManagedIdentitySources/CloudShell";
|
|
15
|
-
import { Imds } from "./ManagedIdentitySources/Imds";
|
|
16
|
-
import { ServiceFabric } from "./ManagedIdentitySources/ServiceFabric";
|
|
17
|
-
import { CryptoProvider } from "../crypto/CryptoProvider";
|
|
18
|
-
import {
|
|
19
|
-
ManagedIdentityErrorCodes,
|
|
20
|
-
createManagedIdentityError,
|
|
21
|
-
} from "../error/ManagedIdentityError";
|
|
22
|
-
import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest";
|
|
23
|
-
import { ManagedIdentityId } from "../config/ManagedIdentityId";
|
|
24
|
-
import { NodeStorage } from "../cache/NodeStorage";
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
* Class to initialize a managed identity and identify the service.
|
|
28
|
-
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ManagedIdentityClient.cs
|
|
29
|
-
*/
|
|
30
|
-
export class ManagedIdentityClient {
|
|
31
|
-
private logger: Logger;
|
|
32
|
-
private nodeStorage: NodeStorage;
|
|
33
|
-
private networkClient: INetworkModule;
|
|
34
|
-
private cryptoProvider: CryptoProvider;
|
|
35
|
-
|
|
36
|
-
static identitySource:
|
|
37
|
-
| ServiceFabric
|
|
38
|
-
| AppService
|
|
39
|
-
| CloudShell
|
|
40
|
-
| AzureArc
|
|
41
|
-
| Imds
|
|
42
|
-
| undefined;
|
|
43
|
-
|
|
44
|
-
constructor(
|
|
45
|
-
logger: Logger,
|
|
46
|
-
nodeStorage: NodeStorage,
|
|
47
|
-
networkClient: INetworkModule,
|
|
48
|
-
cryptoProvider: CryptoProvider
|
|
49
|
-
) {
|
|
50
|
-
this.logger = logger;
|
|
51
|
-
this.nodeStorage = nodeStorage;
|
|
52
|
-
this.networkClient = networkClient;
|
|
53
|
-
this.cryptoProvider = cryptoProvider;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public async sendManagedIdentityTokenRequest(
|
|
57
|
-
managedIdentityRequest: ManagedIdentityRequest,
|
|
58
|
-
managedIdentityId: ManagedIdentityId,
|
|
59
|
-
fakeAuthority: Authority,
|
|
60
|
-
refreshAccessToken?: boolean
|
|
61
|
-
): Promise<AuthenticationResult> {
|
|
62
|
-
if (!ManagedIdentityClient.identitySource) {
|
|
63
|
-
ManagedIdentityClient.identitySource =
|
|
64
|
-
this.selectManagedIdentitySource(
|
|
65
|
-
this.logger,
|
|
66
|
-
this.nodeStorage,
|
|
67
|
-
this.networkClient,
|
|
68
|
-
this.cryptoProvider,
|
|
69
|
-
managedIdentityId
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return ManagedIdentityClient.identitySource.acquireTokenWithManagedIdentity(
|
|
74
|
-
managedIdentityRequest,
|
|
75
|
-
managedIdentityId,
|
|
76
|
-
fakeAuthority,
|
|
77
|
-
refreshAccessToken
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Tries to create a managed identity source for all sources
|
|
83
|
-
* @returns the managed identity Source
|
|
84
|
-
*/
|
|
85
|
-
private selectManagedIdentitySource(
|
|
86
|
-
logger: Logger,
|
|
87
|
-
nodeStorage: NodeStorage,
|
|
88
|
-
networkClient: INetworkModule,
|
|
89
|
-
cryptoProvider: CryptoProvider,
|
|
90
|
-
managedIdentityId: ManagedIdentityId
|
|
91
|
-
): ServiceFabric | AppService | CloudShell | AzureArc | Imds {
|
|
92
|
-
const source =
|
|
93
|
-
ServiceFabric.tryCreate(
|
|
94
|
-
logger,
|
|
95
|
-
nodeStorage,
|
|
96
|
-
networkClient,
|
|
97
|
-
cryptoProvider,
|
|
98
|
-
managedIdentityId
|
|
99
|
-
) ||
|
|
100
|
-
AppService.tryCreate(
|
|
101
|
-
logger,
|
|
102
|
-
nodeStorage,
|
|
103
|
-
networkClient,
|
|
104
|
-
cryptoProvider
|
|
105
|
-
) ||
|
|
106
|
-
CloudShell.tryCreate(
|
|
107
|
-
logger,
|
|
108
|
-
nodeStorage,
|
|
109
|
-
networkClient,
|
|
110
|
-
cryptoProvider,
|
|
111
|
-
managedIdentityId
|
|
112
|
-
) ||
|
|
113
|
-
AzureArc.tryCreate(
|
|
114
|
-
logger,
|
|
115
|
-
nodeStorage,
|
|
116
|
-
networkClient,
|
|
117
|
-
cryptoProvider,
|
|
118
|
-
managedIdentityId
|
|
119
|
-
) ||
|
|
120
|
-
Imds.tryCreate(logger, nodeStorage, networkClient, cryptoProvider);
|
|
121
|
-
if (!source) {
|
|
122
|
-
throw createManagedIdentityError(
|
|
123
|
-
ManagedIdentityErrorCodes.unableToCreateSource
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return source;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,122 +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 { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
8
|
-
import {
|
|
9
|
-
HttpMethod,
|
|
10
|
-
APP_SERVICE_SECRET_HEADER_NAME,
|
|
11
|
-
API_VERSION_QUERY_PARAMETER_NAME,
|
|
12
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
13
|
-
ManagedIdentityEnvironmentVariableNames,
|
|
14
|
-
ManagedIdentitySourceNames,
|
|
15
|
-
ManagedIdentityIdType,
|
|
16
|
-
} from "../../utils/Constants";
|
|
17
|
-
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
18
|
-
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
19
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
20
|
-
import { NodeStorage } from "../../cache/NodeStorage";
|
|
21
|
-
|
|
22
|
-
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
|
23
|
-
const APP_SERVICE_MSI_API_VERSION: string = "2019-08-01";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AppServiceManagedIdentitySource.cs
|
|
27
|
-
*/
|
|
28
|
-
export class AppService 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
|
-
): AppService | null {
|
|
52
|
-
const identityEndpoint: string | undefined =
|
|
53
|
-
process.env[
|
|
54
|
-
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
|
55
|
-
];
|
|
56
|
-
const identityHeader: string | undefined =
|
|
57
|
-
process.env[
|
|
58
|
-
ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
// if either of the identity endpoint or identity header variables are undefined, this MSI provider is unavailable.
|
|
62
|
-
if (!identityEndpoint || !identityHeader) {
|
|
63
|
-
logger.info(
|
|
64
|
-
`[Managed Identity] ${ManagedIdentitySourceNames.APP_SERVICE} managed identity is unavailable because one or both of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}' and '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' environment variables are not defined.`
|
|
65
|
-
);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const validatedIdentityEndpoint: string =
|
|
70
|
-
AppService.getValidatedEnvVariableUrlString(
|
|
71
|
-
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
|
72
|
-
identityEndpoint,
|
|
73
|
-
ManagedIdentitySourceNames.APP_SERVICE,
|
|
74
|
-
logger
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
logger.info(
|
|
78
|
-
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.APP_SERVICE} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.APP_SERVICE} managed identity.`
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
return new AppService(
|
|
82
|
-
logger,
|
|
83
|
-
nodeStorage,
|
|
84
|
-
networkClient,
|
|
85
|
-
cryptoProvider,
|
|
86
|
-
identityEndpoint,
|
|
87
|
-
identityHeader
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public createRequest(
|
|
92
|
-
resource: string,
|
|
93
|
-
managedIdentityId: ManagedIdentityId
|
|
94
|
-
): ManagedIdentityRequestParameters {
|
|
95
|
-
const request: ManagedIdentityRequestParameters =
|
|
96
|
-
new ManagedIdentityRequestParameters(
|
|
97
|
-
HttpMethod.GET,
|
|
98
|
-
this.identityEndpoint
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
request.headers[APP_SERVICE_SECRET_HEADER_NAME] = this.identityHeader;
|
|
102
|
-
|
|
103
|
-
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
104
|
-
APP_SERVICE_MSI_API_VERSION;
|
|
105
|
-
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
106
|
-
resource;
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
110
|
-
) {
|
|
111
|
-
request.queryParameters[
|
|
112
|
-
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
|
113
|
-
managedIdentityId.idType
|
|
114
|
-
)
|
|
115
|
-
] = managedIdentityId.id;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
119
|
-
|
|
120
|
-
return request;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
AuthError,
|
|
8
|
-
ClientAuthErrorCodes,
|
|
9
|
-
createClientAuthError,
|
|
10
|
-
HttpStatus,
|
|
11
|
-
INetworkModule,
|
|
12
|
-
NetworkResponse,
|
|
13
|
-
NetworkRequestOptions,
|
|
14
|
-
Logger,
|
|
15
|
-
ServerAuthorizationTokenResponse,
|
|
16
|
-
} from "@azure/msal-common";
|
|
17
|
-
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters";
|
|
18
|
-
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource";
|
|
19
|
-
import { CryptoProvider } from "../../crypto/CryptoProvider";
|
|
20
|
-
import {
|
|
21
|
-
ManagedIdentityErrorCodes,
|
|
22
|
-
createManagedIdentityError,
|
|
23
|
-
} from "../../error/ManagedIdentityError";
|
|
24
|
-
import {
|
|
25
|
-
API_VERSION_QUERY_PARAMETER_NAME,
|
|
26
|
-
AUTHORIZATION_HEADER_NAME,
|
|
27
|
-
HttpMethod,
|
|
28
|
-
METADATA_HEADER_NAME,
|
|
29
|
-
ManagedIdentityEnvironmentVariableNames,
|
|
30
|
-
ManagedIdentityIdType,
|
|
31
|
-
ManagedIdentitySourceNames,
|
|
32
|
-
RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
|
|
33
|
-
} from "../../utils/Constants";
|
|
34
|
-
import { NodeStorage } from "../../cache/NodeStorage";
|
|
35
|
-
import { readFileSync } from "fs";
|
|
36
|
-
import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse";
|
|
37
|
-
import { ManagedIdentityId } from "../../config/ManagedIdentityId";
|
|
38
|
-
|
|
39
|
-
export const ARC_API_VERSION: string = "2019-11-01";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
|
|
43
|
-
*/
|
|
44
|
-
export class AzureArc extends BaseManagedIdentitySource {
|
|
45
|
-
private identityEndpoint: string;
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
logger: Logger,
|
|
49
|
-
nodeStorage: NodeStorage,
|
|
50
|
-
networkClient: INetworkModule,
|
|
51
|
-
cryptoProvider: CryptoProvider,
|
|
52
|
-
identityEndpoint: string
|
|
53
|
-
) {
|
|
54
|
-
super(logger, nodeStorage, networkClient, cryptoProvider);
|
|
55
|
-
|
|
56
|
-
this.identityEndpoint = identityEndpoint;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public static tryCreate(
|
|
60
|
-
logger: Logger,
|
|
61
|
-
nodeStorage: NodeStorage,
|
|
62
|
-
networkClient: INetworkModule,
|
|
63
|
-
cryptoProvider: CryptoProvider,
|
|
64
|
-
managedIdentityId: ManagedIdentityId
|
|
65
|
-
): AzureArc | null {
|
|
66
|
-
const identityEndpoint: string | undefined =
|
|
67
|
-
process.env[
|
|
68
|
-
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
|
69
|
-
];
|
|
70
|
-
const imdsEndpoint: string | undefined =
|
|
71
|
-
process.env[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT];
|
|
72
|
-
|
|
73
|
-
// if either of the identity or imds endpoints are undefined, this MSI provider is unavailable.
|
|
74
|
-
if (!identityEndpoint || !imdsEndpoint) {
|
|
75
|
-
logger.info(
|
|
76
|
-
`[Managed Identity] ${ManagedIdentitySourceNames.AZURE_ARC} managed identity is unavailable because one or both of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' and '${ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT}' environment variables are not defined.`
|
|
77
|
-
);
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const validatedIdentityEndpoint: string =
|
|
82
|
-
AzureArc.getValidatedEnvVariableUrlString(
|
|
83
|
-
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
|
84
|
-
identityEndpoint,
|
|
85
|
-
ManagedIdentitySourceNames.AZURE_ARC,
|
|
86
|
-
logger
|
|
87
|
-
);
|
|
88
|
-
// remove trailing slash
|
|
89
|
-
validatedIdentityEndpoint.endsWith("/")
|
|
90
|
-
? validatedIdentityEndpoint.slice(0, -1)
|
|
91
|
-
: validatedIdentityEndpoint;
|
|
92
|
-
|
|
93
|
-
AzureArc.getValidatedEnvVariableUrlString(
|
|
94
|
-
ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT,
|
|
95
|
-
imdsEndpoint,
|
|
96
|
-
ManagedIdentitySourceNames.AZURE_ARC,
|
|
97
|
-
logger
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
logger.info(
|
|
101
|
-
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.AZURE_ARC} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.AZURE_ARC} managed identity.`
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
|
106
|
-
) {
|
|
107
|
-
throw createManagedIdentityError(
|
|
108
|
-
ManagedIdentityErrorCodes.unableToCreateAzureArc
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return new AzureArc(
|
|
113
|
-
logger,
|
|
114
|
-
nodeStorage,
|
|
115
|
-
networkClient,
|
|
116
|
-
cryptoProvider,
|
|
117
|
-
identityEndpoint
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
|
122
|
-
const request: ManagedIdentityRequestParameters =
|
|
123
|
-
new ManagedIdentityRequestParameters(
|
|
124
|
-
HttpMethod.GET,
|
|
125
|
-
this.identityEndpoint.replace("localhost", "127.0.0.1")
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
request.headers[METADATA_HEADER_NAME] = "true";
|
|
129
|
-
|
|
130
|
-
request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
|
|
131
|
-
ARC_API_VERSION;
|
|
132
|
-
request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
|
|
133
|
-
resource;
|
|
134
|
-
|
|
135
|
-
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
|
136
|
-
|
|
137
|
-
return request;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public async getServerTokenResponseAsync(
|
|
141
|
-
originalResponse: NetworkResponse<ManagedIdentityTokenResponse>,
|
|
142
|
-
networkClient: INetworkModule,
|
|
143
|
-
networkRequest: ManagedIdentityRequestParameters,
|
|
144
|
-
networkRequestOptions: NetworkRequestOptions
|
|
145
|
-
): Promise<ServerAuthorizationTokenResponse> {
|
|
146
|
-
let retryResponse:
|
|
147
|
-
| NetworkResponse<ManagedIdentityTokenResponse>
|
|
148
|
-
| undefined;
|
|
149
|
-
|
|
150
|
-
if (originalResponse.status === HttpStatus.UNAUTHORIZED) {
|
|
151
|
-
const wwwAuthHeader: string =
|
|
152
|
-
originalResponse.headers["www-authenticate"];
|
|
153
|
-
if (!wwwAuthHeader) {
|
|
154
|
-
throw createManagedIdentityError(
|
|
155
|
-
ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (!wwwAuthHeader.includes("Basic realm=")) {
|
|
159
|
-
throw createManagedIdentityError(
|
|
160
|
-
ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const secretFile = wwwAuthHeader.split("Basic realm=")[1];
|
|
165
|
-
let secret;
|
|
166
|
-
try {
|
|
167
|
-
secret = readFileSync(secretFile, "utf-8");
|
|
168
|
-
} catch (e) {
|
|
169
|
-
throw createManagedIdentityError(
|
|
170
|
-
ManagedIdentityErrorCodes.unableToReadSecretFile
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
const authHeaderValue = `Basic ${secret}`;
|
|
174
|
-
|
|
175
|
-
this.logger.info(
|
|
176
|
-
`[Managed Identity] Adding authorization header to the request.`
|
|
177
|
-
);
|
|
178
|
-
networkRequest.headers[AUTHORIZATION_HEADER_NAME] = authHeaderValue;
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
retryResponse =
|
|
182
|
-
await networkClient.sendGetRequestAsync<ManagedIdentityTokenResponse>(
|
|
183
|
-
networkRequest.computeUri(),
|
|
184
|
-
networkRequestOptions
|
|
185
|
-
);
|
|
186
|
-
} catch (error) {
|
|
187
|
-
if (error instanceof AuthError) {
|
|
188
|
-
throw error;
|
|
189
|
-
} else {
|
|
190
|
-
throw createClientAuthError(
|
|
191
|
-
ClientAuthErrorCodes.networkError
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return this.getServerTokenResponse(retryResponse || originalResponse);
|
|
198
|
-
}
|
|
199
|
-
}
|