@house-agency/brewsession
v0.3.3
Published
The Brewery Session Manager
Downloads
7
Readme
The Brewery Session Manager
The easy way
::javascript
const conf = require('@house-agency/brewtils/config').load('config.json');
const express = require('express');
const http = require('http');
const sessions = require('brewsession/route');
const webapp = express();
const server = http.createServer(webapp);
webapp.use(/\/api(?!\/session\/create)/, route.verify_http_request);
webapp.use('/api/session', route.routes);
server.listen(5555);
Configuring keys and validation
In the config.json file:
::javascript
{
"api": {
"key": "test-key",
"valid": 500,
"generate": 500,
"remove": 1000
}
}
Using the service directly
::javascript
const service = require('brewsession/service');
// Generate new api-keys
service.generate_apikey()
.then(api_key => {
// Do something with key
});
// Create a session
service.create(api_key)
.then(token => {
// Do something with token
});
// Validate a session
service.verify(token)
.then(token => {
// Do something verified
})
.catch(error => {
// Do something unverified
});