Add JWT data in the signature

This commit adds Mainflux metadata embedded in JWT.

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2015-12-06 14:56:33 +01:00
parent 40194aeb9b
commit 55b28f90f0
2 changed files with 17 additions and 3 deletions

View File

@ -3,6 +3,9 @@ var devicesDb = require('../database').collection('devices');
var jwt = require('jsonwebtoken');
var config = require('../../config/config');
var log = require('../logger');
var os = require('os');
/** createDevice() */
exports.createDevice = function(req, res, next) {
@ -14,8 +17,16 @@ exports.createDevice = function(req, res, next) {
if (err)
return next(err);
var token = jwt.sign(device, config.tokenSecret, {
expiresInMinutes: config.userTokenExpirePeriod
var signaturePayload = {
version: config.version
}
console.log(signaturePayload);
var token = jwt.sign(signaturePayload, config.tokenSecret, {
subject: 'Device Auth Token',
issuer: req.headers.host,
audience: device._id.toString()
});
res.json({
@ -32,6 +43,8 @@ exports.createDevice = function(req, res, next) {
exports.getAllDevices = function(req, res, next) {
console.log("req.headers['x-auth-token'] = ", req.headers['x-auth-token']);
log.info('hi');
devicesDb.find(req.body, function(err, devices) {
if (err)

View File

@ -11,5 +11,6 @@
"limiter" : {
"defaultBurstRate": 50,
"defaultRatePerSec": 0.5
}
},
"version": "0.1"
}