Created
July 20, 2019 07:48
-
-
Save franzwong/e02803a7a89719707fb5f06f08bd801a to your computer and use it in GitHub Desktop.
Mac OS Keychain wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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