@@ -46,7 +46,6 @@ def __init__(self,
4646 proxy : str = None ,
4747 gateway : str = "gateway" ):
4848 """Initialize an instance of organization."""
49- self .gateway = gateway
5049 # set debug and file if specified and let the calling application dictate logging handlers
5150 self .log_file = log_file
5251 self .debug = debug
@@ -81,6 +80,9 @@ def __init__(self,
8180 else :
8281 self .verify = False
8382
83+ self .gateway = gateway
84+ self .logger .debug (f"got 'gateway' param { self .gateway } " )
85+
8486 epoch = round (time .time ())
8587 self .expiry_seconds = 0 # initialize a placeholder for remaining seconds until expiry
8688 client_id = None
@@ -258,6 +260,8 @@ def __init__(self,
258260 if not re .search (self .environment , self .audience ):
259261 self .logger .error (f"mismatched audience URL '{ self .audience } ' and environment '{ self .environment } '" )
260262 exit (1 )
263+ else :
264+ self .logger .debug (f"found audience already computed '{ self .audience } ' and matching environment '{ self .environment } '" )
261265
262266 # the purpose of this try-except block is to soft-fail all attempts
263267 # to parse the JWT, which is intended for the API, not this
@@ -290,12 +294,15 @@ def __init__(self,
290294 self .logger .debug (f"using environment parsed from authenticationUrl: { self .environment } " )
291295 # re: scope: we're not using scopes with Cognito, but a non-empty value is required;
292296 # hence "/ignore-scope"
293- scope = f"https://{ self . gateway } .{ self .environment } .netfoundry.io//ignore-scope"
294- self .logger .debug (f"computed scope URL from gateway and environment: { scope } " )
297+ scope = f"https://gateway.{ self .environment } .netfoundry.io//ignore-scope"
298+ self .logger .debug (f"computed scope URL from ' gateway' and environment: { scope } " )
295299 # we can gather the URL of the API from the first part of the scope string by
296300 # dropping the scope suffix
297301 self .audience = scope .replace (r'/ignore-scope' , '' )
298- self .logger .debug (f"using audience parsed from authenticationUrl: { self .audience } " )
302+ self .logger .debug (f"computed audience from authenticationUrl sans the trailing '/ignore-scope': { self .audience } " )
303+ audience_parts = self .audience .split ('.' )
304+ self .audience = '.' .join ([f"https://{ self .gateway } " ]+ audience_parts [1 :])
305+ self .logger .debug (f"computed audience with substituted param 'gateway': { self .audience } " )
299306 assertion = {
300307 "scope" : scope ,
301308 "grant_type" : "client_credentials"
0 commit comments