66import requests
77from aiohttp import hdrs , web
88from google .protobuf import json_format
9+ from jwt import PyJWK
910from jwt .algorithms import RSAAlgorithm
1011from temporalio .api .cloud .cloudservice .v1 import GetUsersRequest
1112from temporalio .api .common .v1 import Payloads
1819
1920TEMPORAL_CLIENT_CLOUD_API_VERSION = "2024-05-13-00"
2021
21- temporal_ops_address = "saas-api.tmprl.cloud:443"
22- if os .environ .get ("TEMPORAL_OPS_ADDRESS" ):
23- temporal_ops_address = os . environ . get ( "TEMPORAL_OPS_ADDRESS" )
22+ temporal_ops_address = (
23+ os .environ .get ("TEMPORAL_OPS_ADDRESS" ) or "saas-api.tmprl.cloud:443"
24+ )
2425
2526
2627def build_codec_server () -> web .Application :
@@ -76,8 +77,8 @@ async def decryption_authorized(email: str, namespace: str) -> bool:
7677
7778 def make_handler (fn : str ):
7879 async def handler (req : web .Request ):
79- namespace = req .headers .get ("x-namespace" )
80- auth_header = req .headers .get ("Authorization" )
80+ namespace = req .headers .get ("x-namespace" ) or "default"
81+ auth_header = req .headers .get ("Authorization" ) or ""
8182 _bearer , encoded = auth_header .split (" " )
8283
8384 # Extract the kid from the Auth header
@@ -90,20 +91,20 @@ async def handler(req: web.Request):
9091 jwks = requests .get (jwks_url ).json ()
9192
9293 # Extract Temporal Cloud's public key
93- public_key = None
94+ pyjwk = None
9495 for key in jwks ["keys" ]:
9596 if key ["kid" ] == kid :
9697 # Convert JWKS key to PEM format
97- public_key = RSAAlgorithm . from_jwk (key )
98+ pyjwk = PyJWK . from_dict (key )
9899 break
99100
100- if public_key is None :
101+ if pyjwk is None :
101102 raise ValueError ("Public key not found in JWKS" )
102103
103104 # Decode the jwt, verifying against Temporal Cloud's public key
104105 decoded = jwt .decode (
105106 encoded ,
106- public_key ,
107+ pyjwk . key ,
107108 algorithms = [algorithm ],
108109 audience = [
109110 "https://saas-api.tmprl.cloud" ,
@@ -156,7 +157,7 @@ async def handler(req: web.Request):
156157 ssl_context = ssl .create_default_context (ssl .Purpose .CLIENT_AUTH )
157158 ssl_context .check_hostname = False
158159 ssl_context .load_cert_chain (
159- os .environ .get ("SSL_PEM" ), os .environ .get ("SSL_KEY" )
160+ os .environ .get ("SSL_PEM" ) or "" , os .environ .get ("SSL_KEY" ) or ""
160161 )
161162
162163 web .run_app (
0 commit comments