Add extracted source directory and README navigation

This commit is contained in:
Shawn Bot
2026-03-31 14:56:06 +00:00
parent 6252bb6eb5
commit 91e01d755b
4757 changed files with 984951 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export function getIdentityTokenEndpointSuffix(tenantId) {
if (tenantId === "adfs") {
return "oauth2/token";
}
else {
return "oauth2/v2.0/token";
}
}
//# sourceMappingURL=identityTokenEndpoint.js.map

View File

@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createClientLogger } from "@azure/logger";
/**
* The AzureLogger used for all clients within the identity package
*/
export const logger = createClientLogger("identity");
/**
* Separates a list of environment variable names into a plain object with two arrays: an array of missing environment variables and another array with assigned environment variables.
* @param supportedEnvVars - List of environment variable names
*/
export function processEnvVars(supportedEnvVars) {
return supportedEnvVars.reduce((acc, envVariable) => {
if (process.env[envVariable]) {
acc.assigned.push(envVariable);
}
else {
acc.missing.push(envVariable);
}
return acc;
}, { missing: [], assigned: [] });
}
/**
* Based on a given list of environment variable names,
* logs the environment variables currently assigned during the usage of a credential that goes by the given name.
* @param credentialName - Name of the credential in use
* @param supportedEnvVars - List of environment variables supported by that credential
*/
export function logEnvVars(credentialName, supportedEnvVars) {
const { assigned } = processEnvVars(supportedEnvVars);
logger.info(`${credentialName} => Found the following environment variables: ${assigned.join(", ")}`);
}
/**
* Formatting the success event on the credentials
*/
export function formatSuccess(scope) {
return `SUCCESS. Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
}
/**
* Formatting the success event on the credentials
*/
export function formatError(scope, error) {
let message = "ERROR.";
if (scope === null || scope === void 0 ? void 0 : scope.length) {
message += ` Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
}
return `${message} Error message: ${typeof error === "string" ? error : error.message}.`;
}
/**
* Generates a CredentialLoggerInstance.
*
* It logs with the format:
*
* `[title] => [message]`
*
*/
export function credentialLoggerInstance(title, parent, log = logger) {
const fullTitle = parent ? `${parent.fullTitle} ${title}` : title;
function info(message) {
log.info(`${fullTitle} =>`, message);
}
function warning(message) {
log.warning(`${fullTitle} =>`, message);
}
function verbose(message) {
log.verbose(`${fullTitle} =>`, message);
}
function error(message) {
log.error(`${fullTitle} =>`, message);
}
return {
title,
fullTitle,
info,
warning,
verbose,
error,
};
}
/**
* Generates a CredentialLogger, which is a logger declared at the credential's constructor, and used at any point in the credential.
* It has all the properties of a CredentialLoggerInstance, plus other logger instances, one per method.
*
* It logs with the format:
*
* `[title] => [message]`
* `[title] => getToken() => [message]`
*
*/
export function credentialLogger(title, log = logger) {
const credLogger = credentialLoggerInstance(title, undefined, log);
return Object.assign(Object.assign({}, credLogger), { parent: log, getToken: credentialLoggerInstance("=> getToken()", credLogger, log) });
}
//# sourceMappingURL=logging.js.map

View File

@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { CredentialUnavailableError } from "../errors.js";
function createConfigurationErrorMessage(tenantId) {
return `The current credential is not configured to acquire tokens for tenant ${tenantId}. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to AdditionallyAllowedTenants to allow acquiring tokens for any tenant.`;
}
/**
* Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
* unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
* or unless the original tenant Id is `adfs`.
* @internal
*/
export function processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowedTenantIds = [], logger) {
var _a;
let resolvedTenantId;
if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
resolvedTenantId = tenantId;
}
else if (tenantId === "adfs") {
resolvedTenantId = tenantId;
}
else {
resolvedTenantId = (_a = getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId) !== null && _a !== void 0 ? _a : tenantId;
}
if (tenantId &&
resolvedTenantId !== tenantId &&
!additionallyAllowedTenantIds.includes("*") &&
!additionallyAllowedTenantIds.some((t) => t.localeCompare(resolvedTenantId) === 0)) {
const message = createConfigurationErrorMessage(resolvedTenantId);
logger === null || logger === void 0 ? void 0 : logger.info(message);
throw new CredentialUnavailableError(message);
}
return resolvedTenantId;
}
//# sourceMappingURL=processMultiTenantRequest.js.map

View File

@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import * as childProcess from "child_process";
/**
* Easy to mock childProcess utils.
* @internal
*/
export const processUtils = {
/**
* Promisifying childProcess.execFile
* @internal
*/
execFile(file, params, options) {
return new Promise((resolve, reject) => {
childProcess.execFile(file, params, options, (error, stdout, stderr) => {
if (Buffer.isBuffer(stdout)) {
stdout = stdout.toString("utf8");
}
if (Buffer.isBuffer(stderr)) {
stderr = stderr.toString("utf8");
}
if (stderr || error) {
reject(stderr ? new Error(stderr) : error);
}
else {
resolve(stdout);
}
});
});
},
};
//# sourceMappingURL=processUtils.js.map

View File

@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { formatError } from "./logging.js";
/**
* Ensures the scopes value is an array.
* @internal
*/
export function ensureScopes(scopes) {
return Array.isArray(scopes) ? scopes : [scopes];
}
/**
* Throws if the received scope is not valid.
* @internal
*/
export function ensureValidScopeForDevTimeCreds(scope, logger) {
if (!scope.match(/^[0-9a-zA-Z-_.:/]+$/)) {
const error = new Error("Invalid scope was specified by the user or calling client");
logger.getToken.info(formatError(scope, error));
throw error;
}
}
/**
* Returns the resource out of a scope.
* @internal
*/
export function getScopeResource(scope) {
return scope.replace(/\/.default$/, "");
}
//# sourceMappingURL=scopeUtils.js.map

View File

@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { formatError } from "./logging.js";
/**
* @internal
*/
export function checkSubscription(logger, subscription) {
if (!subscription.match(/^[0-9a-zA-Z-._ ]+$/)) {
const error = new Error("Invalid subscription provided. You can locate your subscription by following the instructions listed here: https://learn.microsoft.com/azure/azure-portal/get-subscription-tenant-id.");
logger.info(formatError("", error));
throw error;
}
}
//# sourceMappingURL=subscriptionUtils.js.map

View File

@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { ALL_TENANTS, DeveloperSignOnClientId } from "../constants.js";
import { formatError } from "./logging.js";
export { processMultiTenantRequest } from "./processMultiTenantRequest.js";
/**
* @internal
*/
export function checkTenantId(logger, tenantId) {
if (!tenantId.match(/^[0-9a-zA-Z-.]+$/)) {
const error = new Error("Invalid tenant id provided. You can locate your tenant id by following the instructions listed here: https://learn.microsoft.com/partner-center/find-ids-and-domain-names.");
logger.info(formatError("", error));
throw error;
}
}
/**
* @internal
*/
export function resolveTenantId(logger, tenantId, clientId) {
if (tenantId) {
checkTenantId(logger, tenantId);
return tenantId;
}
if (!clientId) {
clientId = DeveloperSignOnClientId;
}
if (clientId !== DeveloperSignOnClientId) {
return "common";
}
return "organizations";
}
/**
* @internal
*/
export function resolveAdditionallyAllowedTenantIds(additionallyAllowedTenants) {
if (!additionallyAllowedTenants || additionallyAllowedTenants.length === 0) {
return [];
}
if (additionallyAllowedTenants.includes("*")) {
return ALL_TENANTS;
}
return additionallyAllowedTenants;
}
//# sourceMappingURL=tenantIdUtils.js.map

View File

@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { SDK_VERSION } from "../constants.js";
import { createTracingClient } from "@azure/core-tracing";
/**
* Creates a span using the global tracer.
* @internal
*/
export const tracingClient = createTracingClient({
namespace: "Microsoft.AAD",
packageName: "@azure/identity",
packageVersion: SDK_VERSION,
});
//# sourceMappingURL=tracing.js.map