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) #41

Closed
ssoerensen opened this issue Dec 8, 2023 · 1 comment
Assignees

Comments

@ssoerensen
Copy link
Contributor

ssoerensen commented Dec 8, 2023

src/context/AuthContextProvider.tsx

https://my.msg-david.de/confluence/display/GAIAX/PoC%3A+Authentication+via+Keycloak

@devbysp
Copy link
Contributor

devbysp commented Sep 30, 2024

Pull Request

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 pushed a commit that referenced this issue Sep 30, 2024
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 pushed a commit that referenced this issue Oct 7, 2024
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 pushed a commit that referenced this issue Oct 8, 2024
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]>
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

No branches or pull requests

4 participants