@@ -587,7 +587,7 @@ async def run(
587587 self .connection_settings .generate_temp_token
588588 and self .connection_settings .auth_token is not None
589589 ):
590- temp_token = await _get_temp_token (self .connection_settings . auth_token )
590+ temp_token = await _get_temp_token (self .connection_settings )
591591 token = f"Bearer { temp_token } "
592592 extra_headers ["Authorization" ] = token
593593
@@ -670,18 +670,30 @@ async def send_message(self, message_type: str, data: Optional[Any] = None):
670670 raise exc
671671
672672
673- async def _get_temp_token (api_key ):
673+ async def _get_temp_token (connection_settings : ConnectionSettings ):
674674 """
675675 Used to get a temporary token from management platform api for SaaS users
676676 """
677677 version = get_version ()
678- mp_api_url = os .getenv ("SM_MANAGEMENT_PLATFORM_URL" , "https://mp.speechmatics.com" )
678+ mp_api_url = os .getenv ("SM_MANAGEMENT_PLATFORM_URL" , connection_settings .mp_url )
679+
680+ assert mp_api_url , "Management platform URL not set"
681+
679682 endpoint = mp_api_url + "/v1/api_keys"
680683 params = {"type" : "rt" , "sm-sdk" : f"python-{ version } " }
681- body = {"ttl" : 60 }
682- headers = {"Authorization" : f"Bearer { api_key } " , "Content-Type" : "application/json" }
684+ payload : dict [str , Union [str , int ]] = {"ttl" : 60 }
685+
686+ if connection_settings .region :
687+ payload ["region" ] = connection_settings .region
688+ if connection_settings .client_ref :
689+ payload ["client_ref" ] = connection_settings .client_ref
690+
691+ headers = {
692+ "Authorization" : f"Bearer { connection_settings .auth_token } " ,
693+ "Content-Type" : "application/json" ,
694+ }
683695 # pylint: disable=no-member
684- response = httpx .post (endpoint , json = body , params = params , headers = headers )
696+ response = httpx .post (endpoint , json = payload , params = params , headers = headers )
685697 response .raise_for_status ()
686698 response .read ()
687699 key_object = response .json ()
0 commit comments