There was an error while loading. Please reload this page.
1 parent 1b960f2 commit 0d63147Copy full SHA for 0d63147
protected-routes.js
@@ -5,11 +5,23 @@ var express = require('express'),
5
6
var app = module.exports = express.Router();
7
8
+// Validate access_token
9
var jwtCheck = jwt({
- secret: config.secret
10
+ secret: config.secret,
11
+ audience: config.audience,
12
+ issuer: config.issuer
13
});
14
-app.use('/api/protected', jwtCheck);
15
+// Check for scope
16
+function require_scope(scope) {
17
+ return function (req, res, next) {
18
+ var has_scopes = req.user.scope === scope;
19
+ if (!has_scopes) { res.send(401); }
20
+ next();
21
+ };
22
+}
23
+
24
+app.use('/api/protected', jwtCheck, require_scope('full_access'));
25
26
app.get('/api/protected/random-quote', function(req, res) {
27
res.status(200).send(quoter.getRandomOne());
0 commit comments