@azure/identity-cache-persistence
Version:
A secure, persistent token cache for Azure Identity credentials that uses the OS secret-management API
107 lines (106 loc) • 4.53 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var platforms_exports = {};
__export(platforms_exports, {
defaultMsalValues: () => defaultMsalValues,
msalPersistencePlatforms: () => msalPersistencePlatforms
});
module.exports = __toCommonJS(platforms_exports);
var import_node_path = __toESM(require("node:path"));
var import_msal_node_extensions = require("@azure/msal-node-extensions");
const localApplicationDataFolder = process.env.APPDATA?.replace?.(/(.Roaming)*$/, "\\Local") ?? process.env.HOME;
const defaultMsalValues = {
tokenCache: {
name: "msal.cache",
// Expected values:
// - Darwin: '/Users/user/.IdentityService'
// - Windows 8+: 'C:\Users\user\AppData\Local\.IdentityService'
// - Linux: '/home/user/.IdentityService'
directory: import_node_path.default.join(localApplicationDataFolder, ".IdentityService")
},
keyRing: {
label: "MSALCache",
schema: "msal.cache",
collection: "default",
attributes: {
MsalClientID: "Microsoft.Developer.IdentityService",
"Microsoft.Developer.IdentityService": "1.0.0.0"
},
service: "Microsoft.Developer.IdentityService",
account: "MSALCache"
},
keyChain: {
service: "Microsoft.Developer.IdentityService",
account: "MSALCache"
}
};
function getPersistencePath(name) {
return import_node_path.default.join(defaultMsalValues.tokenCache.directory, name);
}
const msalPersistencePlatforms = {
win32: ({ name = defaultMsalValues.tokenCache.name } = {}) => import_msal_node_extensions.FilePersistenceWithDataProtection.create(
getPersistencePath(name),
import_msal_node_extensions.DataProtectionScope.CurrentUser
),
darwin: async (options = {}) => {
const { name, unsafeAllowUnencryptedStorage } = options;
const { service, account } = defaultMsalValues.keyChain;
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
try {
const persistence = await import_msal_node_extensions.KeychainPersistence.create(persistencePath, service, account);
await persistence.load();
return persistence;
} catch (e) {
if (!unsafeAllowUnencryptedStorage) {
throw new Error("Unable to read from the macOS Keychain.");
}
return import_msal_node_extensions.FilePersistence.create(persistencePath);
}
},
linux: async (options = {}) => {
const { name, unsafeAllowUnencryptedStorage } = options;
const { service, account } = defaultMsalValues.keyRing;
const persistencePath = getPersistencePath(name || defaultMsalValues.tokenCache.name);
try {
const persistence = await import_msal_node_extensions.LibSecretPersistence.create(persistencePath, service, account);
await persistence.load();
return persistence;
} catch (e) {
if (!unsafeAllowUnencryptedStorage) {
throw new Error("Unable to read from the system keyring (libsecret).");
}
return import_msal_node_extensions.FilePersistence.create(persistencePath);
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defaultMsalValues,
msalPersistencePlatforms
});
//# sourceMappingURL=platforms.js.map