@@ -226,55 +226,68 @@ def logout(args: Namespace) -> None:
226226def status (args : Namespace ) -> None :
227227 auth = FabAuth ()
228228 tenant_id = auth .get_tenant_id ()
229+ identity_type = auth .get_identity_type () or "N/A"
229230
230- def __get_token_info (scope ):
231- try :
232- token = auth .get_access_token (scope , interactive_renew = False )
233- except FabricCLIError as e :
234- if e .status_code in [
235- fab_constant .ERROR_UNAUTHORIZED ,
236- fab_constant .ERROR_AUTHENTICATION_FAILED ,
237- ]:
238- return {}
239- else :
240- raise e
241- if isinstance (token , str ):
242- token = token .encode () # Ensure bytes type
243- return _get_token_info_from_bearer_token (token ) if token else {}
244-
245- token_info = __get_token_info (fab_constant .SCOPE_FABRIC_DEFAULT )
246-
247- upn = token_info .get ("upn" ) or "N/A"
248- oid = token_info .get ("oid" ) or "N/A"
249- tid = token_info .get ("tid" , tenant_id ) or "N/A"
250- appid = token_info .get ("appid" ) or "N/A"
251-
252- def __mask_token (scope ):
253- try :
254- token = auth .get_access_token (scope , interactive_renew = False )
255- except FabricCLIError as e :
256- if e .status_code in [
257- fab_constant .ERROR_UNAUTHORIZED ,
258- fab_constant .ERROR_AUTHENTICATION_FAILED ,
259- ]:
260- return "N/A"
261- else :
262- raise e
263- if isinstance (token , str ):
264- token = token .encode () # Ensure bytes type
265- return (
266- token [:4 ].decode () + "************************************"
267- if token
268- else "N/A"
269- )
231+ # Suppress noisy Azure SDK stderr logging during status checks
232+ # (AzureCliCredential logs "Please run 'az login'" before raising)
233+ import logging
234+
235+ azure_logger = logging .getLogger ("azure.identity" )
236+ original_level = azure_logger .level
237+ azure_logger .setLevel (logging .CRITICAL )
238+
239+ try :
240+
241+ def __get_token_info (scope ):
242+ try :
243+ token = auth .get_access_token (scope , interactive_renew = False )
244+ except FabricCLIError as e :
245+ if e .status_code in [
246+ fab_constant .ERROR_UNAUTHORIZED ,
247+ fab_constant .ERROR_AUTHENTICATION_FAILED ,
248+ ]:
249+ return {}
250+ else :
251+ raise e
252+ if isinstance (token , str ):
253+ token = token .encode () # Ensure bytes type
254+ return _get_token_info_from_bearer_token (token ) if token else {}
255+
256+ token_info = __get_token_info (fab_constant .SCOPE_FABRIC_DEFAULT )
257+
258+ upn = token_info .get ("upn" ) or "N/A"
259+ oid = token_info .get ("oid" ) or "N/A"
260+ tid = token_info .get ("tid" , tenant_id ) or "N/A"
261+ appid = token_info .get ("appid" ) or "N/A"
262+
263+ def __mask_token (scope ):
264+ try :
265+ token = auth .get_access_token (scope , interactive_renew = False )
266+ except FabricCLIError as e :
267+ if e .status_code in [
268+ fab_constant .ERROR_UNAUTHORIZED ,
269+ fab_constant .ERROR_AUTHENTICATION_FAILED ,
270+ ]:
271+ return "N/A"
272+ else :
273+ raise e
274+ if isinstance (token , str ):
275+ token = token .encode () # Ensure bytes type
276+ return (
277+ token [:4 ].decode () + "************************************"
278+ if token
279+ else "N/A"
280+ )
281+
282+ fabric_secret = __mask_token (fab_constant .SCOPE_FABRIC_DEFAULT )
283+ storage_secret = __mask_token (fab_constant .SCOPE_ONELAKE_DEFAULT )
284+ azure_secret = __mask_token (fab_constant .SCOPE_AZURE_DEFAULT )
270285
271- fabric_secret = __mask_token (fab_constant .SCOPE_FABRIC_DEFAULT )
272- storage_secret = __mask_token (fab_constant .SCOPE_ONELAKE_DEFAULT )
273- azure_secret = __mask_token (fab_constant .SCOPE_AZURE_DEFAULT )
286+ finally :
287+ azure_logger .setLevel (original_level )
274288
275289 # Check login status
276290 is_logged_in = fabric_secret != "N/A"
277- identity_type = auth .get_identity_type () or "N/A"
278291 login_status = (
279292 "✓ Logged in to app.fabric.microsoft.com"
280293 if is_logged_in
@@ -283,6 +296,11 @@ def __mask_token(scope):
283296 fab_ui .print_grey (login_status )
284297 if identity_type == "azure_cli" and is_logged_in :
285298 fab_ui .print_grey (f" Auth mode: Azure CLI (tenant: { tid } )" )
299+ elif identity_type == "azure_cli" and not is_logged_in :
300+ fab_ui .print_grey (
301+ " Azure CLI session expired or logged out. "
302+ "Run 'az login' then 'fab auth login --azure-cli' to re-authenticate."
303+ )
286304
287305 auth_data = {
288306 "logged_in" : is_logged_in ,
0 commit comments