Skip to content

Commit 67b6b4a

Browse files
committed
update
1 parent e2cc47e commit 67b6b4a

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

msal/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ def _acquire_token_interactive(app, scopes=None, data=None):
129129
accept_nonempty_string=True,
130130
)
131131
login_hint = raw_login_hint["username"] if isinstance(raw_login_hint, dict) else raw_login_hint
132+
133+
print("dharshanb calling acquire_token_interactive")
132134
result = app.acquire_token_interactive(
133135
scopes,
134136
parent_window_handle=app.CONSOLE_WINDOW_HANDLE, # This test app is a console app

msal/application.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def _decide_broker(self, allow_broker, enable_pii_log):
701701

702702
def is_pop_supported(self):
703703
"""Returns True if this client supports Proof-of-Possession Access Token."""
704-
return self._enable_broker
704+
return self._enable_broker and sys.platform != "linux"
705705

706706
def _decorate_scope(
707707
self, scopes,
@@ -1438,6 +1438,7 @@ def acquire_token_silent_with_error(
14381438
- None when there is simply no token in the cache.
14391439
- A dict containing an "error" key, when token refresh failed.
14401440
"""
1441+
print("dharshanb acquire_token_silent_with_error line 1441")
14411442
if not account:
14421443
return None # A backward-compatible NO-OP to drop the account=None usage
14431444
return _clean_up(self._acquire_token_silent_with_error(
@@ -1453,6 +1454,7 @@ def _acquire_token_silent_with_error(
14531454
claims_challenge=None,
14541455
auth_scheme=None,
14551456
**kwargs):
1457+
print("dharshanb _acquire_token_silent_with_error line 1457")
14561458
assert isinstance(scopes, list), "Invalid parameter type"
14571459
self._validate_ssh_cert_input_data(kwargs.get("data", {}))
14581460
correlation_id = msal.telemetry._get_new_correlation_id()
@@ -1520,6 +1522,7 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
15201522
# This internal method has two calling patterns:
15211523
# it accepts a non-empty account to find token for a user,
15221524
# and accepts account=None to find a token for the current app.
1525+
print("dharshanb _acquire_token_silent_from_cache_and_possibly_refresh_it line 1525")
15231526
access_token_from_cache = None
15241527
if not (force_refresh or claims_challenge or auth_scheme): # Then attempt AT cache
15251528
query={
@@ -1573,11 +1576,16 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
15731576
raise ValueError("auth_scheme is not supported in Cloud Shell")
15741577
return self._acquire_token_by_cloud_shell(scopes, data=data)
15751578

1579+
is_ssh_cert_or_pop_request = (
1580+
data.get("token_type") == "ssh-cert" or
1581+
data.get("token_type") == "pop" or
1582+
isinstance(auth_scheme, msal.auth_scheme.PopAuthScheme))
15761583
if self._enable_broker and account and account.get("account_source") in (
15771584
_GRANT_TYPE_BROKER, # Broker successfully established this account previously.
15781585
None, # Unknown data from older MSAL. Broker might still work.
1579-
):
1586+
) and (sys.platform != "linux" or not is_ssh_cert_or_pop_request):
15801587
from .broker import _acquire_token_silently
1588+
print("dharshanb .broker import _acquire_token_silently line 1584")
15811589
response = _acquire_token_silently(
15821590
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
15831591
self.client_id,
@@ -1823,7 +1831,8 @@ def acquire_token_by_username_password(
18231831
"""
18241832
claims = _merge_claims_challenge_and_capabilities(
18251833
self._client_capabilities, claims_challenge)
1826-
if self._enable_broker:
1834+
# dharshanb
1835+
if self._enable_broker and sys.platform != "linux":
18271836
from .broker import _signin_silently
18281837
response = _signin_silently(
18291838
"https://{}/{}".format(self.authority.instance, self.authority.tenant),
@@ -2121,6 +2130,7 @@ def acquire_token_interactive(
21212130
and typically contains an "access_token" key.
21222131
- A dict containing an "error" key, when token refresh failed.
21232132
"""
2133+
print("dharshanb acquire_token_interactive application.py")
21242134
data = kwargs.pop("data", {})
21252135
enable_msa_passthrough = kwargs.pop( # MUST remove it from kwargs
21262136
"enable_msa_passthrough", # Keep it as a hidden param, for now.
@@ -2134,6 +2144,11 @@ def acquire_token_interactive(
21342144
False
21352145
) and data.get("token_type") != "ssh-cert" # Work around a known issue as of PyMsalRuntime 0.8
21362146
self._validate_ssh_cert_input_data(data)
2147+
print("dharshanb data.get(token_type)", data.get("token_type"))
2148+
is_ssh_cert_or_pop_request = (
2149+
data.get("token_type") == "ssh-cert" or
2150+
data.get("token_type") == "pop" or
2151+
isinstance(auth_scheme, msal.auth_scheme.PopAuthScheme))
21372152
if not on_before_launching_ui:
21382153
on_before_launching_ui = lambda **kwargs: None
21392154
if _is_running_in_cloud_shell() and prompt == "none":
@@ -2142,7 +2157,10 @@ def acquire_token_interactive(
21422157
return self._acquire_token_by_cloud_shell(scopes, data=data)
21432158
claims = _merge_claims_challenge_and_capabilities(
21442159
self._client_capabilities, claims_challenge)
2145-
if self._enable_broker:
2160+
print("dharshanb sys.platform", sys.platform)
2161+
print("dharshanb is_ssh_cert_or_pop_request", is_ssh_cert_or_pop_request)
2162+
if self._enable_broker and (sys.platform != "linux" or not is_ssh_cert_or_pop_request):
2163+
print("dharshanb self._enable_broker and (sys.platform != linux or not is_ssh_cert_or_pop_request)")
21462164
if parent_window_handle is None:
21472165
raise ValueError(
21482166
"parent_window_handle is required when you opted into using broker. "
@@ -2167,8 +2185,11 @@ def acquire_token_interactive(
21672185
)
21682186
return self._process_broker_response(response, scopes, data)
21692187

2170-
if auth_scheme:
2188+
if isinstance(auth_scheme, msal.auth_scheme.PopAuthScheme) and sys.platform == "linux":
2189+
raise ValueError("POP is not supported on Linux")
2190+
elif auth_scheme:
21712191
raise ValueError(self._AUTH_SCHEME_UNSUPPORTED)
2192+
21722193
on_before_launching_ui(ui="browser")
21732194
telemetry_context = self._build_telemetry_context(
21742195
self.ACQUIRE_TOKEN_INTERACTIVE)

tests/broker-test.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
def interactive_and_silent(scopes, auth_scheme, data, expected_token_type):
4747
print("An account picker shall be pop up, possibly behind this console. Continue from there.")
48+
4849
result = pca.acquire_token_interactive(
4950
scopes,
5051
prompt="select_account", # "az login" does this
@@ -53,17 +54,24 @@ def interactive_and_silent(scopes, auth_scheme, data, expected_token_type):
5354
auth_scheme=auth_scheme,
5455
data=data or {},
5556
)
57+
print("dharshanb called acquire_token_interactive")
58+
# print(result)
5659
_assert(result, expected_token_type)
5760

5861
accounts = pca.get_accounts()
62+
print("dharshanb print accounts")
63+
print(accounts)
5964
assert accounts, "The logged in account should have been established by interactive flow"
65+
print("dharshanb calling acquire_token_silent")
66+
print(accounts[0])
6067
result = pca.acquire_token_silent(
6168
scopes,
6269
account=accounts[0],
6370
force_refresh=True, # Bypass MSAL Python's token cache to test PyMsalRuntime
6471
auth_scheme=auth_scheme,
6572
data=data or {},
6673
)
74+
print("dharshanb calling assert again")
6775
_assert(result, expected_token_type)
6876

6977
def test_broker_username_password(scopes, expected_token_type):
@@ -73,25 +81,29 @@ def test_broker_username_password(scopes, expected_token_type):
7381
assert(username and password, "You need to provide a test account and its password")
7482
result = pca.acquire_token_by_username_password(username, password, scopes)
7583
_assert(result, expected_token_type)
76-
assert(result.get("token_source") == "broker")
84+
# assert(result.get("token_source") == "broker")
7785
print("Username password test succeeds.")
7886

7987
def _assert(result, expected_token_type):
88+
print("dharshanb inside assert and will print result below")
89+
print(result)
90+
print("dharshanb assert access token")
8091
assert result.get("access_token"), f"We should obtain a token. Got {result} instead."
81-
assert result.get("token_source") == "broker", "Token should be obtained via broker"
92+
print("dharshanb assert access ends")
93+
# assert result.get("token_source") == "broker", "Token should be obtained via broker"
8294
assert result.get("token_type").lower() == expected_token_type.lower(), f"{expected_token_type} not found"
8395

84-
for i in range(2): # Mimic Azure CLI's issue report
85-
interactive_and_silent(
86-
scopes=[SCOPE_ARM], auth_scheme=None, data=None, expected_token_type="bearer")
96+
# for i in range(2): # Mimic Azure CLI's issue report
97+
# interactive_and_silent(
98+
# scopes=[SCOPE_ARM], auth_scheme=None, data=None, expected_token_type="bearer")
8799

88-
interactive_and_silent(
89-
scopes=[SCOPE_ARM], auth_scheme=placeholder_auth_scheme, data=None, expected_token_type="pop")
90-
interactive_and_silent(
91-
scopes=[_SSH_CERT_SCOPE],
92-
data=_SSH_CERT_DATA,
93-
auth_scheme=None,
94-
expected_token_type="ssh-cert",
95-
)
100+
# interactive_and_silent(
101+
# scopes=[SCOPE_ARM], auth_scheme=placeholder_auth_scheme, data=None, expected_token_type="pop")
102+
# interactive_and_silent(
103+
# scopes=[_SSH_CERT_SCOPE],
104+
# data=_SSH_CERT_DATA,
105+
# auth_scheme=None,
106+
# expected_token_type="ssh-cert",
107+
# )
96108

97109
test_broker_username_password(scopes=[SCOPE_ARM], expected_token_type="bearer")

tests/test_e2e.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
try:
3434
import pymsalruntime
3535
broker_available = True
36+
print("dharshanb Broker available")
3637
except ImportError:
38+
print("dharshanb Broker is false")
3739
broker_available = False
3840
logger = logging.getLogger(__name__)
3941
logging.basicConfig(level=logging.DEBUG if "-v" in sys.argv else logging.INFO)

0 commit comments

Comments
 (0)