Skip to content

Instantly share code, notes, and snippets.

@khle
Created February 25, 2016 01:38
Show Gist options
  • Select an option

  • Save khle/23d8616c0eee2a5fd44f to your computer and use it in GitHub Desktop.

Select an option

Save khle/23d8616c0eee2a5fd44f to your computer and use it in GitHub Desktop.
server.js
var express = require('express'),
app = express(),
fs = require('fs'),
aad = require('azure-ad-jwt');
app.get('/books', function(req, res) {
var audience = 'http://samplewebservice.azure-mobile.net'
var authorization = req.headers['authorization']
if (authorization) {
var bearer = authorization.split(" ");
var jwtToken = bearer[1];
if (jwtToken) {
aad.verify(jwtToken, { audience: audience}, function(err, result) {
if (result) {
fs.readFile(__dirname + "/" + "_data.json", 'utf8', function(err, data) {
res.status(200).send(data)
});
} else {
res.status(401).send('no valid token')
}
})
} else {
res.status(401).send('no token in header')
}
} else {
res.status(401).send('no auth attr in header')
}
})
var server = app.listen(8080)
console.log('Server listening on port 8080')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment