Skip to content

Repository: keycloak

  • In the env variabels in the server Rancher/Azure Container APP add the following:
Terminal window
JAVA_OPTS_APPEND = -Djboss.jgroups.azure_ping.storage_account_name=BLOB_STORAGE_NAME -Djboss.jgroups.azure_ping.storage_access_key=BLOB_STORAGE_ACCESS_KEY -Djboss.jgroups.azure_ping.container=THE_CONTAINER_NAME
  • In the env variabels in the server Rancher/Azure Container APP add the following:
Terminal window
KC_DB=postgres
KC_DB_USERNAME=KEYCLOAK_DB_USERNAME
KC_DB_PASSWORD=KEYCLOAK_DB_PASSWORD
KC_DB_URL=jdbc:postgresql://{HOST}:{PORT}/{DB_NAME}?&sslmode=verify-ca&sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory
KC_HTTP_ENABLED=true
KC_PROXY_HEADERS=xforwarded
KC_HOSTNAME_DEBUG=true

TO ENABLE IT

  • in the start the variable must be added
Terminal window
REALM_PROVIDER='the-name-of-the-realm'
...
...
...
KC_DB=postgres
KC_DB_USERNAME=KEYCLOAK_DB_USERNAME
KC_DB_PASSWORD=KEYCLOAK_DB_PASSWORD
...
  • later after starting key claok only create a realm that has the same name as the REALM_PROVIDER variable. and it is ready to use.

======================

  • Build the project in mvn

  • Copy the JAR file to the provider folder in the keycloak server

  • This extension provids an API fuctionality to get the realm for a user.

    • For example if the realm that we activated this functionality on is called realm-provider then the API is available on the following endpoint: http://{KEYCLOAK-HOST}/realms/realm-provider/user-extention/realms

      • The call is a GET request it must take a query parameter called user stating the username or the email.
      • The complete call is http://{KEYCLOAK-HOST}/realms/realm-provider/user-extention/realms?user={username}
      • As we stated in the environment variable REALM_PROVIDER the value is the realm name that this functionality is available on, so the call is only available on the realm that is stated in the environment variable. If the same call is done using another realm name, the call will return a 404 error.
    • The response is a json object as follows:

      1. If no query parameter is provided, the response is a 400 error.
      {
      "error": "User parameter is required"
      }
      1. If the user is not found, the response is a 404 error.
      {
      "error": "User not found in any realm"
      }
      1. If the user is found in only ONE realm, the response is a 200 status code with the following response:
      {
      "hint": "realm-name",
      "status": "ok"
      }

      Hint: the hint param is the realm name that the user is found in.

      1. If the user is found in MORE than one realm, the response is a 200 status code with the following response:
      {
      "message": "User found in multiple realms",
      "status": "ok"
      }

      Hint: in this case the user have to state the realm so we can use the login directly to correct realm.