For more up to date example of using express-jwt-auth with angular check: angular-auth-foundation repository.
Set up a nodejs server in a separate directory with package.json and server.js files:
{
"name": "express-jwt-auth-demo",
"version": "0.0.0",
"main": "server.js",
"dependencies": {
"express": "^4.9.7",
"mongoose": "^3.8.16",
"express-jwt-auth": "*",
"body-parser": "^1.9.2"
}
}var express = require('express');
var app = express();
var http = require('http');
var server = http.Server(app);
var path = require('path');
var bodyParser = require('body-parser');
var settings = {
mongoconnection: 'mongodb://localhost:27017/simple-api-auth',
logFile: path.join(__dirname, 'authlogger.log'),
corsDomains: ['http://localhost:3000'],
// Nodemailer settings, used for resetting password
mailer: {
mailerFrom : 'your.mail@example.com',
mailerTitle : 'Password reset',
transporter : {
service: 'Gmail',
auth: {
user: 'your.mail@gmail.com',
pass: '<app_token>'
}
}
}
};
var auth = require('express-jwt-auth')(app, settings);
app.use(bodyParser.json());
app.get('/api/test', auth, function(req, res) {
res.send('Secured access.');
});
server.listen(5000);Make sure you have node, npm, gulp and bower installed.
npm installbower install
To run the project locally: gulp serve.
This example is based on: https://github.com/sahat/tvshow-tracker