message: API understands keycloak "admin" role
diff: @@ -2,9 +2,7 @@ const Keycloak = require('keycloak-connect');
  const Setup = require('keycloak-connect/middleware/setup');
  const GrantAttacher = require('keycloak-connect/middleware/grant-attacher');
  const R = require('ramda');
  -const {
  - getPermissionsForUser,
  -} = require('./util/auth');
  +const { getPermissionsForUser } = require('./util/auth');
  const lagoonRoutes =
  (process.env.LAGOON_ROUTES && process.env.LAGOON_ROUTES.split(',')) || [];
  @@ -13,13 +11,17 @@ const lagoonKeycloakRoute = lagoonRoutes.find(routes =>
  routes.includes('keycloak-'),
  );
  -const keycloak = new Keycloak({}, {
  +const keycloak = new Keycloak(
  + {},
  + {
  realm: 'lagoon',
  - serverUrl: lagoonKeycloakRoute || 'http://docker.for.mac.localhost:8088/auth',
  + serverUrl:
  + lagoonKeycloakRoute || 'http://docker.for.mac.localhost:8088/auth',
  clientId: 'lagoon-ui',
  publicClient: true,
  bearerOnly: true,
  -});
  + },
  +);
  // Override default of returning a 403
  keycloak.accessDenied = (req, res, next) => {
  @@ -38,26 +40,26 @@ const authWithKeycloak = async (req, res, next) => {
  try {
  const {
  content: {
  - lagoon: {
  - user_id: userId,
  - },
  + lagoon: { user_id: userId },
  + realm_access: { roles },
  },
  } = req.kauth.grant.access_token;
  - console.log(userId);
  const permissions = await getPermissionsForUser(dao, userId);
  if (R.isEmpty(permissions)) {
  res.status(401).send({
  - errors: [{
  + errors: [
  + {
  message: `Unauthorized - No permissions for user id ${userId}`,
  - }],
  + },
  + ],
  });
  return;
  }
  req.credentials = {
  - role: 'none',
  + role: R.contains('admin', roles) ? 'admin' : 'none',
  userId,
  // Read and write permissions
  permissions,
  @@ -66,9 +68,11 @@ const authWithKeycloak = async (req, res, next) => {
  next();
  } catch (e) {
  res.status(403).send({
  - errors: [{
  - message: `!Forbidden - Invalid Auth Token: ${e.message}`,
  - }],
  + errors: [
  + {
  + message: `Forbidden - Invalid Keycloak Token: ${e.message}`,
  + },
  + ],
  });
  }
  };
  