-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (37 loc) · 1.14 KB
/
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
45
46
const express = require('express');
require('dotenv').config();
const jwt = require("express-jwt");
const jwksRsa = require("jwks-rsa");
const checkScope = require("express-jwt-authz");
const checkJwt = jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,//Used to prevent attacks
jwksUri: `https://${process.env.REACT_APP_AUTH0_DOMAIN}/.well-known/jwks.json`
}),
audience: process.env.REACT_APP_AUTH0_AUDIENCE,
issuser: `https://${process.env.REACT_APP_AUTH0_DOMAIN}`,
algorithms: ["RS256"]
});
const app = express();
app.get("/public", function(req, res) {
res.json({
message: "Hello from a public API!"
});
});
app.get("/private", checkJwt, function(req, res) {
res.json({
message: "Hello from a private API!"
});
});
app.get("/course", checkJwt, checkScope(["read:courses"]), function(req,res) {
res.json({
courses: [
{id: 1 , title: "Building apps with react and redux" },
{id: 1 , title: "Creating Reusables React Components" },
]
});
});
app.listen(3001);
console.log('API server listening on ' + process.env.REACT_APP_API_URL);