Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
const response = await this.sendTokenRequest(webResource, expiresOnParser);
logger.info(`IdentityClient: refreshed token for client ID: ${clientId}`);
return response;
} catch (err) {
if (
err.name === AuthenticationErrorName &&
err.errorResponse.error === "interaction_required"
) {
// It's likely that the refresh token has expired, so
// return null so that the credential implementation will
// initiate the authentication flow again.
logger.info(`IdentityClient: interaction required for client ID: ${clientId}`);
span.setStatus({
code: CanonicalCode.UNAUTHENTICATED,
message: err.message
});
return null;
} else {
logger.warning(
`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`
);
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
}
} finally {
span.end();
throw err;
default:
// Any other error should be rethrown
throw err;
}
} else {
throw err;
}
}
}
return tokenResponse;
} catch (err) {
const code =
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
span.setStatus({
code,
message: err.message
});
throw err;
} finally {
span.end();
}
}
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
span.setStatus({
code,
message: err.message
});
throw err;
} finally {
span.end();
}
}
// If by this point we don't have a credential, throw an exception so that
// the user knows the credential was not configured appropriately
span.setStatus({ code: CanonicalCode.UNAUTHENTICATED });
span.end();
throw new AuthenticationError(400, {
error: "missing_environment_variables",
error_description: `EnvironmentCredential cannot return a token because one or more of the following environment variables is missing:
${this._environmentVarsMissing.join("\n")}
To authenticate with a service principal AZURE_TENANT_ID, AZURE_CLIENT_ID, and either AZURE_CLIENT_SECRET or AZURE_CLIENT_CERTIFICATE_PATH must be set. To authenticate with a user account AZURE_TENANT_ID, AZURE_USERNAME, and AZURE_PASSWORD must be set.
`
});
}
}
if (statusCode < 200 || statusCode > 504) {
return { code: CanonicalCode.UNKNOWN };
} else if (statusCode >= 200 && statusCode < 400) {
return { code: CanonicalCode.OK };
} else {
switch (statusCode) {
case 400:
return { code: CanonicalCode.INVALID_ARGUMENT };
case 504:
return { code: CanonicalCode.DEADLINE_EXCEEDED };
case 404:
return { code: CanonicalCode.NOT_FOUND };
case 403:
return { code: CanonicalCode.PERMISSION_DENIED };
case 401:
return { code: CanonicalCode.UNAUTHENTICATED };
case 429:
return { code: CanonicalCode.RESOURCE_EXHAUSTED };
case 501:
return { code: CanonicalCode.UNIMPLEMENTED };
case 503:
return { code: CanonicalCode.UNAVAILABLE };
default:
return { code: CanonicalCode.UNKNOWN };
}
}
};
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
}),
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
abortSignal: options && options.abortSignal,
spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
});
const tokenResponse = await this.identityClient.sendTokenRequest(webResource);
return (tokenResponse && tokenResponse.accessToken) || null;
} catch (err) {
const code =
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
span.setStatus({
code,
message: err.message
});
throw err;
} finally {
span.end();
}
}
}
const errors = [];
const { span, options: newOptions } = createSpan("ChainedTokenCredential-getToken", options);
for (let i = 0; i < this._sources.length && token === null; i++) {
try {
token = await this._sources[i].getToken(scopes, newOptions);
} catch (err) {
errors.push(err);
}
}
if (!token && errors.length > 0) {
const err = new AggregateAuthenticationError(errors);
span.setStatus({
code: CanonicalCode.UNAUTHENTICATED,
message: err.message
});
throw err;
}
span.end();
return token;
}
}
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
}),
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
abortSignal: options && options.abortSignal,
spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
});
const tokenResponse = await this.identityClient.sendTokenRequest(webResource);
return (tokenResponse && tokenResponse.accessToken) || null;
} catch (err) {
const code =
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
span.setStatus({
code,
message: err.message
});
throw err;
} finally {
span.end();
}
}
}
scope: typeof scopes === "string" ? scopes : scopes.join(" ")
}),
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
abortSignal: options && options.abortSignal,
spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
});
const tokenResponse = await this.identityClient.sendTokenRequest(webResource);
return (tokenResponse && tokenResponse.accessToken) || null;
} catch (err) {
const code =
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
span.setStatus({
code,
message: err.message
});
throw err;
} finally {
span.end();
}
}
}