@@ -68,25 +68,31 @@ def acquire_token(self, scopes, claims_challenge=None, **kwargs):
6868 # browser is available.
6969 if 'data' in kwargs :
7070 logger .warning (ex )
71- logger .warning ("\n The default web browser has been opened at %s for scope '%s'. "
72- "Please continue the login in the web browser." ,
73- self ._msal_app .authority .authorization_endpoint , ' ' .join (scopes ))
74-
75- from .util import read_response_templates
76- success_template , error_template = read_response_templates ()
77-
78- result = self ._msal_app .acquire_token_interactive (
79- scopes , login_hint = self ._account ['username' ],
80- port = 8400 if self ._msal_app .authority .is_adfs else None ,
81- success_template = success_template , error_template = error_template , ** kwargs )
82- check_result (result )
83-
71+ result = self ._acquire_token_interactive (scopes , ** kwargs )
8472 # For other scenarios like Storage Conditional Access MFA step-up, do not
8573 # launch browser, but show the error message and `az login` command instead.
8674 else :
8775 raise
8876 return result
8977
78+ def _acquire_token_interactive (self , scopes , ** kwargs ):
79+ from .util import read_response_templates
80+ success_template , error_template = read_response_templates ()
81+
82+ def _prompt_launching_ui (ui = None , ** _ ):
83+ logger .warning (
84+ "Interactively acquiring token for scope '%s'. Continue the login in the %s." ,
85+ ' ' .join (scopes ), 'web browser' if ui == 'browser' else 'pop-up window' )
86+
87+ result = self ._msal_app .acquire_token_interactive (
88+ scopes , login_hint = self ._account ['username' ],
89+ port = 8400 if self ._msal_app .authority .is_adfs else None ,
90+ success_template = success_template , error_template = error_template ,
91+ parent_window_handle = self ._msal_app .CONSOLE_WINDOW_HANDLE ,
92+ on_before_launching_ui = _prompt_launching_ui ,
93+ ** kwargs )
94+ check_result (result )
95+ return result
9096
9197class ServicePrincipalCredential : # pylint: disable=too-few-public-methods
9298
0 commit comments