forked from auth0/node-jwks-rsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (39 loc) · 962 Bytes
/
server.js
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
35
36
37
38
39
40
41
42
43
44
const Express = require('express');
const jwt = require('express-jwt');
const logger = require('debug')('express');
const jwksRsa = require('../../lib');
const jwksHost = process.env.JWKS_HOST;
const audience = process.env.AUDIENCE;
const issuer = process.env.ISSUER;
// Initialize the app.
const app = new Express();
app.use(jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 2,
jwksUri: `${jwksHost}/.well-known/jwks.json`
}),
audience: audience,
issuer: issuer,
algorithms: [ 'RS256' ]
}));
app.get('/me', (req, res) => {
res.json(req.user);
});
app.use((err, req, res, next) => {
logger(err.name, err.message);
res.json({
name: err.name,
message: err.message
});
});
// Start the server.
const port = process.env.PORT || 4001;
app.listen(port, function(error) {
if (error) {
logger(error);
} else {
logger('Listening on http://localhost:' + port);
}
});