Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Export keycloak config into a keycloak.json (remove hard coded config) #107

Conversation

devbysp
Copy link
Contributor

@devbysp devbysp commented Sep 30, 2024

Task

Solution

  • The aplication loads the configuration from the keycloak-config alisa with the following expression import keycloakConfig from 'keycloak-config';
  • The alias is set inside the webpack in the ''config-overrride.js' file.
    • If the app is started in 'production' env, for example is built with the command npm run build then started with the serve -s build or live-server build --host=localhost --port=3000, then the configuration is taken from the 'keycloak-config.production.json'.
    • If the application is started in 'development' env, for example started with the npm start, then the configuration is taken from the 'keycloak-config.json'.
  • The configuration for 'production' env is stored in the 'src/keycloak-config.production.json'
  • The configuration for 'developmen' env is stored in the 'src/keycloak-config.json'
  • The related 'webpack' configuration look like this:

config-overrides.js

module.exports = override(
  ...

  // Add Webpack alias for Keycloak configuration based on the environment
  (config) => {
    const isProduction = process.env.NODE_ENV === 'production';

    // Define the path to the correct keycloak-config based on the environment
    config.resolve.alias['keycloak-config'] = path.resolve(
      __dirname,
      isProduction
        ? 'src/keycloak-config.prod.json'   // Production environment
        : 'src/keycloak-config.json'        // Development environment
    );

    // Return the modified Webpack config
    return config;
  }
);
  • The keycloack config for 'development' enviroment looks like this:

src/keycloak-config.json

{
  "config": {
    "realm": "gaia-x",
    "clientId": "portal",
  },
  "initOptions": {
    "onLoad": "check-sso",
    "checkLoginIframe": false,
    "pkceMethod": "S256"
  }
}
  • The keycloak url is taken from the .env.
...
REACT_APP_KEYCLOAK_API_URL=https://fc-keycloak.gxfs.gx4fm.org/
...

@devbysp devbysp changed the base branch from main to feature/82-filter-based-on-values-from-shape September 30, 2024 14:12
@devbysp devbysp changed the base branch from feature/82-filter-based-on-values-from-shape to feature/82-filter-based-on-values-from-shape-3 September 30, 2024 14:13
@devbysp devbysp marked this pull request as ready for review September 30, 2024 14:14
@devbysp devbysp force-pushed the feature/41-API-Export-keycloak-config-into-a-keycloak.json branch from e73f9f5 to 11cd537 Compare October 7, 2024 04:05
devbysp and others added 3 commits October 8, 2024 07:03
…n-values-from-shape-3

Rework search Page Resources: Filter based on values from shape 3
Depending on the environment the app loads the corresponding json config file.

It is controlled by the webpack, see: 'config-overrides.js'

Signed-off-by: Zoltan Magyari <[email protected]>
@devbysp devbysp force-pushed the feature/41-API-Export-keycloak-config-into-a-keycloak.json branch from 11cd537 to 7da2f6b Compare October 8, 2024 06:33
@devbysp devbysp merged commit 610b949 into feature/82-filter-based-on-values-from-shape-3 Oct 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants