@@ -140,37 +140,44 @@ def _run_sf_command(args: list[str], description: str) -> dict:
140140 )
141141 return dict (data )
142142
143- # Get instanceUrl from sf org display
143+ # Get org info from sf org display
144144 display_data = _run_sf_command (
145145 ["sf" , "org" , "display" , "--target-org" , self .sf_cli_org , "--json" ],
146146 "sf org display" ,
147147 )
148- instance_url = display_data .get ("result" , {}).get ("instanceUrl" )
148+ result_data = display_data .get ("result" , {})
149+ instance_url = result_data .get ("instanceUrl" )
149150 if not instance_url :
150151 raise RuntimeError (
151152 f"'sf org display' did not return an instance URL "
152153 f"for org '{ self .sf_cli_org } '"
153154 )
154155
155- # Get access token via show-access-token (newer SF CLI versions
156- # redact the token in sf org display)
157- token_data = _run_sf_command (
158- [
159- "sf" ,
160- "org" ,
161- "auth" ,
162- "show-access-token" ,
163- "--target-org" ,
164- self .sf_cli_org ,
165- "--json" ,
166- ],
167- "sf org auth show-access-token" ,
168- )
169- access_token = token_data .get ("result" , {}).get ("accessToken" )
156+ # Try show-access-token first (SF CLI >= 2.136.6); fall back to the
157+ # token from sf org display (older CLIs don't redact it).
158+ access_token = None
159+ try :
160+ token_data = _run_sf_command (
161+ [
162+ "sf" ,
163+ "org" ,
164+ "auth" ,
165+ "show-access-token" ,
166+ "--target-org" ,
167+ self .sf_cli_org ,
168+ "--json" ,
169+ ],
170+ "sf org auth show-access-token" ,
171+ )
172+ access_token = token_data .get ("result" , {}).get ("accessToken" )
173+ except RuntimeError :
174+ # Command not available on older SF CLI versions
175+ access_token = result_data .get ("accessToken" )
176+
170177 if not access_token :
171178 raise RuntimeError (
172- f"'sf org auth show-access-token' did not return an access token "
173- f"for org ' { self . sf_cli_org } ' "
179+ f"Could not obtain an access token for org ' { self . sf_cli_org } '. "
180+ f"Upgrade SF CLI to 2.136.6+ or ensure the org is authenticated. "
174181 )
175182
176183 return AccessTokenResponse (access_token = access_token , instance_url = instance_url )
0 commit comments