Skip to content

mongodb-js/node-keytar

 
 

Repository files navigation

keytar travis appveyor

Securely store and manage passwords using platform specific backends. The backend on macOS is Keychain, on Linux it's the Secret Service, and on Windows it's Credential Vault.

Install and Usage

npm install keytar
const keytar = require('keytar');

keytar.addPassword('com.mycompany.myapp', 'weblogin', 'myPassword');
>> true
keytar.getPassword('com.mycompany.myapp', 'weblogin');
>> 'myPassword'
keytar.replacePassword('com.mycompany.myapp', 'weblogin', 'myBett3rPassw0rd');
>> true
keytar.getPassword('com.mycompany.myapp', 'weblogin');
>> 'myBett3rPassw0rd'
keytar.removePassword('com.mycompany.myapp', 'weblogin');
>> true

Linux

Currently this library uses libsecret so you may need to install it before npm installing.

Depending on your distribution, you will need to run the following command:

  • Debian/Ubuntu: sudo apt-get install libsecret-1-dev
  • Red Hat-based: sudo yum install libsecret-devel
  • Arch: sudo pacman -S libsecret

API

getPassword(service, account)

Get the stored password for the service and account.

service - The string service name.

account - The string account name.

Returns the string password or null on failures.

addPassword(service, account, password)

Add the password for the service and account to the keychain.

service - The string service name.

account - The string account name.

password - The string password.

Returns true on success, false on failure.

deletePassword(service, account)

Delete the stored password for the service and account.

service - The string service name.

account - The string account name.

Returns true if a password has been deleted, or false on failure.

replacePassword(service, account, password)

Replace the password for the service and account in the keychain.

This is a simple convenience function that internally calls deletePassword(service, account) followed by addPassword(service, account, password).

service - The string service name.

account - The string account name.

password - The string password.

Returns true on success, false on failure.

findPassword(service)

Find a password for the service in the keychain.

service - The string service name.

Returns the string password or null on failures.

Development

git clone git@github.com:mongodb-js/node-keytar.git ~/keytar;
cd ~/keytar;
npm install;
npm test;

Packages

 
 
 

Languages

  • C++ 58.3%
  • JavaScript 31.9%
  • Python 8.1%
  • Shell 1.7%