Skip to content

Commit 5528fe3

Browse files
committed
Adjust device flow api interface and behavior
1 parent cc23f9b commit 5528fe3

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

msal/application.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,17 @@ def initiate_device_flow(self, scopes=None, **kwargs):
265265
scope=decorate_scope(scopes or [], self.client_id),
266266
**kwargs)
267267

268-
def acquire_token_by_device_flow(
269-
self, flow, exit_condition=lambda: True, **kwargs):
270-
"""Obtain token by a device flow object, with optional polling effect.
268+
def acquire_token_by_device_flow(self, flow, **kwargs):
269+
"""Obtain token by a device flow object, with customizable polling effect.
271270
272271
Args:
273272
flow (dict):
274-
An object previously generated by initiate_device_flow(...).
275-
exit_condition (Callable):
276-
This method implements a loop to provide polling effect.
277-
The loop's exit condition is calculated by this callback.
278-
The default callback makes the loop run only once, i.e. no polling.
273+
A dict previously generated by initiate_device_flow(...).
274+
You can exit the polling loop early, by changing the value of
275+
its "expires_at" key to 0, at any time.
279276
"""
280277
return self.client.obtain_token_by_device_flow(
281-
flow, exit_condition=exit_condition,
278+
flow,
282279
data={"code": flow["device_code"]}, # 2018-10-4 Hack:
283280
# during transition period,
284281
# service seemingly need both device_code and code parameter.

tests/test_application.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ def test_device_flow(self):
142142

143143
duration = 30
144144
logging.warn("We will wait up to %d seconds for you to sign in" % duration)
145-
result = self.app.acquire_token_by_device_flow(
146-
flow,
147-
exit_condition=lambda end=time.time() + duration: time.time() > end)
145+
flow["expires_at"] = time.time() + duration # Shorten the time for quick test
146+
result = self.app.acquire_token_by_device_flow(flow)
148147
self.assertLoosely(
149148
result,
150149
assertion=lambda: self.assertIn('access_token', result),

0 commit comments

Comments
 (0)