Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const apiPath = options && options.apiPath ? options.apiPath : '/graphql'
const tokenEndpoint = options && options.tokenEndpoint ? options.tokenEndpoint : false
this.log.info('Initializing Keycloak authentication')
const memoryStore = new session.MemoryStore()
expressRouter.use(session({
secret: this.keycloakConfig.secret || 'secret',
resave: false,
saveUninitialized: true,
store: memoryStore
}))
if (!this.keycloak) {
this.keycloak = new Keycloak({
store: memoryStore
}, this.keycloakConfig)
}
// Install general keycloak middleware
expressRouter.use(this.keycloak.middleware({
admin: apiPath
}))
// Protect the main route for all graphql services
// Disable unauthenticated access
expressRouter.use(apiPath, this.keycloak.protect())
if (tokenEndpoint) {
expressRouter.get('/token', this.keycloak.protect(), function (req, res) {
if (req.session && req.session['keycloak-token']) {
const apiPath = options && options.apiPath ? options.apiPath : '/graphql'
const tokenEndpoint = options && options.tokenEndpoint ? options.tokenEndpoint : false
this.log.info('Initializing Keycloak authentication')
const memoryStore = new session.MemoryStore()
expressRouter.use(session({
secret: this.keycloakConfig.secret || 'secret',
resave: false,
saveUninitialized: true,
store: memoryStore
}) as any)
if (!this.keycloak) {
this.keycloak = new Keycloak({
store: memoryStore
}, this.keycloakConfig)
}
// Install general keycloak middleware
expressRouter.use(this.keycloak.middleware({
admin: apiPath
}))
// Protect the main route for all graphql services
// Disable unauthenticated access
expressRouter.use(apiPath, this.keycloak.protect())
if (tokenEndpoint) {
expressRouter.get('/token', this.keycloak.protect(), function (req, res) {
if (req.session && req.session['keycloak-token']) {