forked from goldbergjeffrey/qlik-embed-oauth-spa
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (40 loc) · 1.29 KB
/
index.js
File metadata and controls
48 lines (40 loc) · 1.29 KB
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
47
48
const __dirname = new URL('.', import.meta.url).pathname;
import { auth } from 'express-openid-connect';
import express from 'express';
import { join } from 'path';
import { config } from './config.js';
const Auth0config = {
authRequired: false,
auth0Logout: true,
secret: config.sessionSecret,
baseURL: `https://${config.HOST}`,
clientID: config.clientId,
clientSecret: config.clientSecret,
issuerBaseURL: `https://${config.idpUri}`,
authorizationParams: {
response_type: 'code',
scope: 'openid profile email'
},
attemptSilentLogin: true,
};
// This example uses express.js to provide the proxy services between the
// frontend web application and Qlik Cloud REST endpoints and websocket
// connections to the engine.
const app = express();
app.use(express.static("public"));
// auth router attaches /login, /logout, and /callback routes to the baseURL
app.use(auth(Auth0config));
// req.isAuthenticated is provided from the auth router
app.get('/', (req, res) => {
if(req.oidc.isAuthenticated()) {
res.sendFile(join(__dirname, 'index.html'))
return
}
res.oidc.login({ returnTo: '/' })
});
app.get('/oauth-callback', (req, res) => {
res.sendFile('/public/oauth-callback.html')
})
const server = app.listen(process.env.PORT, () => {
console.log('Backend started');
})