Skip to content

Create a plug-in

An example of a basic (skeleton) plug-in using node.js and express:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var jwt = require('jsonwebtoken');  
var express = require('express');  
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var app = express();  

app.use(cookieParser());
app.use(bodyParser.urlencoded({extended:true}));

app.use(function(req, res, next){  
    var token = req.query.token || req.cookies.token;  
    jwt.verify(token, key, {algorithms:['RS256']}, function(err, params){  
        if (err) return res.status(400).send('error');  
        if (!params) return res.status(400).send('error');  
        // params contains a json object with the exposed profile data  
        req.user = params;              // for use in routes  
        res.cookie('token', token);     // store token in cookie  
        next();  
    });  
});

app.get('/', function(req, res){
    res.json({user:req.user});
});

app.listen(8080, function(err){
    if (err) throw(err);
});