4
4
# ------------------------------------
5
5
import socket
6
6
import sys
7
- from typing import Dict , Any , Mapping , Union
7
+ from typing import Dict , Any , Mapping , Union , cast
8
8
import msal
9
9
10
10
from azure .core .exceptions import ClientAuthenticationError
14
14
) # pylint:disable=protected-access
15
15
from azure .identity ._exceptions import CredentialUnavailableError # pylint:disable=protected-access
16
16
from 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
18
18
19
19
20
20
class PopTokenRequestOptions (TokenRequestOptions ):
@@ -50,6 +50,8 @@ class InteractiveBrowserBrokerCredential(_InteractiveBrowserCredential):
50
50
unspecified, users will authenticate to an Azure development application.
51
51
:keyword str login_hint: a username suggestion to pre-fill the login page's username/email address field. A user
52
52
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.
53
55
:paramtype cache_persistence_options: ~azure.identity.TokenCachePersistenceOptions
54
56
:keyword int timeout: seconds to wait for the user to complete authentication. Defaults to 300 (5 minutes).
55
57
: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:
80
82
81
83
@wrap_exceptions
82
84
def _request_token (self , * scopes : str , ** kwargs : Any ) -> Dict :
83
- scopes = list (scopes ) # type: ignore
85
+ scopes_list = list (scopes )
84
86
claims = kwargs .get ("claims" )
85
87
pop = kwargs .get ("pop" )
86
- app = self ._get_app (** kwargs )
88
+ app = cast ( msal . PublicClientApplication , self ._get_app (** kwargs ) )
87
89
port = self ._parsed_url .port if self ._parsed_url else None
88
90
auth_scheme = None
89
91
if pop :
90
92
auth_scheme = msal .PopAuthScheme (
91
93
http_method = pop ["resource_request_method" ], url = pop ["resource_request_url" ], nonce = pop ["nonce" ]
92
94
)
93
- if sys .platform .startswith ("win" ):
95
+ if sys .platform .startswith ("win" ) or is_wsl () :
94
96
if self ._use_default_broker_account :
95
97
try :
96
98
result = app .acquire_token_interactive (
97
- scopes = scopes ,
99
+ scopes = scopes_list ,
98
100
login_hint = self ._login_hint ,
99
101
claims_challenge = claims ,
100
102
timeout = self ._timeout ,
@@ -110,7 +112,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
110
112
pass
111
113
try :
112
114
result = app .acquire_token_interactive (
113
- scopes = scopes ,
115
+ scopes = scopes_list ,
114
116
login_hint = self ._login_hint ,
115
117
claims_challenge = claims ,
116
118
timeout = self ._timeout ,
@@ -133,7 +135,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
133
135
else :
134
136
try :
135
137
result = app .acquire_token_interactive (
136
- scopes = scopes ,
138
+ scopes = scopes_list ,
137
139
login_hint = self ._login_hint ,
138
140
claims_challenge = claims ,
139
141
timeout = self ._timeout ,
@@ -144,9 +146,9 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
144
146
auth_scheme = auth_scheme ,
145
147
)
146
148
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 ) )
148
150
result = app .acquire_token_interactive (
149
- scopes = scopes ,
151
+ scopes = scopes_list ,
150
152
login_hint = self ._login_hint ,
151
153
claims_challenge = claims ,
152
154
timeout = self ._timeout ,
0 commit comments