codemix/oriento — pull request #165 by phpnode (2014-12-17 01:05:10+00:00)
Title: Add support for token based authentication.

This adds support for using tokens to authenticate with OrientDB.

```js
var oriento = require('oriento');
var server = oriento({
username: 'root',
password: 'root',
useToken: true
});

var readerToken, adminToken;

var db = server.use({
name: 'mydb',
username: 'admin',
password: 'admin'
});

db.open()
.then(function () {
adminToken = db.token;
// by default, execute a command using the main user (admin)
return db.select().from('OUser').all();
})
.then(function (users) {
// get a token for the `reader` user.
return server.use({
name: 'mydb',
username: 'reader',
password: 'reader'
})
.open()
.then(function (readerDb) {
readerToken = readerDb.token;
})
})
.then(function () {
// execute a command on behalf of the reader:
return db.select().from('OUser').token(readerToken).all();
})
.then(function (users) {
// try and insert something using the reader user.
return db.insert().into('V').set({foo: 'bar'}).token(readerToken).one(); // fails, no permissions!
});

```