@azure/identity 4.3.0-beta.2 → 4.3.1-alpha.20240618.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -8
- package/dist/index.js +61 -83
- package/dist/index.js.map +1 -1
- package/dist-esm/src/constants.js +1 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/credentials/azurePipelinesCredential.js +35 -60
- package/dist-esm/src/credentials/azurePipelinesCredential.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClient.js +27 -24
- package/dist-esm/src/msal/nodeFlows/msalClient.js.map +1 -1
- package/package.json +3 -3
- package/types/identity.d.ts +3 -8
package/README.md
CHANGED
@@ -14,10 +14,6 @@ Key links:
|
|
14
14
|
|
15
15
|
## Getting started
|
16
16
|
|
17
|
-
### Migrate from v1 to v2 of @azure/identity
|
18
|
-
|
19
|
-
If you're using v1 of `@azure/identity`, see the [migration guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/migration-v1-v2.md) to update to v2.
|
20
|
-
|
21
17
|
### Currently supported environments
|
22
18
|
|
23
19
|
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
|
@@ -62,7 +58,7 @@ For advanced authentication workflows in the browser, we have a section where we
|
|
62
58
|
|
63
59
|
### Authenticate the client in development environment
|
64
60
|
|
65
|
-
While we recommend using managed identity
|
61
|
+
While we recommend using managed identity in your Azure-hosted application, it is typical for a developer to use their own account for authenticating calls to Azure services when debugging and executing code locally. There are several developer tools which can be used to perform this authentication in your development environment.
|
66
62
|
|
67
63
|
#### Authenticate via the Azure Developer CLI
|
68
64
|
|
@@ -88,7 +84,7 @@ For systems without a default web browser, the `az login` command will use the d
|
|
88
84
|
|
89
85
|
Applications using the `AzurePowerShellCredential`, whether directly or via the `DefaultAzureCredential`, can use the account connected to Azure PowerShell to authenticate calls in the application when running locally.
|
90
86
|
|
91
|
-
To authenticate with [Azure PowerShell][azure_powershell] users can run the `Connect-AzAccount` cmdlet. By default,
|
87
|
+
To authenticate with [Azure PowerShell][azure_powershell] users can run the `Connect-AzAccount` cmdlet. By default, like the Azure CLI, `Connect-AzAccount` will launch the default web browser to authenticate a user account.
|
92
88
|
|
93
89
|
![Azure PowerShell Account Sign In][azurepowershelllogin_image]
|
94
90
|
|
@@ -151,8 +147,8 @@ Due to a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500),
|
|
151
147
|
|
152
148
|
Azure Identity for JavaScript provides a plugin API that allows us to provide certain functionality through separate _plugin packages_. The `@azure/identity` package exports a top-level function (`useIdentityPlugin`) that can be used to enable a plugin. We provide two plugin packages:
|
153
149
|
|
154
|
-
- [`@azure/identity-broker`](https://
|
155
|
-
- [`@azure/identity-cache-persistence`](https://
|
150
|
+
- [`@azure/identity-broker`](https://www.npmjs.com/package/@azure/identity-broker), which provides brokered authentication support through a native broker, such as Web Account Manager.
|
151
|
+
- [`@azure/identity-cache-persistence`](https://www.npmjs.com/package/@azure/identity-cache-persistence), which provides persistent token caching in Node.js using a native secure storage system provided by your operating system. This plugin allows cached `access_token` values to persist across sessions, meaning that an interactive login flow does not need to be repeated as long as a cached token is available.
|
156
152
|
|
157
153
|
## Examples
|
158
154
|
|
package/dist/index.js
CHANGED
@@ -45,7 +45,7 @@ var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_proce
|
|
45
45
|
/**
|
46
46
|
* Current version of the `@azure/identity` package.
|
47
47
|
*/
|
48
|
-
const SDK_VERSION = `4.3.
|
48
|
+
const SDK_VERSION = `4.3.1`;
|
49
49
|
/**
|
50
50
|
* The default client ID for authentication
|
51
51
|
* @internal
|
@@ -1931,7 +1931,7 @@ function calculateRegionalAuthority(regionalAuthority) {
|
|
1931
1931
|
// Copyright (c) Microsoft Corporation.
|
1932
1932
|
// Licensed under the MIT license.
|
1933
1933
|
/**
|
1934
|
-
* The logger
|
1934
|
+
* The default logger used if no logger was passed in by the credential.
|
1935
1935
|
*/
|
1936
1936
|
const msalLogger = credentialLogger("MsalClient");
|
1937
1937
|
/**
|
@@ -1943,10 +1943,10 @@ const msalLogger = credentialLogger("MsalClient");
|
|
1943
1943
|
* @returns The MSAL configuration object.
|
1944
1944
|
*/
|
1945
1945
|
function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
|
1946
|
-
var _a, _b, _c;
|
1947
|
-
const resolvedTenant = resolveTenantId(msalLogger, tenantId, clientId);
|
1946
|
+
var _a, _b, _c, _d;
|
1947
|
+
const resolvedTenant = resolveTenantId((_a = msalClientOptions.logger) !== null && _a !== void 0 ? _a : msalLogger, tenantId, clientId);
|
1948
1948
|
// TODO: move and reuse getIdentityClientAuthorityHost
|
1949
|
-
const authority = getAuthority(resolvedTenant, (
|
1949
|
+
const authority = getAuthority(resolvedTenant, (_b = msalClientOptions.authorityHost) !== null && _b !== void 0 ? _b : process.env.AZURE_AUTHORITY_HOST);
|
1950
1950
|
const httpClient = new IdentityClient(Object.assign(Object.assign({}, msalClientOptions.tokenCredentialOptions), { authorityHost: authority, loggingOptions: msalClientOptions.loggingOptions }));
|
1951
1951
|
const msalConfig = {
|
1952
1952
|
auth: {
|
@@ -1957,9 +1957,9 @@ function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
|
|
1957
1957
|
system: {
|
1958
1958
|
networkClient: httpClient,
|
1959
1959
|
loggerOptions: {
|
1960
|
-
loggerCallback: defaultLoggerCallback((
|
1960
|
+
loggerCallback: defaultLoggerCallback((_c = msalClientOptions.logger) !== null && _c !== void 0 ? _c : msalLogger),
|
1961
1961
|
logLevel: getMSALLogLevel(logger$r.getLogLevel()),
|
1962
|
-
piiLoggingEnabled: (
|
1962
|
+
piiLoggingEnabled: (_d = msalClientOptions.loggingOptions) === null || _d === void 0 ? void 0 : _d.enableUnsafeSupportLogging,
|
1963
1963
|
},
|
1964
1964
|
},
|
1965
1965
|
};
|
@@ -1976,23 +1976,25 @@ function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
|
|
1976
1976
|
* @public
|
1977
1977
|
*/
|
1978
1978
|
function createMsalClient(clientId, tenantId, createMsalClientOptions = {}) {
|
1979
|
+
var _a;
|
1979
1980
|
const state = {
|
1980
1981
|
msalConfig: generateMsalConfiguration(clientId, tenantId, createMsalClientOptions),
|
1981
1982
|
cachedAccount: createMsalClientOptions.authenticationRecord
|
1982
1983
|
? publicToMsal(createMsalClientOptions.authenticationRecord)
|
1983
1984
|
: null,
|
1984
1985
|
pluginConfiguration: msalPlugins.generatePluginConfiguration(createMsalClientOptions),
|
1986
|
+
logger: (_a = createMsalClientOptions.logger) !== null && _a !== void 0 ? _a : msalLogger,
|
1985
1987
|
};
|
1986
1988
|
const publicApps = new Map();
|
1987
1989
|
async function getPublicApp(options = {}) {
|
1988
1990
|
const appKey = options.enableCae ? "CAE" : "default";
|
1989
1991
|
let publicClientApp = publicApps.get(appKey);
|
1990
1992
|
if (publicClientApp) {
|
1991
|
-
|
1993
|
+
state.logger.getToken.info("Existing PublicClientApplication found in cache, returning it.");
|
1992
1994
|
return publicClientApp;
|
1993
1995
|
}
|
1994
1996
|
// Initialize a new app and cache it
|
1995
|
-
|
1997
|
+
state.logger.getToken.info(`Creating new PublicClientApplication with CAE ${options.enableCae ? "enabled" : "disabled"}.`);
|
1996
1998
|
const cachePlugin = options.enableCae
|
1997
1999
|
? state.pluginConfiguration.cache.cachePluginCae
|
1998
2000
|
: state.pluginConfiguration.cache.cachePlugin;
|
@@ -2006,11 +2008,11 @@ function createMsalClient(clientId, tenantId, createMsalClientOptions = {}) {
|
|
2006
2008
|
const appKey = options.enableCae ? "CAE" : "default";
|
2007
2009
|
let confidentialClientApp = confidentialApps.get(appKey);
|
2008
2010
|
if (confidentialClientApp) {
|
2009
|
-
|
2011
|
+
state.logger.getToken.info("Existing ConfidentialClientApplication found in cache, returning it.");
|
2010
2012
|
return confidentialClientApp;
|
2011
2013
|
}
|
2012
2014
|
// Initialize a new app and cache it
|
2013
|
-
|
2015
|
+
state.logger.getToken.info(`Creating new ConfidentialClientApplication with CAE ${options.enableCae ? "enabled" : "disabled"}.`);
|
2014
2016
|
const cachePlugin = options.enableCae
|
2015
2017
|
? state.pluginConfiguration.cache.cachePluginCae
|
2016
2018
|
: state.pluginConfiguration.cache.cachePlugin;
|
@@ -2021,14 +2023,15 @@ function createMsalClient(clientId, tenantId, createMsalClientOptions = {}) {
|
|
2021
2023
|
}
|
2022
2024
|
async function getTokenSilent(app, scopes, options = {}) {
|
2023
2025
|
if (state.cachedAccount === null) {
|
2024
|
-
|
2026
|
+
state.logger.getToken.info("No cached account found in local state, attempting to load it from MSAL cache.");
|
2025
2027
|
const cache = app.getTokenCache();
|
2026
2028
|
const accounts = await cache.getAllAccounts();
|
2027
2029
|
if (accounts === undefined || accounts.length === 0) {
|
2028
2030
|
throw new AuthenticationRequiredError({ scopes });
|
2029
2031
|
}
|
2030
2032
|
if (accounts.length > 1) {
|
2031
|
-
|
2033
|
+
state.logger
|
2034
|
+
.info(`More than one account was found authenticated for this Client ID and Tenant ID.
|
2032
2035
|
However, no "authenticationRecord" has been provided for this credential,
|
2033
2036
|
therefore we're unable to pick between these accounts.
|
2034
2037
|
A new login attempt will be requested, to ensure the correct account is picked.
|
@@ -2052,7 +2055,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2052
2055
|
silentRequest.tokenQueryParameters["msal_request_type"] = "consumer_passthrough";
|
2053
2056
|
}
|
2054
2057
|
}
|
2055
|
-
|
2058
|
+
state.logger.getToken.info("Attempting to acquire token silently");
|
2056
2059
|
return app.acquireTokenSilent(silentRequest);
|
2057
2060
|
}
|
2058
2061
|
/**
|
@@ -2095,14 +2098,14 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2095
2098
|
// At this point we should have a token, process it
|
2096
2099
|
ensureValidMsalToken(scopes, response, options);
|
2097
2100
|
state.cachedAccount = (_a = response === null || response === void 0 ? void 0 : response.account) !== null && _a !== void 0 ? _a : null;
|
2098
|
-
|
2101
|
+
state.logger.getToken.info(formatSuccess(scopes));
|
2099
2102
|
return {
|
2100
2103
|
token: response.accessToken,
|
2101
2104
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
2102
2105
|
};
|
2103
2106
|
}
|
2104
2107
|
async function getTokenByClientSecret(scopes, clientSecret, options = {}) {
|
2105
|
-
|
2108
|
+
state.logger.getToken.info(`Attempting to acquire token using client secret`);
|
2106
2109
|
state.msalConfig.auth.clientSecret = clientSecret;
|
2107
2110
|
const msalApp = await getConfidentialApp(options);
|
2108
2111
|
try {
|
@@ -2113,7 +2116,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2113
2116
|
claims: options === null || options === void 0 ? void 0 : options.claims,
|
2114
2117
|
});
|
2115
2118
|
ensureValidMsalToken(scopes, response, options);
|
2116
|
-
|
2119
|
+
state.logger.getToken.info(formatSuccess(scopes));
|
2117
2120
|
return {
|
2118
2121
|
token: response.accessToken,
|
2119
2122
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
@@ -2124,7 +2127,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2124
2127
|
}
|
2125
2128
|
}
|
2126
2129
|
async function getTokenByClientAssertion(scopes, clientAssertion, options = {}) {
|
2127
|
-
|
2130
|
+
state.logger.getToken.info(`Attempting to acquire token using client assertion`);
|
2128
2131
|
state.msalConfig.auth.clientAssertion = clientAssertion;
|
2129
2132
|
const msalApp = await getConfidentialApp(options);
|
2130
2133
|
try {
|
@@ -2136,7 +2139,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2136
2139
|
clientAssertion,
|
2137
2140
|
});
|
2138
2141
|
ensureValidMsalToken(scopes, response, options);
|
2139
|
-
|
2142
|
+
state.logger.getToken.info(formatSuccess(scopes));
|
2140
2143
|
return {
|
2141
2144
|
token: response.accessToken,
|
2142
2145
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
@@ -2147,7 +2150,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2147
2150
|
}
|
2148
2151
|
}
|
2149
2152
|
async function getTokenByClientCertificate(scopes, certificate, options = {}) {
|
2150
|
-
|
2153
|
+
state.logger.getToken.info(`Attempting to acquire token using client certificate`);
|
2151
2154
|
state.msalConfig.auth.clientCertificate = certificate;
|
2152
2155
|
const msalApp = await getConfidentialApp(options);
|
2153
2156
|
try {
|
@@ -2158,7 +2161,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2158
2161
|
claims: options === null || options === void 0 ? void 0 : options.claims,
|
2159
2162
|
});
|
2160
2163
|
ensureValidMsalToken(scopes, response, options);
|
2161
|
-
|
2164
|
+
state.logger.getToken.info(formatSuccess(scopes));
|
2162
2165
|
return {
|
2163
2166
|
token: response.accessToken,
|
2164
2167
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
@@ -2169,7 +2172,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2169
2172
|
}
|
2170
2173
|
}
|
2171
2174
|
async function getTokenByDeviceCode(scopes, deviceCodeCallback, options = {}) {
|
2172
|
-
|
2175
|
+
state.logger.getToken.info(`Attempting to acquire token using device code`);
|
2173
2176
|
const msalApp = await getPublicApp(options);
|
2174
2177
|
return withSilentAuthentication(msalApp, scopes, options, () => {
|
2175
2178
|
var _a, _b;
|
@@ -2190,7 +2193,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2190
2193
|
});
|
2191
2194
|
}
|
2192
2195
|
async function getTokenByUsernamePassword(scopes, username, password, options = {}) {
|
2193
|
-
|
2196
|
+
state.logger.getToken.info(`Attempting to acquire token using username and password`);
|
2194
2197
|
const msalApp = await getPublicApp(options);
|
2195
2198
|
return withSilentAuthentication(msalApp, scopes, options, () => {
|
2196
2199
|
const requestOptions = {
|
@@ -2210,7 +2213,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
2210
2213
|
return msalToPublic(clientId, state.cachedAccount);
|
2211
2214
|
}
|
2212
2215
|
async function getTokenByAuthorizationCode(scopes, redirectUri, authorizationCode, clientSecret, options = {}) {
|
2213
|
-
|
2216
|
+
state.logger.getToken.info(`Attempting to acquire token using authorization code`);
|
2214
2217
|
let msalApp;
|
2215
2218
|
if (clientSecret) {
|
2216
2219
|
// If a client secret is provided, we need to use a confidential client application
|
@@ -4418,7 +4421,7 @@ class DeviceCodeCredential {
|
|
4418
4421
|
// Licensed under the MIT license.
|
4419
4422
|
const credentialName$1 = "AzurePipelinesCredential";
|
4420
4423
|
const logger$2 = credentialLogger(credentialName$1);
|
4421
|
-
const OIDC_API_VERSION = "7.1
|
4424
|
+
const OIDC_API_VERSION = "7.1";
|
4422
4425
|
/**
|
4423
4426
|
* This credential is designed to be used in Azure Pipelines with service connections
|
4424
4427
|
* as a setup for workload identity federation.
|
@@ -4428,23 +4431,23 @@ class AzurePipelinesCredential {
|
|
4428
4431
|
* AzurePipelinesCredential supports Federated Identity on Azure Pipelines through Service Connections.
|
4429
4432
|
* @param tenantId - tenantId associated with the service connection
|
4430
4433
|
* @param clientId - clientId associated with the service connection
|
4431
|
-
* @param serviceConnectionId -
|
4434
|
+
* @param serviceConnectionId - Unique ID for the service connection, as found in the querystring's resourceId key
|
4435
|
+
* @param systemAccessToken - The pipeline's <see href="https://learn.microsoft.com/azure/devops/pipelines/build/variables?view=azure-devops%26tabs=yaml#systemaccesstoken">System.AccessToken</see> value.
|
4432
4436
|
* @param options - The identity client options to use for authentication.
|
4433
4437
|
*/
|
4434
|
-
constructor(tenantId, clientId, serviceConnectionId, options) {
|
4435
|
-
if (!clientId || !tenantId || !serviceConnectionId) {
|
4436
|
-
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. tenantId, clientId, and
|
4438
|
+
constructor(tenantId, clientId, serviceConnectionId, systemAccessToken, options) {
|
4439
|
+
if (!clientId || !tenantId || !serviceConnectionId || !systemAccessToken) {
|
4440
|
+
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. tenantId, clientId, serviceConnectionId, and systemAccessToken are required parameters.`);
|
4437
4441
|
}
|
4438
4442
|
this.identityClient = new IdentityClient(options);
|
4439
4443
|
checkTenantId(logger$2, tenantId);
|
4440
|
-
logger$2.info(`Invoking AzurePipelinesCredential with tenant ID: ${tenantId},
|
4441
|
-
if (
|
4442
|
-
this
|
4443
|
-
const oidcRequestUrl = `${process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI}${process.env.SYSTEM_TEAMPROJECTID}/_apis/distributedtask/hubs/build/plans/${process.env.SYSTEM_PLANID}/jobs/${process.env.SYSTEM_JOBID}/oidctoken?api-version=${OIDC_API_VERSION}&serviceConnectionId=${serviceConnectionId}`;
|
4444
|
-
const systemAccessToken = `${process.env.SYSTEM_ACCESSTOKEN}`;
|
4445
|
-
logger$2.info(`Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${clientId} and service connection id: ${serviceConnectionId}`);
|
4446
|
-
this.clientAssertionCredential = new ClientAssertionCredential(tenantId, clientId, this.requestOidcToken.bind(this, oidcRequestUrl, systemAccessToken), options);
|
4444
|
+
logger$2.info(`Invoking AzurePipelinesCredential with tenant ID: ${tenantId}, client ID: ${clientId}, and service connection ID: ${serviceConnectionId}`);
|
4445
|
+
if (!process.env.SYSTEM_OIDCREQUESTURI) {
|
4446
|
+
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. Ensure that you're running this task in an Azure Pipeline, so that following missing system variable(s) can be defined- "SYSTEM_OIDCREQUESTURI"`);
|
4447
4447
|
}
|
4448
|
+
const oidcRequestUrl = `${process.env.SYSTEM_OIDCREQUESTURI}?api-version=${OIDC_API_VERSION}&serviceConnectionId=${serviceConnectionId}`;
|
4449
|
+
logger$2.info(`Invoking ClientAssertionCredential with tenant ID: ${tenantId}, client ID: ${clientId} and service connection ID: ${serviceConnectionId}`);
|
4450
|
+
this.clientAssertionCredential = new ClientAssertionCredential(tenantId, clientId, this.requestOidcToken.bind(this, oidcRequestUrl, systemAccessToken), options);
|
4448
4451
|
}
|
4449
4452
|
/**
|
4450
4453
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
@@ -4456,16 +4459,13 @@ class AzurePipelinesCredential {
|
|
4456
4459
|
*/
|
4457
4460
|
async getToken(scopes, options) {
|
4458
4461
|
if (!this.clientAssertionCredential) {
|
4459
|
-
const errorMessage = `${credentialName$1}: is unavailable. To use Federation Identity in Azure Pipelines,
|
4462
|
+
const errorMessage = `${credentialName$1}: is unavailable. To use Federation Identity in Azure Pipelines, the following parameters are required -
|
4460
4463
|
tenantId,
|
4461
4464
|
clientId,
|
4462
4465
|
serviceConnectionId,
|
4463
|
-
|
4464
|
-
"
|
4465
|
-
|
4466
|
-
"SYSTEM_JOBID" &&
|
4467
|
-
"SYSTEM_ACCESSTOKEN"
|
4468
|
-
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/troubleshoot`;
|
4466
|
+
systemAccessToken,
|
4467
|
+
"SYSTEM_OIDCREQUESTURI".
|
4468
|
+
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`;
|
4469
4469
|
logger$2.error(errorMessage);
|
4470
4470
|
throw new CredentialUnavailableError(errorMessage);
|
4471
4471
|
}
|
@@ -4493,48 +4493,26 @@ class AzurePipelinesCredential {
|
|
4493
4493
|
const text = response.bodyAsText;
|
4494
4494
|
if (!text) {
|
4495
4495
|
logger$2.error(`${credentialName$1}: Authenticated Failed. Received null token from OIDC request. Response status- ${response.status}. Complete response - ${JSON.stringify(response)}`);
|
4496
|
-
throw new
|
4497
|
-
}
|
4498
|
-
const result = JSON.parse(text);
|
4499
|
-
if (result === null || result === void 0 ? void 0 : result.oidcToken) {
|
4500
|
-
return result.oidcToken;
|
4496
|
+
throw new AuthenticationError(response.status, `${credentialName$1}: Authenticated Failed. Received null token from OIDC request. Response status- ${response.status}. Complete response - ${JSON.stringify(response)}`);
|
4501
4497
|
}
|
4502
|
-
|
4503
|
-
|
4504
|
-
|
4505
|
-
|
4506
|
-
|
4507
|
-
|
4508
|
-
|
4509
|
-
|
4510
|
-
|
4511
|
-
|
4512
|
-
|
4513
|
-
|
4514
|
-
|
4515
|
-
process.env.SYSTEM_PLANID &&
|
4516
|
-
process.env.SYSTEM_JOBID &&
|
4517
|
-
process.env.SYSTEM_ACCESSTOKEN) {
|
4518
|
-
return;
|
4498
|
+
try {
|
4499
|
+
const result = JSON.parse(text);
|
4500
|
+
if (result === null || result === void 0 ? void 0 : result.oidcToken) {
|
4501
|
+
return result.oidcToken;
|
4502
|
+
}
|
4503
|
+
else {
|
4504
|
+
let errorMessage = `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response.`;
|
4505
|
+
if (response.status !== 200) {
|
4506
|
+
errorMessage += `Response = ${JSON.stringify(result)}`;
|
4507
|
+
}
|
4508
|
+
logger$2.error(errorMessage);
|
4509
|
+
throw new AuthenticationError(response.status, errorMessage);
|
4510
|
+
}
|
4519
4511
|
}
|
4520
|
-
|
4521
|
-
|
4522
|
-
|
4523
|
-
|
4524
|
-
}
|
4525
|
-
if (!process.env.SYSTEM_TEAMPROJECTID)
|
4526
|
-
missingEnvVars.push("SYSTEM_TEAMPROJECTID");
|
4527
|
-
if (!process.env.SYSTEM_PLANID)
|
4528
|
-
missingEnvVars.push("SYSTEM_PLANID");
|
4529
|
-
if (!process.env.SYSTEM_JOBID)
|
4530
|
-
missingEnvVars.push("SYSTEM_JOBID");
|
4531
|
-
if (!process.env.SYSTEM_ACCESSTOKEN) {
|
4532
|
-
errorMessage +=
|
4533
|
-
"\nPlease ensure that the system access token is available in the SYSTEM_ACCESSTOKEN value; this is often most easily achieved by adding a block to the end of your pipeline yaml for the task with:\n env: \n- SYSTEM_ACCESSTOKEN: $(System.AccessToken)";
|
4534
|
-
missingEnvVars.push("SYSTEM_ACCESSTOKEN");
|
4535
|
-
}
|
4536
|
-
if (missingEnvVars.length > 0) {
|
4537
|
-
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. Ensure that you're running this task in an Azure Pipeline, so that following missing system variable(s) can be defined- ${missingEnvVars.join(", ")}.${errorMessage}`);
|
4512
|
+
catch (e) {
|
4513
|
+
logger$2.error(e.message);
|
4514
|
+
logger$2.error(`${credentialName$1}: Authentication Failed. oidcToken field not detected in the response. Response = ${text}`);
|
4515
|
+
throw new AuthenticationError(response.status, `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response. Response = ${text}`);
|
4538
4516
|
}
|
4539
4517
|
}
|
4540
4518
|
}
|