mirror of
https://github.com/expo/node-vault.git
synced 2026-11-27 16:45:28 -10:00
23 lines
645 B
JavaScript
23 lines
645 B
JavaScript
// file: example/auth_userpass.js
|
|
|
|
process.env.DEBUG = 'node-vault'; // switch on debug mode
|
|
const vault = require('./../src/index')();
|
|
|
|
const mountPoint = 'userpass';
|
|
const username = 'me';
|
|
const password = 'foo';
|
|
|
|
vault.auths()
|
|
.then((result) => {
|
|
if (result.hasOwnProperty('userpass/')) return undefined;
|
|
return vault.enableAuth({
|
|
mount_point: mountPoint,
|
|
type: 'userpass',
|
|
description: 'userpass auth',
|
|
});
|
|
})
|
|
.then(() => vault.write(`auth/userpass/users/${username}`, { password, policies: 'root' }))
|
|
.then(() => vault.userpassLogin({ username, password }))
|
|
.then(console.log)
|
|
.catch((err) => console.error(err.message));
|