Skip to content

Commit 91c988b

Browse files
authored
Merge pull request #410 from AzureAD/http-cache
Bypass device authorization flow, for real
2 parents 2b056ba + 05b6143 commit 91c988b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

msal/throttled_http_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ def __init__(self, http_client, http_cache):
100100
# acquire_token_silent(..., force_refresh=True) pattern.
101101
str(kwargs.get("params")) + str(kwargs.get("data"))),
102102
),
103-
expires_in=lambda result=None, data=None, **ignored:
103+
expires_in=lambda result=None, kwargs=None, **ignored:
104104
60
105105
if result.status_code == 400
106106
# Here we choose to cache exact HTTP 400 errors only (rather than 4xx)
107107
# because they are the ones defined in OAuth2
108108
# (https://datatracker.ietf.org/doc/html/rfc6749#section-5.2)
109109
# Other 4xx errors might have different requirements e.g.
110110
# "407 Proxy auth required" would need a key including http headers.
111-
and not( # Exclude Device Flow cause its retry is expected and regulated
112-
isinstance(data, dict) and data.get("grant_type") == DEVICE_AUTH_GRANT
111+
and not( # Exclude Device Flow whose retry is expected and regulated
112+
isinstance(kwargs.get("data"), dict)
113+
and kwargs["data"].get("grant_type") == DEVICE_AUTH_GRANT
113114
)
114115
and "retry-after" not in set( # Leave it to the Retry-After decorator
115116
h.lower() for h in getattr(result, "headers", {}).keys())

tests/test_throttled_http_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def test_device_flow_retry_should_not_be_cached(self):
163163
http_cache = {}
164164
http_client = DummyHttpClient(status_code=400)
165165
http_client = ThrottledHttpClient(http_client, http_cache)
166-
resp1 = http_client.get(
166+
resp1 = http_client.post(
167167
"https://example.com", data={"grant_type": DEVICE_AUTH_GRANT})
168-
resp2 = http_client.get(
168+
resp2 = http_client.post(
169169
"https://example.com", data={"grant_type": DEVICE_AUTH_GRANT})
170170
logger.debug(http_cache)
171171
self.assertNotEqual(resp1.text, resp2.text, "Should return a new response")

0 commit comments

Comments
 (0)