-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanifest.js
47 lines (42 loc) · 1.35 KB
/
manifest.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
const egLogger = require('express-gateway/lib/logger')
const session = require('express-session')
const Keycloak = require('keycloak-connect')
module.exports = {
version: '1.2.0',
init: function (pluginContext) {
const memoryStore = new session.MemoryStore()
const kcConfig = pluginContext.settings.kcConfigParams
const keycloak = new Keycloak({ store: memoryStore }, kcConfig || null )
const logger = egLogger.createLoggerWithLabel('[EG:plugins:keycloak]')
pluginContext.registerGatewayRoute((app)=>{
logger.debug('Register',pluginContext)
logger.info('Registering keycloak middleware')
app.use(keycloak.middleware())
})
pluginContext.registerPolicy({
name: 'keycloak-protect',
schema: {
$id: 'http://express-gateway.io/schemas/policy/keycloak-protect-policy.json',
type: 'object',
properties: {
roles: {
type: 'string'
}
}
},
policy: (actionParams)=>{
return keycloak.protect(actionParams.roles || null)
}
})
},
policies:['keycloak-protect'],
schema: {
$id: 'http://express-gateway.io/schemas/plugin/keycloak-connect.json',
kcConfigParams: {
title: 'keycloak-connect config parameters',
description: 'Parameters in case no config file exists',
type: 'object'
},
required:[]
}
};