-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (22 loc) · 755 Bytes
/
server.js
File metadata and controls
35 lines (22 loc) · 755 Bytes
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
29
30
31
32
33
34
var express = require('express');
var bodyParser = require('body-parser');
const OAuth2Server = require('node-oauth2-server');
var models = require('./models');
var port = process.env.PORT || 3000;
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.oauth = new OAuth2Server({
model: models.oauth,
grants: ['password', 'authorization_code', 'refresh_token']
});
app.all('/oauth/token', app.oauth.grant());
app.all('/oauth/authorise', app.oauth.authCodeGrant((req, next) => {
next(null, true, '123456', null);
}));
app.get('/', app.oauth.authorise(), (req,res) => {
res.send('Secret Area');
});
app.use(app.oauth.errorHandler());
app.listen(port, () => {
console.log('listening to port'+port);
});