-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
49 lines (41 loc) · 1.01 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import express from 'express';
import bodyParser from 'body-parser';
import session from 'express-session';
import Keycloak from 'keycloak-connect';
const app = express();
app.use(bodyParser.json());
const memoryStore = new session.MemoryStore();
app.use(
session({
secret: 'secretKey',
resave: false,
saveUninitialized: true,
store: memoryStore
})
);
const keycloak = new Keycloak({
store: memoryStore
});
app.use(
keycloak.middleware({
logout: '/logout',
admin: '/'
})
);
app.get('/api/unsecured', function(req, res) {
res.json({ message: 'This is an unsecured endpoint payload' });
});
app.get('/api/user', keycloak.protect('realm:user'), function(req, res) {
res.json({ message: 'This is an USER endpoint payload' });
});
app.get('/api/admin', keycloak.protect('realm:admin'), function(req, res) {
res.json({ message: 'This is an ADMIN endpoint payload' });
});
app.listen(3000, err => {
if (err) {
console.error(err);
}
{
console.log(`APP Listen to port : 3000`);
}
});