-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (21 loc) · 938 Bytes
/
index.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
const express = require('express');
const jwt = require('express-jwt');
const jwksRsa = require('jwks-rsa');
const envVariables = require('./env-variables.json');
const app = express();
app.get('/public', (req, res) => res.send('Everyone in the world can read this message.'));
app.use(jwt({
// Dynamically provide a signing key based on the kid in the header and the singing keys provided by the JWKS endpoint.
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${envVariables.auth0Domain}/.well-known/jwks.json`
}),
// Validate the audience and the issuer.
audience: envVariables.apiIdentifier,
issuer: `https://${envVariables.auth0Domain}/`,
algorithms: ['RS256']
}));
app.get('/private', (req, res) => res.send('Only authenticated users can read this message.'));
app.listen(3000, () => console.log('Example app listening on port 3000!'));