Skip to content

Instantly share code, notes, and snippets.

@franzwong
Created July 20, 2019 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franzwong/e02803a7a89719707fb5f06f08bd801a to your computer and use it in GitHub Desktop.
Save franzwong/e02803a7a89719707fb5f06f08bd801a to your computer and use it in GitHub Desktop.
Mac OS Keychain wrapper
const util = require('util');
const child_process = require('child_process');
const exec = util.promisify(child_process.exec);
function addPassword(serviceName, userName, password) {
return exec(`security add-generic-password -s ${serviceName} -a ${userName} -w ${password}`);
}
async function getPassword(serviceName, userName) {
const { stdout } = await exec(`security find-generic-password -s ${serviceName} -a ${userName} -w`);
return stdout.trim();
}
function deletePassword(serviceName, userName) {
return exec(`security delete-generic-password -s ${serviceName} -a ${userName}`);
}
module.exports = {
addPassword,
getPassword,
deletePassword,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment