@@ -35,29 +35,37 @@ function tenantIdFromToken(token) {
3535 return normalizeGuid ( payload && payload . tid ) ;
3636}
3737
38- function runCli ( command , args , { execFile = execFileSync , platform = process . platform } = { } ) {
38+ function runPacAuthWho ( { execFile = execFileSync , platform = process . platform } = { } ) {
3939 if ( platform === 'win32' ) {
40- // On Windows, `az` is commonly an `az.cmd` shim, while PAC installs as
41- // `pac.exe`. Node's execFile can miss shell-resolved shims even when the same
42- // command works interactively. Route through cmd.exe with fixed,
43- // code-controlled arguments so the helper matches what users run manually.
44- const executable = command === 'pac' ? 'pac.exe' : `${ command } .cmd` ;
45- return execFile ( 'cmd.exe' , [ '/d' , '/s' , '/c' , executable , ...args ] , { encoding : 'utf8' , timeout : 15000 } ) ;
40+ // PAC installs as pac.exe on Windows. Route through cmd.exe so PATH lookup
41+ // matches the user's terminal while keeping the executable literal fixed for
42+ // the secure-process validator.
43+ return execFile ( 'cmd.exe' , [ '/d' , '/s' , '/c' , 'pac.exe' , 'auth' , 'who' ] , { encoding : 'utf8' , timeout : 15000 } ) ;
4644 }
47- return execFile ( command , args , { encoding : 'utf8' , timeout : 15000 } ) ;
45+ return execFile ( 'pac' , [ 'auth' , 'who' ] , { encoding : 'utf8' , timeout : 15000 } ) ;
46+ }
47+
48+ function runAzAccountShowTenant ( { execFile = execFileSync , platform = process . platform } = { } ) {
49+ if ( platform === 'win32' ) {
50+ // Azure CLI installs an az.cmd shim on Windows. Route through cmd.exe so PATH
51+ // lookup matches the user's terminal while keeping the executable literal
52+ // fixed for the secure-process validator.
53+ return execFile ( 'cmd.exe' , [ '/d' , '/s' , '/c' , 'az.cmd' , 'account' , 'show' , '--query' , 'tenantId' , '-o' , 'tsv' ] , { encoding : 'utf8' , timeout : 15000 } ) ;
54+ }
55+ return execFile ( 'az' , [ 'account' , 'show' , '--query' , 'tenantId' , '-o' , 'tsv' ] , { encoding : 'utf8' , timeout : 15000 } ) ;
4856}
4957
5058function getPacTenantId ( execFile = execFileSync , platform = process . platform ) {
5159 try {
52- return parsePacTenantId ( runCli ( 'pac' , [ 'auth' , 'who' ] , { execFile, platform } ) ) ;
60+ return parsePacTenantId ( runPacAuthWho ( { execFile, platform } ) ) ;
5361 } catch {
5462 return null ;
5563 }
5664}
5765
5866function getAzAccountTenantId ( execFile = execFileSync , platform = process . platform ) {
5967 try {
60- return normalizeGuid ( runCli ( 'az' , [ 'account' , 'show' , '--query' , 'tenantId' , '-o' , 'tsv' ] , { execFile, platform } ) ) ;
68+ return normalizeGuid ( runAzAccountShowTenant ( { execFile, platform } ) ) ;
6169 } catch {
6270 return null ;
6371 }
@@ -106,7 +114,8 @@ function validateCliTenantAlignment({ envUrl, token, pacTenantId, azTenantId, to
106114module . exports = {
107115 decodeJwtPayload,
108116 parsePacTenantId,
109- runCli,
117+ runAzAccountShowTenant,
118+ runPacAuthWho,
110119 tenantIdFromToken,
111120 validateCliTenantAlignment,
112121} ;
0 commit comments