Skip to content

Commit

Permalink
Ensure public mode does not crash due to missing configuration keys
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Ho <[email protected]>
  • Loading branch information
jujaga committed Oct 15, 2021
1 parent 492a763 commit 2fde4fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ if (process.env.NODE_ENV !== 'test') {

// Use Keycloak OIDC Middleware
if (config.has('keycloak.enabled')) {
log.info('Running in authenticated mode');
app.use(keycloak.middleware());
} else {
log.info('Running in public mode');
}

// Block requests until service is ready and mounted
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const Keycloak = require('keycloak-connect');
module.exports = new Keycloak({}, {
bearerOnly: true,
'confidential-port': 0,
clientId: config.get('keycloak.clientId'),
clientId: config.has('keycloak.clientId') ? config.get('keycloak.clientId') : undefined,
'policy-enforcer': {},
realm: config.get('keycloak.realm'),
realmPublicKey: config.has('keycloak.publicKey') ? config.get('keycloak.publicKey') : undefined,
secret: config.get('keycloak.clientSecret'),
secret: config.has('keycloak.clientSecret') ? config.get('keycloak.clientSecret') : undefined,
serverUrl: config.get('keycloak.serverUrl'),
'ssl-required': 'external',
'use-resource-role-mappings': true,
Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const healthRouter = require('./health');
const { protect } = require('../../middleware/authorization');
const { getDocs, getJsonSpec, getYamlSpec } = require('../../middleware/openapi');

const clientId = config.get('keycloak.clientId');
const clientId = config.has('keycloak.enabled') ? config.get('keycloak.clientId') : '';
const version = 'v1';

/** Base Responder */
Expand Down

0 comments on commit 2fde4fd

Please sign in to comment.