Skip to content

Commit f037c59

Browse files
committed
Make Keycloak URL protocol configurable
1 parent 6765977 commit f037c59

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ pip install .
8181

8282
The application is packaged as an executable `app.py` script. Configuration is based on the following environment variables which should be set accordingly prior to starting:
8383

84-
| name | description |
85-
|--------------------------------|------------------------------------------------------|
86-
| KC_CLIENT_ID | Identifier of pygeopai client in Keycloak |
87-
| KC_CLIENT_SECRET | Secret of pygeopai client in Keycloak |
88-
| KC_TARGET_CLIENT_ID | Identifier of Data Management API client in Keycloak |
89-
| KC_HOSTNAME | Hostname of Keycloak Server (e.g. `keycloak:8080`) |
90-
| KC_HOSTNAME_PATH | Subpath of Keycloak Hostname (e.g. `/keycloak`) |
91-
| KC_REALM_NAME | Name of the Keycloak realm |
92-
| KOMMONITOR_DATA_MANAGEMENT_URL | URL of the KomMonitor Data Management API |
93-
| PROCESS_RESULTS_DIR | Directory to store process results |
94-
| PREFECT_API_URL | URL of the Prefect server |
84+
| name | description |
85+
|--------------------------------|-----------------------------------------------------------------|
86+
| KC_CLIENT_ID | Identifier of pygeopai client in Keycloak |
87+
| KC_CLIENT_SECRET | Secret of pygeopai client in Keycloak |
88+
| KC_TARGET_CLIENT_ID | Identifier of Data Management API client in Keycloak |
89+
| KC_HOSTNAME | Hostname of Keycloak Server (e.g. `keycloak:8080`) |
90+
| KC_HOSTNAME_PATH | Subpath of Keycloak Hostname (e.g. `/keycloak`) |
91+
| KC_URL_PROTOCOL | Whether to use 'http' (only for development purpose) or 'https' |
92+
| KC_REALM_NAME | Name of the Keycloak realm |
93+
| KOMMONITOR_DATA_MANAGEMENT_URL | URL of the KomMonitor Data Management API |
94+
| PROCESS_RESULTS_DIR | Directory to store process results |
95+
| PREFECT_API_URL | URL of the Prefect server |
9596

9697
After these variables are set run the app via
9798
```commandline

docker/dev.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
KC_HOSTNAME=demo.kommonitor.de
22
KC_HOSTNAME_PATH=/keycloak
3+
KC_URL_PROTOCOL=https
34
KC_REALM_NAME=kommonitor-demo
45
KC_CLIENT_ID=kommonitor-processor
56
KC_CLIENT_SECRET=demo.kommonitor.de

processor/auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
KC_HOSTNAME = os.getenv('KC_HOSTNAME', "keycloak:8443")
1313
KC_REALM_NAME = os.getenv('KC_REALM_NAME', "kommonitor-demo")
1414
KC_HOSTNAME_PATH = os.getenv('KC_HOSTNAME_PATH', "")
15+
KC_URL_PROTOCOL = os.getenv('KC_PROTOCOL', "https")
1516

1617

1718
class KomMonitorIntrospectTokenValidator(IntrospectTokenValidator):
1819
def introspect_token(self, token_string):
19-
url = f"https://{KC_HOSTNAME}{KC_HOSTNAME_PATH}/realms/{KC_REALM_NAME}/protocol/openid-connect/token/introspect"
20+
url = f"{KC_URL_PROTOCOL}://{KC_HOSTNAME}{KC_HOSTNAME_PATH}/realms/{KC_REALM_NAME}/protocol/openid-connect/token/introspect"
2021
data = {'token': token_string[7:], 'token_type_hint': 'access_token'}\
2122
if token_string.startswith('Bearer')\
2223
else {'token': token_string, 'token_type_hint': 'access_token'}

processor/process/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class KommonitorProcessConfig:
3434
KC_CLIENT_SECRET = os.getenv('KC_CLIENT_SECRET', "processor-secret")
3535
KC_TARGET_CLIENT_ID = os.getenv('KC_TARGET_CLIENT_ID', "kommonitor-data-management")
3636
KC_HOSTNAME = os.getenv('KC_HOSTNAME', "keycloak:8443")
37+
KC_URL_PROTOCOL = os.getenv('KC_PROTOCOL', "https")
3738
KC_REALM_NAME = os.getenv('KC_REALM_NAME', "kommonitor-demo")
3839
KC_HOSTNAME_PATH = os.getenv('KC_HOSTNAME_PATH', "")
3940
KOMMONITOR_DATA_MANAGEMENT_URL = os.getenv('KOMMONITOR_DATA_MANAGEMENT_URL', "http://localhost:8085/management/")
@@ -54,7 +55,7 @@ def data_management_client(logger: Logger, execute_request: schemas.ExecuteReque
5455

5556
logger.info(f"Requesting token for user with ID: {execute_request.properties.get('user_id', '')}")
5657

57-
http = f"https://{KC_HOSTNAME}{KC_HOSTNAME_PATH}/realms/{KC_REALM_NAME}/protocol/openid-connect/token"
58+
http = f"{KC_URL_PROTOCOL}://{KC_HOSTNAME}{KC_HOSTNAME_PATH}/realms/{KC_REALM_NAME}/protocol/openid-connect/token"
5859
a = requests.post(http, data=payload)
5960
a = a.json()
6061
token = a['access_token']

0 commit comments

Comments
 (0)