Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_migrateKeychain() {
console.log("---> Migrating keychain from Nylas Mail Basic")
try {
const raw = keytar.getPassword("Nylas Mail", "Nylas Mail Keys") || "{}";
const passwords = JSON.parse(raw);
const token = passwords["Nylas Account"]
if (token) {
keytar.replacePassword("Nylas", "Nylas Account", token)
}
} catch (err) {
console.error(err);
// dont' throw
}
}
_writeKeyHash(keys) {
// returns true if successful
return keytar.replacePassword(this.SERVICE_NAME, this.KEY_NAME, JSON.stringify(keys));
}
'use strict';
const speakeasy = require('speakeasy');
const notifier = require('node-notifier');
const keytar = require('keytar');
const ncp = require('copy-paste');
if (!process.argv[2]) {
console.error('Usage: quick-2fa --save KEY-NAME YOUR-KEY');
console.error('Usage: quick-2fa KEY-NAME');
process.exit(1);
}
if (process.argv[2] === '--save') {
const [, , , account, password] = process.argv;
const done = keytar.replacePassword('quick-2fa', account, password);
if (done) {
console.log('Key stored!', 'Now you can retrieve your two-factor authentication token by running:');
console.log(`$ quick-2fa ${account}`);
process.exit(0);
} else {
console.error('Failed to store your key!');
process.exit(1);
}
}
const key = process.argv[2] === '--key' ? process.argv[3] : keytar.getPassword('quick-2fa', process.argv[2]);
if (!key) {
console.error('Sorry, could not find your key...');
process.exit(1);
}
export default () => next => action => {
if (action.type === 'SAVE_TUNNEL') {
if (action.tunnel.password && action.tunnel.password[0] !== '\0') {
const password = action.tunnel.password;
action.tunnel.password = '\0encrypted';
const saved = keytar.replacePassword('tunnels2', action.tunnel.id, password);
if (!saved) {
console.error('Cannot save password to keytar.');
}
}
}
return next(action);
};
setToken (token) {
const tokenResult = keytar.replacePassword(KEYCHAIN_SERVICE_NAME, KEYCHAIN_ACCOUNT, token)
this.emitter.emit('did-set-token')
return tokenResult
}
this._try(() => {
const keys = this._getKeyHash();
delete keys[keyName];
return keytar.replacePassword(this.SERVICE_NAME, this.KEY_NAME, JSON.stringify(keys))
})
}
const setGoogleMapsAPIToken = token => replacePassword('uber-cli', 'Google Maps API Token', token);
const setUberAPIToken = token => replacePassword('uber-cli', 'Uber API Token', token);