@@ -102,6 +102,42 @@ export async function getAzureManagedIdentityToken(
102102 return result ;
103103}
104104
105+ export function getAzureCliToken (
106+ scope = 'https://cognitiveservices.azure.com/.default' ,
107+ check : string
108+ ) : { token : string ; error : string | null } {
109+ const result : { token : string ; error : string | null } = {
110+ token : '' ,
111+ error : null ,
112+ } ;
113+
114+ try {
115+ // Note: Azure CLI auth only works in Node.js runtime
116+ // This will not work in Cloudflare Workers or other edge runtimes
117+ if ( typeof process === 'undefined' || ! process . versions ?. node ) {
118+ result . error = 'Azure CLI authentication requires Node.js runtime' ;
119+ return result ;
120+ }
121+
122+ const { execSync } = require ( 'child_process' ) ;
123+
124+ // Execute Azure CLI command to get access token
125+ const command = `az account get-access-token --resource ${ scope . replace ( '/.default' , '' ) } ` ;
126+ const output = execSync ( command , { encoding : 'utf-8' } ) ;
127+
128+ const tokenData = JSON . parse ( output ) ;
129+ result . token = tokenData . accessToken ;
130+ } catch ( error : any ) {
131+ result . error = error ?. message || String ( error ) ;
132+ console . error ( 'getAzureCliToken error: ' , result . error ) ;
133+ console . error (
134+ 'Make sure Azure CLI is installed and you are logged in using "az login"'
135+ ) ;
136+ }
137+
138+ return result ;
139+ }
140+
105141export const getAccessToken = async (
106142 credentials : AzureCredentials ,
107143 check : string ,
@@ -142,5 +178,9 @@ export const getAccessToken = async (
142178 ) ;
143179 }
144180
181+ if ( azureAuthMode === 'azure_cli' ) {
182+ tokenResult = getAzureCliToken ( scope , check ) ;
183+ }
184+
145185 return tokenResult ;
146186} ;
0 commit comments