UNPKG

@azure/identity

Version:

Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID

159 lines (158 loc) • 5.92 kB
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 msalPlugins_exports = {}; __export(msalPlugins_exports, { hasNativeBroker: () => hasNativeBroker, hasVSCodePlugin: () => hasVSCodePlugin, msalNodeFlowCacheControl: () => msalNodeFlowCacheControl, msalNodeFlowNativeBrokerControl: () => msalNodeFlowNativeBrokerControl, msalNodeFlowVSCodeCredentialControl: () => msalNodeFlowVSCodeCredentialControl, msalPlugins: () => msalPlugins, nativeBrokerInfo: () => nativeBrokerInfo, persistenceProvider: () => persistenceProvider, vsCodeAuthRecordPath: () => vsCodeAuthRecordPath, vsCodeBrokerInfo: () => vsCodeBrokerInfo }); module.exports = __toCommonJS(msalPlugins_exports); var import_constants = require("../../constants.js"); let persistenceProvider = void 0; const msalNodeFlowCacheControl = { setPersistence(pluginProvider) { persistenceProvider = pluginProvider; } }; let nativeBrokerInfo = void 0; let vsCodeAuthRecordPath = void 0; let vsCodeBrokerInfo = void 0; function hasNativeBroker() { return nativeBrokerInfo !== void 0; } function hasVSCodePlugin() { return vsCodeAuthRecordPath !== void 0 && vsCodeBrokerInfo !== void 0; } const msalNodeFlowNativeBrokerControl = { setNativeBroker(broker) { nativeBrokerInfo = { broker }; } }; const msalNodeFlowVSCodeCredentialControl = { setVSCodeAuthRecordPath(path) { vsCodeAuthRecordPath = path; }, setVSCodeBroker(broker) { vsCodeBrokerInfo = { broker }; } }; function generatePluginConfiguration(options) { const config = { cache: {}, broker: { ...options.brokerOptions, isEnabled: options.brokerOptions?.enabled ?? false, enableMsaPassthrough: options.brokerOptions?.legacyEnableMsaPassthrough ?? false } }; if (options.tokenCachePersistenceOptions?.enabled) { if (persistenceProvider === void 0) { throw new Error( [ "Persistent token caching was requested, but no persistence provider was configured.", "You must install the identity-cache-persistence plugin package (`npm install --save @azure/identity-cache-persistence`)", "and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling", "`useIdentityPlugin(cachePersistencePlugin)` before using `tokenCachePersistenceOptions`." ].join(" ") ); } const cacheBaseName = options.tokenCachePersistenceOptions.name || import_constants.DEFAULT_TOKEN_CACHE_NAME; config.cache.cachePlugin = persistenceProvider({ name: `${cacheBaseName}.${import_constants.CACHE_NON_CAE_SUFFIX}`, ...options.tokenCachePersistenceOptions }); config.cache.cachePluginCae = persistenceProvider({ name: `${cacheBaseName}.${import_constants.CACHE_CAE_SUFFIX}`, ...options.tokenCachePersistenceOptions }); } if (options.brokerOptions?.enabled) { config.broker.nativeBrokerPlugin = getBrokerPlugin(options.isVSCodeCredential || false); } return config; } const brokerErrorTemplates = { missing: (credentialName, packageName, pluginVar) => [ `${credentialName} was requested, but no plugin was configured or no authentication record was found.`, `You must install the ${packageName} plugin package (npm install --save ${packageName})`, "and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling", `useIdentityPlugin(${pluginVar}) before using enableBroker.` ].join(" "), unavailable: (credentialName, packageName) => [ `${credentialName} was requested, and the plugin is configured, but the broker is unavailable.`, `Ensure the ${credentialName} plugin is properly installed and configured.`, "Check for missing native dependencies and ensure the package is properly installed.", `See the README for prerequisites on installing and using ${packageName}.` ].join(" ") }; const brokerConfig = { vsCode: { credentialName: "Visual Studio Code Credential", packageName: "@azure/identity-vscode", pluginVar: "vsCodePlugin", get brokerInfo() { return vsCodeBrokerInfo; } }, native: { credentialName: "Broker for WAM", packageName: "@azure/identity-broker", pluginVar: "nativeBrokerPlugin", get brokerInfo() { return nativeBrokerInfo; } } }; function getBrokerPlugin(isVSCodePlugin) { const { credentialName, packageName, pluginVar, brokerInfo } = brokerConfig[isVSCodePlugin ? "vsCode" : "native"]; if (brokerInfo === void 0) { throw new Error(brokerErrorTemplates.missing(credentialName, packageName, pluginVar)); } if (brokerInfo.broker.isBrokerAvailable === false) { throw new Error(brokerErrorTemplates.unavailable(credentialName, packageName)); } return brokerInfo.broker; } const msalPlugins = { generatePluginConfiguration }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { hasNativeBroker, hasVSCodePlugin, msalNodeFlowCacheControl, msalNodeFlowNativeBrokerControl, msalNodeFlowVSCodeCredentialControl, msalPlugins, nativeBrokerInfo, persistenceProvider, vsCodeAuthRecordPath, vsCodeBrokerInfo }); //# sourceMappingURL=msalPlugins.js.map