Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@azure/msal-node-extensions

Package Overview
Dependencies
Maintainers
3
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/msal-node-extensions - npm Package Compare versions

Comparing version 1.0.0-alpha.24 to 1.0.0-alpha.25

dist/Dpapi.d.ts

5

dist/msal-node-extensions.cjs.development.js

@@ -521,6 +521,3 @@ 'use strict';

/* eslint-disable-next-line @typescript-eslint/no-var-requires, no-var, import/no-commonjs */
var Dpapi = /*#__PURE__*/require("bindings")({
bindings: "dpapi",
userDefinedTries: [["module_root", "node_modules", "@azure", "msal-node-extensions", "build", "Release", "bindings"]]
});
var Dpapi = /*#__PURE__*/require("../build/Release/dpapi.node");

@@ -527,0 +524,0 @@ /*

2

dist/msal-node-extensions.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,r=require("fs"),i=require("process"),s=require("path"),a=(e=s)&&"object"==typeof e&&"default"in e?e.default:e,c=require("@azure/msal-common"),o=require("keytar");!function(e){e.WINDOWS="win32",e.LINUX="linux",e.MACOS="darwin"}(t||(t={}));class n extends Error{constructor(e,t){super(t?`${e}: ${t}`:e),Object.setPrototypeOf(this,n.prototype),this.errorCode=e,this.errorMessage=t,this.name="PersistenceError"}static createFileSystemError(e,t){return new n(e,t)}static createLibSecretError(e){return new n("GnomeKeyringError",e)}static createKeychainPersistenceError(e){return new n("KeychainError",e)}static createFilePersistenceWithDPAPIError(e){return new n("DPAPIEncryptedFileError",e)}static createCrossPlatformLockError(e){return new n("CrossPlatformLockError",e)}static createCachePersistenceError(e){return new n("CachePersistenceError",e)}static createNotSupportedError(e){return new n("NotSupportedError",e)}static createPersistenceNotVerifiedError(e){return new n("PersistenceNotVerifiedError",e)}static createPersistenceNotValidatedError(e){return new n("PersistenceNotValidatedError",e)}}class l{constructor(e,t,r){this.lockFilePath=e,this.retryNumber=r?r.retryNumber:500,this.retryDelay=r?r.retryDelay:100,this.logger=t}async lock(){for(let e=0;e<this.retryNumber;e++)try{return this.logger.info(`Pid ${i.pid} trying to acquire lock`),this.lockFileHandle=await r.promises.open(this.lockFilePath,"wx+"),this.logger.info(`Pid ${i.pid} acquired lock`),void await this.lockFileHandle.write(i.pid.toString())}catch(e){if("EEXIST"!==e.code&&"EPERM"!==e.code)throw this.logger.error(`${i.pid} was not able to acquire lock. Ran into error: ${e.message}`),n.createCrossPlatformLockError(e.message);this.logger.info(e),await this.sleep(this.retryDelay)}throw this.logger.error(i.pid+" was not able to acquire lock. Exceeded amount of retries set in the options"),n.createCrossPlatformLockError("Not able to acquire lock. Exceeded amount of retries set in options")}async unlock(){try{this.lockFileHandle?(await r.promises.unlink(this.lockFilePath),await this.lockFileHandle.close(),this.logger.info("lockfile deleted")):this.logger.warning("lockfile handle does not exist, so lockfile could not be deleted")}catch(e){if("ENOENT"!==e.code)throw this.logger.error(`${i.pid} was not able to release lock. Ran into error: ${e.message}`),n.createCrossPlatformLockError(e.message);this.logger.info("Tried to unlock but lockfile does not exist")}}sleep(e){return new Promise(t=>{setTimeout(t,e)})}}class h{async verifyPersistence(){const e=await this.createForPersistenceValidation();try{await e.save("Dummy data to verify underlying persistence mechanism");const t=await e.load();if(!t)throw n.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("Dummy data to verify underlying persistence mechanism"!==t)throw n.createCachePersistenceError("Persistence check failed. Data written Dummy data to verify underlying persistence mechanism is different from data read "+t);return await e.delete(),!0}catch(e){throw n.createCachePersistenceError("Verifing persistence failed with the error: "+e)}}}class d extends h{static async create(e,t){const r=new d;return r.filePath=e,r.logger=new c.Logger(t||d.createDefaultLoggerOptions()),await r.createCacheFile(),r}async save(e){try{await r.promises.writeFile(this.getFilePath(),e,"utf-8")}catch(e){throw n.createFileSystemError(e.code,e.message)}}async saveBuffer(e){try{await r.promises.writeFile(this.getFilePath(),e)}catch(e){throw n.createFileSystemError(e.code,e.message)}}async load(){try{return await r.promises.readFile(this.getFilePath(),"utf-8")}catch(e){throw n.createFileSystemError(e.code,e.message)}}async loadBuffer(){try{return await r.promises.readFile(this.getFilePath())}catch(e){throw n.createFileSystemError(e.code,e.message)}}async delete(){try{return await r.promises.unlink(this.getFilePath()),!0}catch(e){if("ENOENT"===e.code)return this.logger.warning("Cache file does not exist, so it could not be deleted"),!1;throw n.createFileSystemError(e.code,e.message)}}getFilePath(){return this.filePath}async reloadNecessary(e){return e<await this.timeLastModified()}getLogger(){return this.logger}createForPersistenceValidation(){const e=s.dirname(this.filePath)+"/test.cache";return d.create(e)}static createDefaultLoggerOptions(){return{loggerCallback:()=>{},piiLoggingEnabled:!1,logLevel:c.LogLevel.Info}}async timeLastModified(){try{return(await r.promises.stat(this.filePath)).mtime.getTime()}catch(e){if("ENOENT"===e.code)return this.logger.verbose("Cache file does not exist"),0;throw n.createFileSystemError(e.code,e.message)}}async createCacheFile(){await this.createFileDirectory();const e=await r.promises.open(this.filePath,"a");await e.close(),this.logger.info("File created at "+this.filePath)}async createFileDirectory(){try{await r.promises.mkdir(s.dirname(this.filePath),{recursive:!0})}catch(e){if("EEXIST"!==e.code)throw n.createFileSystemError(e.code,e.message);this.logger.info(`Directory ${s.dirname(this.filePath)} already exists`)}}}var u,g=require("bindings")({bindings:"dpapi",userDefinedTries:[["module_root","node_modules","@azure","msal-node-extensions","build","Release","bindings"]]});(u=exports.DataProtectionScope||(exports.DataProtectionScope={})).CurrentUser="CurrentUser",u.LocalMachine="LocalMachine";class m extends h{constructor(e,t){super(),this.scope=e,this.optionalEntropy=t?Buffer.from(t,"utf-8"):null}static async create(e,t,r,i){const s=new m(t,r);return s.filePersistence=await d.create(e,i),s}async save(e){try{const t=g.protectData(Buffer.from(e,"utf-8"),this.optionalEntropy,this.scope.toString());await this.filePersistence.saveBuffer(t)}catch(e){throw n.createFilePersistenceWithDPAPIError(e.message)}}async load(){try{const e=await this.filePersistence.loadBuffer();return void 0!==e&&e&&0!==e.length?g.unprotectData(e,this.optionalEntropy,this.scope.toString()).toString():(this.filePersistence.getLogger().info("Encrypted contents loaded from file were null or empty"),null)}catch(e){throw n.createFilePersistenceWithDPAPIError(e.message)}}async delete(){return this.filePersistence.delete()}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=s.dirname(this.filePersistence.getFilePath())+"/test.cache";return m.create(e,exports.DataProtectionScope.CurrentUser)}}class f extends h{constructor(e,t){super(),this.serviceName=e,this.accountName=t}static async create(e,t,r,i){const s=new f(t,r);return s.filePersistence=await d.create(e,i),s}async save(e){try{await o.setPassword(this.serviceName,this.accountName,e)}catch(e){throw n.createKeychainPersistenceError(e.message)}await this.filePersistence.save("{}")}async load(){try{return await o.getPassword(this.serviceName,this.accountName)}catch(e){throw n.createKeychainPersistenceError(e.message)}}async delete(){try{return await this.filePersistence.delete(),await o.deletePassword(this.serviceName,this.accountName)}catch(e){throw n.createKeychainPersistenceError(e.message)}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=s.dirname(this.filePersistence.getFilePath())+"/test.cache";return f.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class P extends h{constructor(e,t){super(),this.serviceName=e,this.accountName=t}static async create(e,t,r,i){const s=new P(t,r);return s.filePersistence=await d.create(e,i),s}async save(e){try{await o.setPassword(this.serviceName,this.accountName,e)}catch(e){throw n.createLibSecretError(e.message)}await this.filePersistence.save("{}")}async load(){try{return await o.getPassword(this.serviceName,this.accountName)}catch(e){throw n.createLibSecretError(e.message)}}async delete(){try{return await this.filePersistence.delete(),await o.deletePassword(this.serviceName,this.accountName)}catch(e){throw n.createLibSecretError(e.message)}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=s.dirname(this.filePersistence.getFilePath())+"/test.cache";return P.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class y{static get homeEnvVar(){return this.getEnvironmentVariable("HOME")}static get lognameEnvVar(){return this.getEnvironmentVariable("LOGNAME")}static get userEnvVar(){return this.getEnvironmentVariable("USER")}static get lnameEnvVar(){return this.getEnvironmentVariable("LNAME")}static get usernameEnvVar(){return this.getEnvironmentVariable("USERNAME")}static getEnvironmentVariable(e){return process.env[e]}static getEnvironmentPlatform(){return process.platform}static isWindowsPlatform(){return this.getEnvironmentPlatform()===t.WINDOWS}static isLinuxPlatform(){return this.getEnvironmentPlatform()===t.LINUX}static isMacPlatform(){return this.getEnvironmentPlatform()===t.MACOS}static isLinuxRootUser(){return 0===process.getuid()}static getUserRootDirectory(){return this.isWindowsPlatform?this.getUserHomeDirOnWindows():this.getUserHomeDirOnUnix()}static getUserHomeDirOnWindows(){return this.getEnvironmentVariable("LOCALAPPDATA")}static getUserHomeDirOnUnix(){if(this.isWindowsPlatform())throw n.createNotSupportedError("Getting the user home directory for unix is not supported in windows");if(!c.StringUtils.isEmpty(this.homeEnvVar))return this.homeEnvVar;let e=null;if(c.StringUtils.isEmpty(this.lognameEnvVar)?c.StringUtils.isEmpty(this.userEnvVar)?c.StringUtils.isEmpty(this.lnameEnvVar)?c.StringUtils.isEmpty(this.usernameEnvVar)||(e=this.usernameEnvVar):e=this.lnameEnvVar:e=this.userEnvVar:e=this.lognameEnvVar,this.isMacPlatform())return c.StringUtils.isEmpty(e)?null:a.join("/Users",e);if(this.isLinuxPlatform())return this.isLinuxRootUser()?"/root":c.StringUtils.isEmpty(e)?null:a.join("/home",e);throw n.createNotSupportedError("Getting the user home directory for unix is not supported in windows")}}exports.Environment=y,exports.FilePersistence=d,exports.FilePersistenceWithDataProtection=m,exports.KeychainPersistence=f,exports.LibSecretPersistence=P,exports.PersistenceCachePlugin=class{constructor(e,t){this.persistence=e,this.logger=e.getLogger(),this.lockFilePath=this.persistence.getFilePath()+".lockfile",this.crossPlatformLock=new l(this.lockFilePath,this.logger,t),this.lastSync=0,this.currentCache=null}async beforeCacheAccess(e){if(this.logger.info("Executing before cache access"),await this.persistence.reloadNecessary(this.lastSync)||null===this.currentCache)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(),e.tokenCache.deserialize(this.currentCache),this.logger.info("Last sync time updated to: "+this.lastSync)}finally{e.cacheHasChanged?this.logger.info(`Pid ${i.pid} beforeCacheAccess did not release lock`):(await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${i.pid} released lock`))}else e.cacheHasChanged&&(this.logger.verbose("Cache context has changed"),await this.crossPlatformLock.lock())}async afterCacheAccess(e){this.logger.info("Executing after cache access");try{e.cacheHasChanged?(this.logger.info("Msal in-memory cache has changed. Writing changes to persistence"),this.currentCache=e.tokenCache.serialize(),await this.persistence.save(this.currentCache)):this.logger.info("Msal in-memory cache has not changed. Did not write to persistence")}finally{await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${i.pid} afterCacheAccess released lock`)}}},exports.PersistenceCreator=class{static async createPersistence(e){let t;if(y.isWindowsPlatform()){if(!e.cachePath||!e.dataProtectionScope)throw n.createPersistenceNotValidatedError("Cache path and/or data protection scope not provided for the FilePersistenceWithDataProtection cache plugin");t=await m.create(e.cachePath,exports.DataProtectionScope.CurrentUser)}else if(y.isMacPlatform()){if(!e.cachePath||!e.serviceName||!e.accountName)throw n.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the KeychainPersistence cache plugin");t=await f.create(e.cachePath,e.serviceName,e.accountName)}else{if(!y.isLinuxPlatform())throw n.createNotSupportedError("The current environment is not supported by msal-node-extensions yet.");if(!e.cachePath||!e.serviceName||!e.accountName)throw n.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the LibSecretPersistence cache plugin");t=await P.create(e.cachePath,e.serviceName,e.accountName)}if(!await t.verifyPersistence().catch(()=>!1)){if(y.isLinuxPlatform()&&e.usePlaintextFileOnLinux){if(!e.cachePath)throw n.createPersistenceNotValidatedError("Cache path not provided for the FilePersistence cache plugin");if(t=await d.create(e.cachePath),await t.verifyPersistence())return t}throw n.createPersistenceNotVerifiedError("Persistence could not be verified")}return t}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,r=require("fs"),i=require("process"),s=require("path"),a=(e=s)&&"object"==typeof e&&"default"in e?e.default:e,c=require("@azure/msal-common"),o=require("keytar");!function(e){e.WINDOWS="win32",e.LINUX="linux",e.MACOS="darwin"}(t||(t={}));class n extends Error{constructor(e,t){super(t?`${e}: ${t}`:e),Object.setPrototypeOf(this,n.prototype),this.errorCode=e,this.errorMessage=t,this.name="PersistenceError"}static createFileSystemError(e,t){return new n(e,t)}static createLibSecretError(e){return new n("GnomeKeyringError",e)}static createKeychainPersistenceError(e){return new n("KeychainError",e)}static createFilePersistenceWithDPAPIError(e){return new n("DPAPIEncryptedFileError",e)}static createCrossPlatformLockError(e){return new n("CrossPlatformLockError",e)}static createCachePersistenceError(e){return new n("CachePersistenceError",e)}static createNotSupportedError(e){return new n("NotSupportedError",e)}static createPersistenceNotVerifiedError(e){return new n("PersistenceNotVerifiedError",e)}static createPersistenceNotValidatedError(e){return new n("PersistenceNotValidatedError",e)}}class l{constructor(e,t,r){this.lockFilePath=e,this.retryNumber=r?r.retryNumber:500,this.retryDelay=r?r.retryDelay:100,this.logger=t}async lock(){for(let e=0;e<this.retryNumber;e++)try{return this.logger.info(`Pid ${i.pid} trying to acquire lock`),this.lockFileHandle=await r.promises.open(this.lockFilePath,"wx+"),this.logger.info(`Pid ${i.pid} acquired lock`),void await this.lockFileHandle.write(i.pid.toString())}catch(e){if("EEXIST"!==e.code&&"EPERM"!==e.code)throw this.logger.error(`${i.pid} was not able to acquire lock. Ran into error: ${e.message}`),n.createCrossPlatformLockError(e.message);this.logger.info(e),await this.sleep(this.retryDelay)}throw this.logger.error(i.pid+" was not able to acquire lock. Exceeded amount of retries set in the options"),n.createCrossPlatformLockError("Not able to acquire lock. Exceeded amount of retries set in options")}async unlock(){try{this.lockFileHandle?(await r.promises.unlink(this.lockFilePath),await this.lockFileHandle.close(),this.logger.info("lockfile deleted")):this.logger.warning("lockfile handle does not exist, so lockfile could not be deleted")}catch(e){if("ENOENT"!==e.code)throw this.logger.error(`${i.pid} was not able to release lock. Ran into error: ${e.message}`),n.createCrossPlatformLockError(e.message);this.logger.info("Tried to unlock but lockfile does not exist")}}sleep(e){return new Promise(t=>{setTimeout(t,e)})}}class h{async verifyPersistence(){const e=await this.createForPersistenceValidation();try{await e.save("Dummy data to verify underlying persistence mechanism");const t=await e.load();if(!t)throw n.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("Dummy data to verify underlying persistence mechanism"!==t)throw n.createCachePersistenceError("Persistence check failed. Data written Dummy data to verify underlying persistence mechanism is different from data read "+t);return await e.delete(),!0}catch(e){throw n.createCachePersistenceError("Verifing persistence failed with the error: "+e)}}}class d extends h{static async create(e,t){const r=new d;return r.filePath=e,r.logger=new c.Logger(t||d.createDefaultLoggerOptions()),await r.createCacheFile(),r}async save(e){try{await r.promises.writeFile(this.getFilePath(),e,"utf-8")}catch(e){throw n.createFileSystemError(e.code,e.message)}}async saveBuffer(e){try{await r.promises.writeFile(this.getFilePath(),e)}catch(e){throw n.createFileSystemError(e.code,e.message)}}async load(){try{return await r.promises.readFile(this.getFilePath(),"utf-8")}catch(e){throw n.createFileSystemError(e.code,e.message)}}async loadBuffer(){try{return await r.promises.readFile(this.getFilePath())}catch(e){throw n.createFileSystemError(e.code,e.message)}}async delete(){try{return await r.promises.unlink(this.getFilePath()),!0}catch(e){if("ENOENT"===e.code)return this.logger.warning("Cache file does not exist, so it could not be deleted"),!1;throw n.createFileSystemError(e.code,e.message)}}getFilePath(){return this.filePath}async reloadNecessary(e){return e<await this.timeLastModified()}getLogger(){return this.logger}createForPersistenceValidation(){const e=s.dirname(this.filePath)+"/test.cache";return d.create(e)}static createDefaultLoggerOptions(){return{loggerCallback:()=>{},piiLoggingEnabled:!1,logLevel:c.LogLevel.Info}}async timeLastModified(){try{return(await r.promises.stat(this.filePath)).mtime.getTime()}catch(e){if("ENOENT"===e.code)return this.logger.verbose("Cache file does not exist"),0;throw n.createFileSystemError(e.code,e.message)}}async createCacheFile(){await this.createFileDirectory();const e=await r.promises.open(this.filePath,"a");await e.close(),this.logger.info("File created at "+this.filePath)}async createFileDirectory(){try{await r.promises.mkdir(s.dirname(this.filePath),{recursive:!0})}catch(e){if("EEXIST"!==e.code)throw n.createFileSystemError(e.code,e.message);this.logger.info(`Directory ${s.dirname(this.filePath)} already exists`)}}}var u,g=require("../build/Release/dpapi.node");(u=exports.DataProtectionScope||(exports.DataProtectionScope={})).CurrentUser="CurrentUser",u.LocalMachine="LocalMachine";class m extends h{constructor(e,t){super(),this.scope=e,this.optionalEntropy=t?Buffer.from(t,"utf-8"):null}static async create(e,t,r,i){const s=new m(t,r);return s.filePersistence=await d.create(e,i),s}async save(e){try{const t=g.protectData(Buffer.from(e,"utf-8"),this.optionalEntropy,this.scope.toString());await this.filePersistence.saveBuffer(t)}catch(e){throw n.createFilePersistenceWithDPAPIError(e.message)}}async load(){try{const e=await this.filePersistence.loadBuffer();return void 0!==e&&e&&0!==e.length?g.unprotectData(e,this.optionalEntropy,this.scope.toString()).toString():(this.filePersistence.getLogger().info("Encrypted contents loaded from file were null or empty"),null)}catch(e){throw n.createFilePersistenceWithDPAPIError(e.message)}}async delete(){return this.filePersistence.delete()}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=s.dirname(this.filePersistence.getFilePath())+"/test.cache";return m.create(e,exports.DataProtectionScope.CurrentUser)}}class f extends h{constructor(e,t){super(),this.serviceName=e,this.accountName=t}static async create(e,t,r,i){const s=new f(t,r);return s.filePersistence=await d.create(e,i),s}async save(e){try{await o.setPassword(this.serviceName,this.accountName,e)}catch(e){throw n.createKeychainPersistenceError(e.message)}await this.filePersistence.save("{}")}async load(){try{return await o.getPassword(this.serviceName,this.accountName)}catch(e){throw n.createKeychainPersistenceError(e.message)}}async delete(){try{return await this.filePersistence.delete(),await o.deletePassword(this.serviceName,this.accountName)}catch(e){throw n.createKeychainPersistenceError(e.message)}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=s.dirname(this.filePersistence.getFilePath())+"/test.cache";return f.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class P extends h{constructor(e,t){super(),this.serviceName=e,this.accountName=t}static async create(e,t,r,i){const s=new P(t,r);return s.filePersistence=await d.create(e,i),s}async save(e){try{await o.setPassword(this.serviceName,this.accountName,e)}catch(e){throw n.createLibSecretError(e.message)}await this.filePersistence.save("{}")}async load(){try{return await o.getPassword(this.serviceName,this.accountName)}catch(e){throw n.createLibSecretError(e.message)}}async delete(){try{return await this.filePersistence.delete(),await o.deletePassword(this.serviceName,this.accountName)}catch(e){throw n.createLibSecretError(e.message)}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=s.dirname(this.filePersistence.getFilePath())+"/test.cache";return P.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class y{static get homeEnvVar(){return this.getEnvironmentVariable("HOME")}static get lognameEnvVar(){return this.getEnvironmentVariable("LOGNAME")}static get userEnvVar(){return this.getEnvironmentVariable("USER")}static get lnameEnvVar(){return this.getEnvironmentVariable("LNAME")}static get usernameEnvVar(){return this.getEnvironmentVariable("USERNAME")}static getEnvironmentVariable(e){return process.env[e]}static getEnvironmentPlatform(){return process.platform}static isWindowsPlatform(){return this.getEnvironmentPlatform()===t.WINDOWS}static isLinuxPlatform(){return this.getEnvironmentPlatform()===t.LINUX}static isMacPlatform(){return this.getEnvironmentPlatform()===t.MACOS}static isLinuxRootUser(){return 0===process.getuid()}static getUserRootDirectory(){return this.isWindowsPlatform?this.getUserHomeDirOnWindows():this.getUserHomeDirOnUnix()}static getUserHomeDirOnWindows(){return this.getEnvironmentVariable("LOCALAPPDATA")}static getUserHomeDirOnUnix(){if(this.isWindowsPlatform())throw n.createNotSupportedError("Getting the user home directory for unix is not supported in windows");if(!c.StringUtils.isEmpty(this.homeEnvVar))return this.homeEnvVar;let e=null;if(c.StringUtils.isEmpty(this.lognameEnvVar)?c.StringUtils.isEmpty(this.userEnvVar)?c.StringUtils.isEmpty(this.lnameEnvVar)?c.StringUtils.isEmpty(this.usernameEnvVar)||(e=this.usernameEnvVar):e=this.lnameEnvVar:e=this.userEnvVar:e=this.lognameEnvVar,this.isMacPlatform())return c.StringUtils.isEmpty(e)?null:a.join("/Users",e);if(this.isLinuxPlatform())return this.isLinuxRootUser()?"/root":c.StringUtils.isEmpty(e)?null:a.join("/home",e);throw n.createNotSupportedError("Getting the user home directory for unix is not supported in windows")}}exports.Environment=y,exports.FilePersistence=d,exports.FilePersistenceWithDataProtection=m,exports.KeychainPersistence=f,exports.LibSecretPersistence=P,exports.PersistenceCachePlugin=class{constructor(e,t){this.persistence=e,this.logger=e.getLogger(),this.lockFilePath=this.persistence.getFilePath()+".lockfile",this.crossPlatformLock=new l(this.lockFilePath,this.logger,t),this.lastSync=0,this.currentCache=null}async beforeCacheAccess(e){if(this.logger.info("Executing before cache access"),await this.persistence.reloadNecessary(this.lastSync)||null===this.currentCache)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(),e.tokenCache.deserialize(this.currentCache),this.logger.info("Last sync time updated to: "+this.lastSync)}finally{e.cacheHasChanged?this.logger.info(`Pid ${i.pid} beforeCacheAccess did not release lock`):(await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${i.pid} released lock`))}else e.cacheHasChanged&&(this.logger.verbose("Cache context has changed"),await this.crossPlatformLock.lock())}async afterCacheAccess(e){this.logger.info("Executing after cache access");try{e.cacheHasChanged?(this.logger.info("Msal in-memory cache has changed. Writing changes to persistence"),this.currentCache=e.tokenCache.serialize(),await this.persistence.save(this.currentCache)):this.logger.info("Msal in-memory cache has not changed. Did not write to persistence")}finally{await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${i.pid} afterCacheAccess released lock`)}}},exports.PersistenceCreator=class{static async createPersistence(e){let t;if(y.isWindowsPlatform()){if(!e.cachePath||!e.dataProtectionScope)throw n.createPersistenceNotValidatedError("Cache path and/or data protection scope not provided for the FilePersistenceWithDataProtection cache plugin");t=await m.create(e.cachePath,exports.DataProtectionScope.CurrentUser)}else if(y.isMacPlatform()){if(!e.cachePath||!e.serviceName||!e.accountName)throw n.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the KeychainPersistence cache plugin");t=await f.create(e.cachePath,e.serviceName,e.accountName)}else{if(!y.isLinuxPlatform())throw n.createNotSupportedError("The current environment is not supported by msal-node-extensions yet.");if(!e.cachePath||!e.serviceName||!e.accountName)throw n.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the LibSecretPersistence cache plugin");t=await P.create(e.cachePath,e.serviceName,e.accountName)}if(!await t.verifyPersistence().catch(()=>!1)){if(y.isLinuxPlatform()&&e.usePlaintextFileOnLinux){if(!e.cachePath)throw n.createPersistenceNotValidatedError("Cache path not provided for the FilePersistence cache plugin");if(t=await d.create(e.cachePath),await t.verifyPersistence())return t}throw n.createPersistenceNotVerifiedError("Persistence could not be verified")}return t}};
//# sourceMappingURL=msal-node-extensions.cjs.production.min.js.map

@@ -514,6 +514,3 @@ import { promises } from 'fs';

/* eslint-disable-next-line @typescript-eslint/no-var-requires, no-var, import/no-commonjs */
var Dpapi = /*#__PURE__*/require("bindings")({
bindings: "dpapi",
userDefinedTries: [["module_root", "node_modules", "@azure", "msal-node-extensions", "build", "Release", "bindings"]]
});
var Dpapi = /*#__PURE__*/require("../build/Release/dpapi.node");

@@ -520,0 +517,0 @@ /*

{
"name": "@azure/msal-node-extensions",
"version": "1.0.0-alpha.24",
"version": "1.0.0-alpha.25",
"repository": {

@@ -11,2 +11,3 @@ "type": "git",

"typings": "dist/index.d.ts",
"gypfile": true,
"keywords": [

@@ -29,4 +30,4 @@ "js",

"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"start": "tsdx watch --tsconfig ./tsconfig.build.json",
"build": "node-gyp rebuild && tsdx build --tsconfig ./tsconfig.build.json",
"build:common": "cd ../../lib/msal-common && npm run build",

@@ -55,10 +56,9 @@ "build:all": "npm run build:common && npm run build",

"dependencies": {
"@azure/msal-common": "^7.5.0",
"bindings": "git+https://github.com/samuelkubai/node-bindings.git#v1.6.0",
"@azure/msal-common": "^7.6.0",
"keytar": "^7.8.0",
"nan": "^2.13.2"
"node-addon-api": "5.0.0"
},
"devDependencies": {
"@types/node": "^18.8.3",
"husky": "^4.2.5",
"node-gyp": "^9.0.0",
"tsdx": "^0.14.1",

@@ -65,0 +65,0 @@ "tslib": "^2.0.0",

@@ -9,3 +9,3 @@ /*

import { PersistenceError } from "../error/PersistenceError";
import { Dpapi } from "../dpapi-addon/Dpapi";
import { Dpapi } from "../Dpapi";
import { DataProtectionScope } from "./DataProtectionScope";

@@ -12,0 +12,0 @@ import { Logger, LoggerOptions } from "@azure/msal-common";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc