44# ------------------------------------
55import socket
66import sys
7- from typing import Dict , Any , Mapping , Union
7+ from typing import Dict , Any , Mapping , Union , cast
88import msal
99
1010from azure .core .exceptions import ClientAuthenticationError
1414) # pylint:disable=protected-access
1515from azure .identity ._exceptions import CredentialUnavailableError # pylint:disable=protected-access
1616from azure .identity ._internal .utils import within_dac # pylint:disable=protected-access
17- from ._utils import wrap_exceptions , resolve_tenant
17+ from ._utils import wrap_exceptions , resolve_tenant , is_wsl
1818
1919
2020class PopTokenRequestOptions (TokenRequestOptions ):
@@ -50,6 +50,8 @@ class InteractiveBrowserBrokerCredential(_InteractiveBrowserCredential):
5050 unspecified, users will authenticate to an Azure development application.
5151 :keyword str login_hint: a username suggestion to pre-fill the login page's username/email address field. A user
5252 may still log in with a different username.
53+ :keyword cache_persistence_options: configuration for persistent token caching. If unspecified, the credential
54+ will cache tokens in memory.
5355 :paramtype cache_persistence_options: ~azure.identity.TokenCachePersistenceOptions
5456 :keyword int timeout: seconds to wait for the user to complete authentication. Defaults to 300 (5 minutes).
5557 :keyword int parent_window_handle: If your app is a GUI app running on Windows 10+ or macOS, you
@@ -80,21 +82,21 @@ def __init__(self, **kwargs: Any) -> None:
8082
8183 @wrap_exceptions
8284 def _request_token (self , * scopes : str , ** kwargs : Any ) -> Dict :
83- scopes = list (scopes ) # type: ignore
85+ scopes_list = list (scopes )
8486 claims = kwargs .get ("claims" )
8587 pop = kwargs .get ("pop" )
86- app = self ._get_app (** kwargs )
88+ app = cast ( msal . PublicClientApplication , self ._get_app (** kwargs ) )
8789 port = self ._parsed_url .port if self ._parsed_url else None
8890 auth_scheme = None
8991 if pop :
9092 auth_scheme = msal .PopAuthScheme (
9193 http_method = pop ["resource_request_method" ], url = pop ["resource_request_url" ], nonce = pop ["nonce" ]
9294 )
93- if sys .platform .startswith ("win" ):
95+ if sys .platform .startswith ("win" ) or is_wsl () :
9496 if self ._use_default_broker_account :
9597 try :
9698 result = app .acquire_token_interactive (
97- scopes = scopes ,
99+ scopes = scopes_list ,
98100 login_hint = self ._login_hint ,
99101 claims_challenge = claims ,
100102 timeout = self ._timeout ,
@@ -110,7 +112,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
110112 pass
111113 try :
112114 result = app .acquire_token_interactive (
113- scopes = scopes ,
115+ scopes = scopes_list ,
114116 login_hint = self ._login_hint ,
115117 claims_challenge = claims ,
116118 timeout = self ._timeout ,
@@ -133,7 +135,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
133135 else :
134136 try :
135137 result = app .acquire_token_interactive (
136- scopes = scopes ,
138+ scopes = scopes_list ,
137139 login_hint = self ._login_hint ,
138140 claims_challenge = claims ,
139141 timeout = self ._timeout ,
@@ -144,9 +146,9 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
144146 auth_scheme = auth_scheme ,
145147 )
146148 except Exception : # pylint: disable=broad-except
147- app = self ._disable_broker_on_app (** kwargs )
149+ app = cast ( msal . PublicClientApplication , self ._disable_broker_on_app (** kwargs ) )
148150 result = app .acquire_token_interactive (
149- scopes = scopes ,
151+ scopes = scopes_list ,
150152 login_hint = self ._login_hint ,
151153 claims_challenge = claims ,
152154 timeout = self ._timeout ,
0 commit comments