push neon reactor

This commit is contained in:
2026-07-12 15:11:38 +02:00
parent 172e72dbcd
commit aeab5f7820
9597 changed files with 2407488 additions and 0 deletions
@@ -0,0 +1,5 @@
import { IPersistence } from "./IPersistence.js";
export declare abstract class BasePersistence {
abstract createForPersistenceValidation(): Promise<IPersistence>;
verifyPersistence(): Promise<boolean>;
}
@@ -0,0 +1,36 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import { PersistenceError } from '../error/PersistenceError.mjs';
import { Constants } from '../utils/Constants.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
class BasePersistence {
async verifyPersistence() {
// We are using a different location for the test to avoid overriding the functional cache
const persistenceValidator = await this.createForPersistenceValidation();
try {
await persistenceValidator.save(Constants.PERSISTENCE_TEST_DATA);
const retrievedDummyData = await persistenceValidator.load();
if (!retrievedDummyData) {
throw PersistenceError.createCachePersistenceError("Persistence check failed. Data was written but it could not be read. " +
"Possible cause: on Linux, LibSecret is installed but D-Bus isn't running \
because it cannot be started over SSH.");
}
if (retrievedDummyData !== Constants.PERSISTENCE_TEST_DATA) {
throw PersistenceError.createCachePersistenceError(`Persistence check failed. Data written ${Constants.PERSISTENCE_TEST_DATA} is different \
from data read ${retrievedDummyData}`);
}
await persistenceValidator.delete();
return true;
}
catch (e) {
throw PersistenceError.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`);
}
}
}
export { BasePersistence };
//# sourceMappingURL=BasePersistence.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"BasePersistence.mjs","sources":["../../src/persistence/BasePersistence.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;MAMmB,eAAe,CAAA;AAG1B,IAAA,MAAM,iBAAiB,GAAA;;AAE1B,QAAA,MAAM,oBAAoB,GACtB,MAAM,IAAI,CAAC,8BAA8B,EAAE,CAAC;QAEhD,IAAI;YACA,MAAM,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEjE,YAAA,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,IAAI,EAAE,CAAC;YAE7D,IAAI,CAAC,kBAAkB,EAAE;AACrB,gBAAA,MAAM,gBAAgB,CAAC,2BAA2B,CAC9C,uEAAuE;AACnE,oBAAA;AACmC,2DAAA,CAC1C,CAAC;AACL,aAAA;AAED,YAAA,IAAI,kBAAkB,KAAK,SAAS,CAAC,qBAAqB,EAAE;AACxD,gBAAA,MAAM,gBAAgB,CAAC,2BAA2B,CAC9C,CAA0C,uCAAA,EAAA,SAAS,CAAC,qBAAqB,CAAA;qCACxD,kBAAkB,CAAA,CAAE,CACxC,CAAC;AACL,aAAA;AACD,YAAA,MAAM,oBAAoB,CAAC,MAAM,EAAE,CAAC;AACpC,YAAA,OAAO,IAAI,CAAC;AACf,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;YACR,MAAM,gBAAgB,CAAC,2BAA2B,CAC9C,+CAA+C,CAAC,CAAA,CAAE,CACrD,CAAC;AACL,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,16 @@
/**
* Specifies the scope of the data protection - either the current user or the local
* machine.
*
* You do not need a key to protect or unprotect the data.
* If you set the Scope to CurrentUser, only applications running on your credentials can
* unprotect the data; however, that means that any application running on your credentials
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
* application on the computer can unprotect, access, and modify the data.
*
*/
export declare const DataProtectionScope: {
readonly CurrentUser: "CurrentUser";
readonly LocalMachine: "LocalMachine";
};
export type DataProtectionScope = (typeof DataProtectionScope)[keyof typeof DataProtectionScope];
@@ -0,0 +1,24 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Specifies the scope of the data protection - either the current user or the local
* machine.
*
* You do not need a key to protect or unprotect the data.
* If you set the Scope to CurrentUser, only applications running on your credentials can
* unprotect the data; however, that means that any application running on your credentials
* can access the protected data. If you set the Scope to LocalMachine, any full-trust
* application on the computer can unprotect, access, and modify the data.
*
*/
const DataProtectionScope = {
CurrentUser: "CurrentUser",
LocalMachine: "LocalMachine",
};
export { DataProtectionScope };
//# sourceMappingURL=DataProtectionScope.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"DataProtectionScope.mjs","sources":["../../src/persistence/DataProtectionScope.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;AAEH;;;;;;;;;;AAUG;AACU,MAAA,mBAAmB,GAAG;AAC/B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,YAAY,EAAE,cAAc;;;;;"}
@@ -0,0 +1,29 @@
import { IPersistence } from "./IPersistence.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { BasePersistence } from "./BasePersistence.js";
/**
* Reads and writes data to file specified by file location. File contents are not
* encrypted.
*
* If file or directory has not been created, it FilePersistence.create() will create
* file and any directories in the path recursively.
*/
export declare class FilePersistence extends BasePersistence implements IPersistence {
private filePath;
private logger;
private constructor();
static create(fileLocation: string, loggerOptions?: LoggerOptions): Promise<FilePersistence>;
save(contents: string): Promise<void>;
saveBuffer(contents: Uint8Array): Promise<void>;
load(): Promise<string | null>;
loadBuffer(): Promise<Uint8Array>;
delete(): Promise<boolean>;
getFilePath(): string;
reloadNecessary(lastSync: number): Promise<boolean>;
getLogger(): Logger;
createForPersistenceValidation(): Promise<FilePersistence>;
private static createDefaultLoggerOptions;
private timeLastModified;
private createCacheFile;
private createFileDirectory;
}
@@ -0,0 +1,173 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import { promises } from 'fs';
import { dirname } from 'path';
import { ErrorCodes, Constants } from '../utils/Constants.mjs';
import { PersistenceError } from '../error/PersistenceError.mjs';
import { BasePersistence } from './BasePersistence.mjs';
import { isNodeError } from '../utils/TypeGuards.mjs';
import { Logger, LogLevel } from '../lib/msal-common/dist/logger/Logger.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Reads and writes data to file specified by file location. File contents are not
* encrypted.
*
* If file or directory has not been created, it FilePersistence.create() will create
* file and any directories in the path recursively.
*/
class FilePersistence extends BasePersistence {
constructor(fileLocation, loggerOptions) {
super();
this.logger = new Logger(loggerOptions || FilePersistence.createDefaultLoggerOptions());
this.filePath = fileLocation;
}
static async create(fileLocation, loggerOptions) {
const filePersistence = new FilePersistence(fileLocation, loggerOptions);
await filePersistence.createCacheFile();
return filePersistence;
}
async save(contents) {
try {
await promises.writeFile(this.getFilePath(), contents, "utf-8");
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
else {
throw err;
}
}
}
async saveBuffer(contents) {
try {
await promises.writeFile(this.getFilePath(), contents);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
else {
throw err;
}
}
}
async load() {
try {
return await promises.readFile(this.getFilePath(), "utf-8");
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
else {
throw err;
}
}
}
async loadBuffer() {
try {
return await promises.readFile(this.getFilePath());
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
else {
throw err;
}
}
}
async delete() {
try {
await promises.unlink(this.getFilePath());
return true;
}
catch (err) {
if (isNodeError(err)) {
if (err.code === Constants.ENOENT_ERROR) {
// file does not exist, so it was not deleted
this.logger.warning("Cache file does not exist, so it could not be deleted");
return false;
}
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
else {
throw err;
}
}
}
getFilePath() {
return this.filePath;
}
async reloadNecessary(lastSync) {
return lastSync < (await this.timeLastModified());
}
getLogger() {
return this.logger;
}
createForPersistenceValidation() {
const testCacheFileLocation = `${dirname(this.filePath)}/test.cache`;
return FilePersistence.create(testCacheFileLocation);
}
static createDefaultLoggerOptions() {
return {
loggerCallback: () => {
// allow users to not set loggerCallback
},
piiLoggingEnabled: false,
logLevel: LogLevel.Info,
};
}
async timeLastModified() {
try {
const stats = await promises.stat(this.filePath);
return stats.mtime.getTime();
}
catch (err) {
if (isNodeError(err)) {
if (err.code === Constants.ENOENT_ERROR) {
// file does not exist, so it's never been modified
this.logger.verbose("Cache file does not exist");
return 0;
}
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
else {
throw err;
}
}
}
async createCacheFile() {
await this.createFileDirectory();
// File is created only if it does not exist
const fileHandle = await promises.open(this.filePath, "a");
await fileHandle.close();
this.logger.info(`File created at ${this.filePath}`);
}
async createFileDirectory() {
try {
await promises.mkdir(dirname(this.filePath), { recursive: true });
}
catch (err) {
if (isNodeError(err)) {
if (err.code === Constants.EEXIST_ERROR) {
this.logger.info(`Directory ${dirname(this.filePath)} already exists`);
}
else {
throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
}
}
else {
throw err;
}
}
}
}
export { FilePersistence };
//# sourceMappingURL=FilePersistence.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"FilePersistence.mjs","sources":["../../src/persistence/FilePersistence.ts"],"sourcesContent":[null],"names":["fs"],"mappings":";;;;;;;;;;AAAA;;;AAGG;AAWH;;;;;;AAMG;AACG,MAAO,eAAgB,SAAQ,eAAe,CAAA;IAIhD,WAAoB,CAAA,YAAoB,EAAE,aAA6B,EAAA;AACnE,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACpB,aAAa,IAAI,eAAe,CAAC,0BAA0B,EAAE,CAChE,CAAC;AACF,QAAA,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;KAChC;AAEM,IAAA,aAAa,MAAM,CACtB,YAAoB,EACpB,aAA6B,EAAA;QAE7B,MAAM,eAAe,GAAG,IAAI,eAAe,CACvC,YAAY,EAC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AC;AACb,aAAA;AACJ,SAAA;KACJ;AAEO,IAAA,MAAM,eAAe,GAAA;AACzB,QAAA,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;;AAEjC,QAAA,MAAM,UAAU,GAAG,MAAMA,QAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACrD,QAAA,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAmB,gBAAA,EAAA,IAAI,CAAC,QAAQ,CAAE,CAAA,CAAC,CAAC;KACxD;AAEO,IAAA,MAAM,mBAAmB,GAAA;QAC7B,IAAI;AACA,YAAA,MAAMA,QAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/D,SAAA;AAAC,QAAA,OAAO,GAAG,EAAE;AACV,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;AAClB,gBAAA,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,YAAY,EAAE;AACrC,oBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,CAAa,UAAA,EAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA,gBAAA,CAAkB,CACxD,CAAC;AACL,iBAAA;AAAM,qBAAA;AACH,oBAAA,MAAM,gBAAgB,CAAC,qBAAqB,CACxC,GAAG,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAC9B,GAAG,CAAC,OAAO,CACd,CAAC;AACL,iBAAA;AACJ,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,24 @@
import { IPersistence } from "./IPersistence.js";
import { DataProtectionScope } from "./DataProtectionScope.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { BasePersistence } from "./BasePersistence.js";
/**
* Uses CryptProtectData and CryptUnprotectData on Windows to encrypt and decrypt file contents.
*
* scope: Scope of the data protection. Either local user or the current machine
* optionalEntropy: Password or other additional entropy used to encrypt the data
*/
export declare class FilePersistenceWithDataProtection extends BasePersistence implements IPersistence {
private filePersistence;
private scope;
private optionalEntropy;
private constructor();
static create(fileLocation: string, scope: DataProtectionScope, optionalEntropy?: string, loggerOptions?: LoggerOptions): Promise<FilePersistenceWithDataProtection>;
save(contents: string): Promise<void>;
load(): Promise<string | null>;
delete(): Promise<boolean>;
reloadNecessary(lastSync: number): Promise<boolean>;
getFilePath(): string;
getLogger(): Logger;
createForPersistenceValidation(): Promise<FilePersistenceWithDataProtection>;
}
@@ -0,0 +1,90 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import { FilePersistence } from './FilePersistence.mjs';
import { PersistenceError } from '../error/PersistenceError.mjs';
import { Dpapi } from '../Dpapi.mjs';
import { DataProtectionScope } from './DataProtectionScope.mjs';
import { dirname } from 'path';
import { BasePersistence } from './BasePersistence.mjs';
import { isNodeError } from '../utils/TypeGuards.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Uses CryptProtectData and CryptUnprotectData on Windows to encrypt and decrypt file contents.
*
* scope: Scope of the data protection. Either local user or the current machine
* optionalEntropy: Password or other additional entropy used to encrypt the data
*/
class FilePersistenceWithDataProtection extends BasePersistence {
constructor(filePersistence, scope, optionalEntropy) {
super();
this.scope = scope;
this.optionalEntropy = optionalEntropy
? Buffer.from(optionalEntropy, "utf-8")
: null;
this.filePersistence = filePersistence;
}
static async create(fileLocation, scope, optionalEntropy, loggerOptions) {
const filePersistence = await FilePersistence.create(fileLocation, loggerOptions);
const persistence = new FilePersistenceWithDataProtection(filePersistence, scope, optionalEntropy);
return persistence;
}
async save(contents) {
try {
const encryptedContents = Dpapi.protectData(Buffer.from(contents, "utf-8"), this.optionalEntropy, this.scope.toString());
await this.filePersistence.saveBuffer(encryptedContents);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createFilePersistenceWithDPAPIError(err.message);
}
else {
throw err;
}
}
}
async load() {
try {
const encryptedContents = await this.filePersistence.loadBuffer();
if (typeof encryptedContents === "undefined" ||
!encryptedContents ||
0 === encryptedContents.length) {
this.filePersistence
.getLogger()
.info("Encrypted contents loaded from file were null or empty");
return null;
}
return Dpapi.unprotectData(encryptedContents, this.optionalEntropy, this.scope.toString()).toString();
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createFilePersistenceWithDPAPIError(err.message);
}
else {
throw err;
}
}
}
async delete() {
return this.filePersistence.delete();
}
async reloadNecessary(lastSync) {
return this.filePersistence.reloadNecessary(lastSync);
}
getFilePath() {
return this.filePersistence.getFilePath();
}
getLogger() {
return this.filePersistence.getLogger();
}
createForPersistenceValidation() {
const testCacheFileLocation = `${dirname(this.filePersistence.getFilePath())}/test.cache`;
return FilePersistenceWithDataProtection.create(testCacheFileLocation, DataProtectionScope.CurrentUser);
}
}
export { FilePersistenceWithDataProtection };
//# sourceMappingURL=FilePersistenceWithDataProtection.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"FilePersistenceWithDataProtection.mjs","sources":["../../src/persistence/FilePersistenceWithDataProtection.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAAA;;;AAGG;AAYH;;;;;AAKG;AACG,MAAO,iCACT,SAAQ,eAAe,CAAA;AAOvB,IAAA,WAAA,CACI,eAAgC,EAChC,KAA0B,EAC1B,eAAwB,EAAA;AAExB,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,eAAe,GAAG,eAAe;cAChC,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC;cACrC,IAAI,CAAC;AACX,QAAA,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;KAC1C;IAEM,aAAa,MAAM,CACtB,YAAoB,EACpB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AAC,KAAK,CAAC,QAAQ,EAAE,CACxB,CAAC,QAAQ,EAAE,CAAC;AAChB,SAAA;AAAC,QAAA,OAAO,GAAG,EAAE;AACV,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;gBAClB,MAAM,gBAAgB,CAAC,mCAAmC,CACtD,GAAG,CAAC,OAAO,CACd,CAAC;AACL,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;AAEM,IAAA,MAAM,MAAM,GAAA;AACf,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;KACxC;IAEM,MAAM,eAAe,CAAC,QAAgB,EAAA;QACzC,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;KACzD;IAEM,WAAW,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;KAC7C;IAEM,SAAS,GAAA;AACZ,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;KAC3C;IAEM,8BAA8B,GAAA;AACjC,QAAA,MAAM,qBAAqB,GAAG,CAAG,EAAA,OAAO,CACpC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CACrC,aAAa,CAAC;QACf,OAAO,iCAAiC,CAAC,MAAM,CAC3C,qBAAqB,EACrB,mBAAmB,CAAC,WAAW,CAClC,CAAC;KACL;AACJ;;;;"}
@@ -0,0 +1,11 @@
import { Logger } from "@azure/msal-common/node";
export interface IPersistence {
save(contents: string): Promise<void>;
load(): Promise<string | null>;
delete(): Promise<boolean>;
reloadNecessary(lastSync: number): Promise<boolean>;
getFilePath(): string;
getLogger(): Logger;
verifyPersistence(): Promise<boolean>;
createForPersistenceValidation(): Promise<IPersistence>;
}
@@ -0,0 +1,10 @@
import type { LoggerOptions } from "@azure/msal-common/node";
import { DataProtectionScope } from "./DataProtectionScope.js";
export interface IPersistenceConfiguration {
cachePath?: string;
dataProtectionScope?: DataProtectionScope;
serviceName?: string;
accountName?: string;
usePlaintextFileOnLinux?: boolean;
loggerOptions?: LoggerOptions;
}
@@ -0,0 +1,23 @@
import { IPersistence } from "./IPersistence.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { BasePersistence } from "./BasePersistence.js";
/**
* Uses reads and writes passwords to macOS keychain
*
* serviceName: Identifier used as key for whatever value is stored
* accountName: Account under which password should be stored
*/
export declare class KeychainPersistence extends BasePersistence implements IPersistence {
protected readonly serviceName: string;
protected readonly accountName: string;
private filePersistence;
private constructor();
static create(fileLocation: string, serviceName: string, accountName: string, loggerOptions?: LoggerOptions): Promise<KeychainPersistence>;
save(contents: string): Promise<void>;
load(): Promise<string | null>;
delete(): Promise<boolean>;
reloadNecessary(lastSync: number): Promise<boolean>;
getFilePath(): string;
getLogger(): Logger;
createForPersistenceValidation(): Promise<KeychainPersistence>;
}
@@ -0,0 +1,90 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import keytar from 'keytar';
import { FilePersistence } from './FilePersistence.mjs';
import { PersistenceError } from '../error/PersistenceError.mjs';
import { dirname } from 'path';
import { BasePersistence } from './BasePersistence.mjs';
import { isNodeError } from '../utils/TypeGuards.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Uses reads and writes passwords to macOS keychain
*
* serviceName: Identifier used as key for whatever value is stored
* accountName: Account under which password should be stored
*/
class KeychainPersistence extends BasePersistence {
constructor(filePersistence, serviceName, accountName) {
super();
this.filePersistence = filePersistence;
this.serviceName = serviceName;
this.accountName = accountName;
}
static async create(fileLocation, serviceName, accountName, loggerOptions) {
const filePersistence = await FilePersistence.create(fileLocation, loggerOptions);
const persistence = new KeychainPersistence(filePersistence, serviceName, accountName);
return persistence;
}
async save(contents) {
try {
await keytar.setPassword(this.serviceName, this.accountName, contents);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createKeychainPersistenceError(err.message);
}
else {
throw err;
}
}
// Write dummy data to update file mtime
await this.filePersistence.save("{}");
}
async load() {
try {
return await keytar.getPassword(this.serviceName, this.accountName);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createKeychainPersistenceError(err.message);
}
else {
throw err;
}
}
}
async delete() {
try {
await this.filePersistence.delete();
return await keytar.deletePassword(this.serviceName, this.accountName);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createKeychainPersistenceError(err.message);
}
else {
throw err;
}
}
}
async reloadNecessary(lastSync) {
return this.filePersistence.reloadNecessary(lastSync);
}
getFilePath() {
return this.filePersistence.getFilePath();
}
getLogger() {
return this.filePersistence.getLogger();
}
createForPersistenceValidation() {
const testCacheFileLocation = `${dirname(this.filePersistence.getFilePath())}/test.cache`;
return KeychainPersistence.create(testCacheFileLocation, "persistenceValidationServiceName", "persistencValidationAccountName");
}
}
export { KeychainPersistence };
//# sourceMappingURL=KeychainPersistence.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"KeychainPersistence.mjs","sources":["../../src/persistence/KeychainPersistence.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAAA;;;AAGG;AAWH;;;;;AAKG;AACG,MAAO,mBACT,SAAQ,eAAe,CAAA;AAOvB,IAAA,WAAA,CACI,eAAgC,EAChC,WAAmB,EACnB,WAAmB,EAAA;AAEnB,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;AACvC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;AAC/B,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;KAClC;IAEM,aAAa,MAAM,CACtB,YAAoB,EACpB,WAAmB,EACnB,WAAmB,EACnB,aAA6B,EAAA;QAE7B,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,MAAM,CAChD,YAAY,EACZ,aAAa,CAChB,CAAC;QACF,MAAM,WAAW,GAAG,IAAI,mBAAmB,CACvC,eAAe,EACf,W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BAA8B,CACjD,GAAG,CAAC,OAAO,CACd,CAAC;AACL,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;IAEM,MAAM,eAAe,CAAC,QAAgB,EAAA;QACzC,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;KACzD;IAEM,WAAW,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;KAC7C;IAEM,SAAS,GAAA;AACZ,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;KAC3C;IAEM,8BAA8B,GAAA;AACjC,QAAA,MAAM,qBAAqB,GAAG,CAAG,EAAA,OAAO,CACpC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CACrC,aAAa,CAAC;QACf,OAAO,mBAAmB,CAAC,MAAM,CAC7B,qBAAqB,EACrB,kCAAkC,EAClC,iCAAiC,CACpC,CAAC;KACL;AACJ;;;;"}
@@ -0,0 +1,24 @@
import { IPersistence } from "./IPersistence.js";
import { Logger, LoggerOptions } from "@azure/msal-common/node";
import { BasePersistence } from "./BasePersistence.js";
/**
* Uses reads and writes passwords to Secret Service API/libsecret. Requires libsecret
* to be installed.
*
* serviceName: Identifier used as key for whatever value is stored
* accountName: Account under which password should be stored
*/
export declare class LibSecretPersistence extends BasePersistence implements IPersistence {
protected readonly serviceName: string;
protected readonly accountName: string;
private filePersistence;
private constructor();
static create(fileLocation: string, serviceName: string, accountName: string, loggerOptions?: LoggerOptions): Promise<LibSecretPersistence>;
save(contents: string): Promise<void>;
load(): Promise<string | null>;
delete(): Promise<boolean>;
reloadNecessary(lastSync: number): Promise<boolean>;
getFilePath(): string;
getLogger(): Logger;
createForPersistenceValidation(): Promise<LibSecretPersistence>;
}
@@ -0,0 +1,91 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import keytar from 'keytar';
import { FilePersistence } from './FilePersistence.mjs';
import { PersistenceError } from '../error/PersistenceError.mjs';
import { dirname } from 'path';
import { BasePersistence } from './BasePersistence.mjs';
import { isNodeError } from '../utils/TypeGuards.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Uses reads and writes passwords to Secret Service API/libsecret. Requires libsecret
* to be installed.
*
* serviceName: Identifier used as key for whatever value is stored
* accountName: Account under which password should be stored
*/
class LibSecretPersistence extends BasePersistence {
constructor(filePersistence, serviceName, accountName) {
super();
this.filePersistence = filePersistence;
this.serviceName = serviceName;
this.accountName = accountName;
}
static async create(fileLocation, serviceName, accountName, loggerOptions) {
const filePersistence = await FilePersistence.create(fileLocation, loggerOptions);
const persistence = new LibSecretPersistence(filePersistence, serviceName, accountName);
return persistence;
}
async save(contents) {
try {
await keytar.setPassword(this.serviceName, this.accountName, contents);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createLibSecretError(err.message);
}
else {
throw err;
}
}
// Write dummy data to update file mtime
await this.filePersistence.save("{}");
}
async load() {
try {
return await keytar.getPassword(this.serviceName, this.accountName);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createLibSecretError(err.message);
}
else {
throw err;
}
}
}
async delete() {
try {
await this.filePersistence.delete();
return await keytar.deletePassword(this.serviceName, this.accountName);
}
catch (err) {
if (isNodeError(err)) {
throw PersistenceError.createLibSecretError(err.message);
}
else {
throw err;
}
}
}
async reloadNecessary(lastSync) {
return this.filePersistence.reloadNecessary(lastSync);
}
getFilePath() {
return this.filePersistence.getFilePath();
}
getLogger() {
return this.filePersistence.getLogger();
}
createForPersistenceValidation() {
const testCacheFileLocation = `${dirname(this.filePersistence.getFilePath())}/test.cache`;
return LibSecretPersistence.create(testCacheFileLocation, "persistenceValidationServiceName", "persistencValidationAccountName");
}
}
export { LibSecretPersistence };
//# sourceMappingURL=LibSecretPersistence.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"LibSecretPersistence.mjs","sources":["../../src/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J;;;;"}
@@ -0,0 +1,38 @@
import { IPersistence } from "./IPersistence.js";
import { CrossPlatformLockOptions } from "../lock/CrossPlatformLockOptions.js";
import { TokenCacheContext, ICachePlugin } from "@azure/msal-common/node";
/**
* MSAL cache plugin which enables callers to write the MSAL cache to disk on Windows,
* macOs, and Linux.
*
* - Persistence can be one of:
* - FilePersistence: Writes and reads from an unencrypted file. Can be used on Windows,
* macOs, or Linux.
* - FilePersistenceWithDataProtection: Used on Windows, writes and reads from file encrypted
* with windows dpapi-addon.
* - KeychainPersistence: Used on macOs, writes and reads from keychain.
* - LibSecretPersistence: Used on linux, writes and reads from secret service API. Requires
* libsecret be installed.
*/
export declare class PersistenceCachePlugin implements ICachePlugin {
persistence: IPersistence;
lastSync: number;
currentCache: string | null;
lockFilePath: string;
private crossPlatformLock;
private logger;
constructor(persistence: IPersistence, lockOptions?: CrossPlatformLockOptions);
/**
* Reads from storage and saves an in-memory copy. If persistence has not been updated
* since last time data was read, in memory copy is used.
*
* If cacheContext.cacheHasChanged === true, then file lock is created and not deleted until
* afterCacheAccess() is called, to prevent the cache file from changing in between
* beforeCacheAccess() and afterCacheAccess().
*/
beforeCacheAccess(cacheContext: TokenCacheContext): Promise<void>;
/**
* Writes to storage if MSAL in memory copy of cache has been changed.
*/
afterCacheAccess(cacheContext: TokenCacheContext): Promise<void>;
}
@@ -0,0 +1,99 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import { CrossPlatformLock } from '../lock/CrossPlatformLock.mjs';
import { pid } from 'process';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* MSAL cache plugin which enables callers to write the MSAL cache to disk on Windows,
* macOs, and Linux.
*
* - Persistence can be one of:
* - FilePersistence: Writes and reads from an unencrypted file. Can be used on Windows,
* macOs, or Linux.
* - FilePersistenceWithDataProtection: Used on Windows, writes and reads from file encrypted
* with windows dpapi-addon.
* - KeychainPersistence: Used on macOs, writes and reads from keychain.
* - LibSecretPersistence: Used on linux, writes and reads from secret service API. Requires
* libsecret be installed.
*/
class PersistenceCachePlugin {
constructor(persistence, lockOptions) {
this.persistence = persistence;
// initialize logger
this.logger = persistence.getLogger();
// create file lock
this.lockFilePath = `${this.persistence.getFilePath()}.lockfile`;
this.crossPlatformLock = new CrossPlatformLock(this.lockFilePath, this.logger, lockOptions);
// initialize default values
this.lastSync = 0;
this.currentCache = null;
}
/**
* Reads from storage and saves an in-memory copy. If persistence has not been updated
* since last time data was read, in memory copy is used.
*
* If cacheContext.cacheHasChanged === true, then file lock is created and not deleted until
* afterCacheAccess() is called, to prevent the cache file from changing in between
* beforeCacheAccess() and afterCacheAccess().
*/
async beforeCacheAccess(cacheContext) {
this.logger.info("Executing before cache access");
const reloadNecessary = await this.persistence.reloadNecessary(this.lastSync);
if (!reloadNecessary && this.currentCache !== null) {
if (cacheContext.cacheHasChanged) {
this.logger.verbose("Cache context has changed");
await this.crossPlatformLock.lock();
}
return;
}
try {
this.logger.info(`Reload necessary. Last sync time: ${this.lastSync}`);
await this.crossPlatformLock.lock();
this.currentCache = await this.persistence.load();
this.lastSync = new Date().getTime();
if (this.currentCache) {
cacheContext.tokenCache.deserialize(this.currentCache);
}
else {
this.logger.info("Cache empty.");
}
this.logger.info(`Last sync time updated to: ${this.lastSync}`);
}
finally {
if (!cacheContext.cacheHasChanged) {
await this.crossPlatformLock.unlock();
this.logger.info(`Pid ${pid} released lock`);
}
else {
this.logger.info(`Pid ${pid} beforeCacheAccess did not release lock`);
}
}
}
/**
* Writes to storage if MSAL in memory copy of cache has been changed.
*/
async afterCacheAccess(cacheContext) {
this.logger.info("Executing after cache access");
try {
if (cacheContext.cacheHasChanged) {
this.logger.info("Msal in-memory cache has changed. Writing changes to persistence");
this.currentCache = cacheContext.tokenCache.serialize();
await this.persistence.save(this.currentCache);
}
else {
this.logger.info("Msal in-memory cache has not changed. Did not write to persistence");
}
}
finally {
await this.crossPlatformLock.unlock();
this.logger.info(`Pid ${pid} afterCacheAccess released lock`);
}
}
}
export { PersistenceCachePlugin };
//# sourceMappingURL=PersistenceCachePlugin.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"PersistenceCachePlugin.mjs","sources":["../../src/persistence/PersistenceCachePlugin.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAYH;;;;;;;;;;;;AAYG;MACU,sBAAsB,CAAA;IAU/B,WACI,CAAA,WAAyB,EACzB,WAAsC,EAAA;AAEtC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;;AAG/B,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;;QAGtC,IAAI,CAAC,YAAY,GAAG,CAAG,EAAA,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAA,SAAA,CAAW,CAAC;AACjE,QAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAC1C,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,MAAM,EACX,WAAW,CACd,CAAC;;AAGF,QAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;AAClB,QAAA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;KAC5B;AAED;;;;;;;AAOG;IACI,MAAM,iBAAiB,CAC1B,YAA+B,EAAA;AAE/B,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;AAClD,QAAA,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,eAAe,CAC1D,IAAI,CAAC,QAAQ,CAChB,CAAC;QACF,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE;YAChD,IAAI,YAAY,CAAC,eAAe,EAAE;AAC9B,gBAAA,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACjD,gBAAA,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;AACvC,aAAA;YACD,OAAO;AAC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,CAAC,MAAM,CAAC,IAAI,CACZ,kEAAkE,CACrE,CAAC;gBACF,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;gBACxD,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAClD,aAAA;AAAM,iBAAA;AACH,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,oEAAoE,CACvE,CAAC;AACL,aAAA;AACJ,SAAA;AAAS,gBAAA;AACN,YAAA,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAO,IAAA,EAAA,GAAG,CAAiC,+BAAA,CAAA,CAAC,CAAC;AACjE,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,5 @@
import { IPersistence } from "./IPersistence.js";
import { IPersistenceConfiguration } from "./IPersistenceConfiguration.js";
export declare class PersistenceCreator {
static createPersistence(config: IPersistenceConfiguration): Promise<IPersistence>;
}
@@ -0,0 +1,68 @@
/*! @azure/msal-node-extensions v1.5.17 2025-07-08 */
'use strict';
import { FilePersistenceWithDataProtection } from './FilePersistenceWithDataProtection.mjs';
import { LibSecretPersistence } from './LibSecretPersistence.mjs';
import { KeychainPersistence } from './KeychainPersistence.mjs';
import { DataProtectionScope } from './DataProtectionScope.mjs';
import { Environment } from '../utils/Environment.mjs';
import { FilePersistence } from './FilePersistence.mjs';
import { PersistenceError } from '../error/PersistenceError.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
class PersistenceCreator {
static async createPersistence(config) {
let peristence;
// On Windows, uses a DPAPI encrypted file
if (Environment.isWindowsPlatform()) {
if (!config.cachePath || !config.dataProtectionScope) {
throw PersistenceError.createPersistenceNotValidatedError("Cache path and/or data protection scope not provided for the FilePersistenceWithDataProtection cache plugin");
}
peristence = await FilePersistenceWithDataProtection.create(config.cachePath, DataProtectionScope.CurrentUser, undefined, config.loggerOptions);
}
// On Mac, uses keychain.
else if (Environment.isMacPlatform()) {
if (!config.cachePath ||
!config.serviceName ||
!config.accountName) {
throw PersistenceError.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the KeychainPersistence cache plugin");
}
peristence = await KeychainPersistence.create(config.cachePath, config.serviceName, config.accountName, config.loggerOptions);
}
// On Linux, uses libsecret to store to secret service. Libsecret has to be installed.
else if (Environment.isLinuxPlatform()) {
if (!config.cachePath ||
!config.serviceName ||
!config.accountName) {
throw PersistenceError.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the LibSecretPersistence cache plugin");
}
peristence = await LibSecretPersistence.create(config.cachePath, config.serviceName, config.accountName, config.loggerOptions);
}
else {
throw PersistenceError.createNotSupportedError("The current environment is not supported by msal-node-extensions yet.");
}
await peristence.verifyPersistence().catch(async (e) => {
if (Environment.isLinuxPlatform() &&
config.usePlaintextFileOnLinux) {
if (!config.cachePath) {
throw PersistenceError.createPersistenceNotValidatedError("Cache path not provided for the FilePersistence cache plugin");
}
peristence = await FilePersistence.create(config.cachePath, config.loggerOptions);
const isFilePersistenceVerified = await peristence.verifyPersistence();
if (isFilePersistenceVerified) {
return peristence;
}
throw PersistenceError.createPersistenceNotVerifiedError("Persistence could not be verified");
}
else {
throw e;
}
});
return peristence;
}
}
export { PersistenceCreator };
//# sourceMappingURL=PersistenceCreator.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"PersistenceCreator.mjs","sources":["../../src/persistence/PersistenceCreator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAAA;;;AAGG;MAYU,kBAAkB,CAAA;AAC3B,IAAA,aAAa,iBAAiB,CAC1B,MAAiC,EAAA;AAEjC,QAAA,IAAI,UAAwB,CAAC;;AAG7B,QAAA,IAAI,WAAW,CAAC,iBAAiB,EAAE,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,mBAAmB,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