@azure/identity
Version:
Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID
146 lines (143 loc) • 4.99 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var errors_exports = {};
__export(errors_exports, {
AggregateAuthenticationError: () => AggregateAuthenticationError,
AggregateAuthenticationErrorName: () => AggregateAuthenticationErrorName,
AuthenticationError: () => AuthenticationError,
AuthenticationErrorName: () => AuthenticationErrorName,
AuthenticationRequiredError: () => AuthenticationRequiredError,
CredentialUnavailableError: () => CredentialUnavailableError,
CredentialUnavailableErrorName: () => CredentialUnavailableErrorName
});
module.exports = __toCommonJS(errors_exports);
function isErrorResponse(errorResponse) {
return errorResponse && typeof errorResponse.error === "string" && typeof errorResponse.error_description === "string";
}
const CredentialUnavailableErrorName = "CredentialUnavailableError";
class CredentialUnavailableError extends Error {
constructor(message, options) {
super(message, options);
this.name = CredentialUnavailableErrorName;
}
}
const AuthenticationErrorName = "AuthenticationError";
class AuthenticationError extends Error {
/**
* The HTTP status code returned from the authentication request.
*/
statusCode;
/**
* The error response details.
*/
errorResponse;
constructor(statusCode, errorBody, options) {
let errorResponse = {
error: "unknown",
errorDescription: "An unknown error occurred and no additional details are available."
};
if (isErrorResponse(errorBody)) {
errorResponse = convertOAuthErrorResponseToErrorResponse(errorBody);
} else if (typeof errorBody === "string") {
try {
const oauthErrorResponse = JSON.parse(errorBody);
errorResponse = convertOAuthErrorResponseToErrorResponse(oauthErrorResponse);
} catch (e) {
if (statusCode === 400) {
errorResponse = {
error: "invalid_request",
errorDescription: `The service indicated that the request was invalid.
${errorBody}`
};
} else {
errorResponse = {
error: "unknown_error",
errorDescription: `An unknown error has occurred. Response body:
${errorBody}`
};
}
}
} else {
errorResponse = {
error: "unknown_error",
errorDescription: "An unknown error occurred and no additional details are available."
};
}
super(
`${errorResponse.error} Status code: ${statusCode}
More details:
${errorResponse.errorDescription},`,
options
);
this.statusCode = statusCode;
this.errorResponse = errorResponse;
this.name = AuthenticationErrorName;
}
}
const AggregateAuthenticationErrorName = "AggregateAuthenticationError";
class AggregateAuthenticationError extends Error {
/**
* The array of error objects that were thrown while trying to authenticate
* with the credentials in a {@link ChainedTokenCredential}.
*/
errors;
constructor(errors, errorMessage) {
const errorDetail = errors.join("\n");
super(`${errorMessage}
${errorDetail}`);
this.errors = errors;
this.name = AggregateAuthenticationErrorName;
}
}
function convertOAuthErrorResponseToErrorResponse(errorBody) {
return {
error: errorBody.error,
errorDescription: errorBody.error_description,
correlationId: errorBody.correlation_id,
errorCodes: errorBody.error_codes,
timestamp: errorBody.timestamp,
traceId: errorBody.trace_id
};
}
class AuthenticationRequiredError extends Error {
/**
* The list of scopes for which the token will have access.
*/
scopes;
/**
* The options passed to the getToken request.
*/
getTokenOptions;
constructor(options) {
super(options.message, options.cause ? { cause: options.cause } : void 0);
this.scopes = options.scopes;
this.getTokenOptions = options.getTokenOptions;
this.name = "AuthenticationRequiredError";
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AggregateAuthenticationError,
AggregateAuthenticationErrorName,
AuthenticationError,
AuthenticationErrorName,
AuthenticationRequiredError,
CredentialUnavailableError,
CredentialUnavailableErrorName
});
//# sourceMappingURL=errors.js.map