-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
34 lines (29 loc) · 1.16 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
const express = require('express');
const jwt = require('jsonwebtoken');
const app = express();
const port = 3000;
const { auth } = require('express-openid-connect');
const config = {
authRequired: false,
auth0Logout: true,
secret: 'a long, randomly-generated string', // retrieve it from the environment or enter it here
baseURL: 'http://localhost:3000',
clientID: 'clientId copied from Auth0 application', // retrieve it from the environment or enter it here
issuerBaseURL: 'issuerBaseURL copied from Auth0 application' // retrieve it from the environment or enter it here
};
// auth router attaches /login, /logout, and /callback routes to the baseURL
app.use(auth(config));
const gitbookSignKey = 'gitbook signing key' // retrieve it from the environment or enter it here
app.get('/', (req, res) => {
if (req.oidc.isAuthenticated()) {
const token = jwt.sign({}, gitbookSignKey, { expiresIn: '1h' });
const redirectURL = `https://example-url.gitbook.io/example/?jwt_token=${token}`;
res.redirect(redirectURL);
}
else {
res.redirect('/login')
}
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});