MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / _keycloak_url

Function _keycloak_url

e2e/python/oidc/oidc_auth_test.py:35–57  ·  view source on GitHub ↗

Derive the Keycloak URL from the gateway's stored OIDC issuer. The server validates the issuer claim in JWTs, so the token must be requested from the same base URL the server was configured with (typically the host IP, not localhost).

()

Source from the content-addressed store, hash-verified

33
34
35def _keycloak_url() -> str:
36 """Derive the Keycloak URL from the gateway's stored OIDC issuer.
37
38 The server validates the issuer claim in JWTs, so the token must be
39 requested from the same base URL the server was configured with
40 (typically the host IP, not localhost).
41 """
42 if url := os.environ.get("OPENSHELL_KEYCLOAK_URL"):
43 return url
44 cluster_name = os.environ.get("OPENSHELL_GATEWAY", "openshell")
45 metadata_path = (
46 _xdg_config_home() / "openshell" / "gateways" / cluster_name / "metadata.json"
47 )
48 if metadata_path.exists():
49 metadata = json.loads(metadata_path.read_text())
50 issuer = metadata.get("oidc_issuer", "")
51 if issuer:
52 # issuer is like "http://192.168.4.172:8180/realms/openshell"
53 # extract base URL before /realms/
54 idx = issuer.find("/realms/")
55 if idx > 0:
56 return issuer[:idx]
57 return "http://localhost:8180"
58
59
60TOKEN_ENDPOINT = (

Callers 1

oidc_auth_test.pyFile · 0.85

Calls 3

existsMethod · 0.80
_xdg_config_homeFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected