Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dawaltconley/secret
https://github.com/dawaltconley/secret
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dawaltconley/secret
- Owner: dawaltconley
- Created: 2019-09-15T18:49:50.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-17T22:25:59.000Z (about 5 years ago)
- Last Synced: 2024-11-03T06:33:15.751Z (12 days ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Storing information in the Mac Keychain
Uses the OSX `security` cli to save and retrieve passwords and other sensitive data.
## Examples
Instantiates a `Secret` object. Takes an argument for the service/url and an optional second argument for the account name.
```javascript
const Secret = require('./secret.js')const generic = new Secret('jekyll-comments')
// creates a generic password with no account infoconst internet = new Secret('https://api.github.com', 'dawaltconley')
// creates an internet password for the account 'dawaltconley'
```Following the behavior of `security`, Secret returns slightly different information depending on whether that Secret is of a generic or internet type.
```javascript
// generic.get().then(s => console.log(s))
{
type: 'generic',
keychain: '/Users/dylan/Library/Keychains/login.keychain-db',
label: 'jekyll-comments',
account: null,
service: 'jekyll-comments',
password: 'passw0rd!'
}// internet.get().then(s => console.log(s))
{
type: 'internet',
keychain: '/Users/dylan/Library/Keychains/login.keychain-db',
label: 'api.github.com',
account: 'dawaltconley',
host: 'api.github.com',
path: '/',
protocol: 'https:',
password: 'passw0rd!'
}
```## Configuration
### Secret.prompt
Determines how the user is prompted to enter a password. Defaults to `'secret: '`.
### Secret.executablePath
The path of the `security` child process. Defaults to `'/usr/bin/security'`.
## Methods
### config()
Runs an interactive commandline prompt to assign or overwrite the secret. Adds an extra prompt to confirm overwriting, if the secret has already been set.
### get(interactive)
Gets a secret from the command line. Accepts a boolean as its argument, which affects its behavior if the secret hasn't been set yet.
If set to true, `get` will prompt the user to input a secret (similar to config). If set to false, `get` will reject with a `SecretNotFoundError` (default: `true`).
### set(password, force)
Sets the secret to a provided string, storing it in the Keychain. Second argument determines whether to overwrite an existing secret in the Keychain, If `false`, rejects with a `SecretAlreadySetError` (default: `false`).
### delete()
Deletes the secret from the Keychain. Doesn't delete the secret object; secrets can still be reset or configured after deletion.