Skip to content

Commit 70fd4d1

Browse files
ashok672rayluo
andauthored
Add claims challenge parameter in initiate_device_flow (#839)
* Add claims challenge parameter in initiate_device_flow * Update msal/application.py Co-authored-by: Ray Luo <[email protected]> * Update msal/oauth2cli/oauth2.py Co-authored-by: Ray Luo <[email protected]> * Update msal/application.py Co-authored-by: Ray Luo <[email protected]> * Update oauth2.py * Update oauth2.py --------- Co-authored-by: Ray Luo <[email protected]>
1 parent b1d8cd7 commit 70fd4d1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

msal/application.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ def _acquire_token_interactive_via_broker(
23262326
auth_scheme=auth_scheme,
23272327
**data)
23282328

2329-
def initiate_device_flow(self, scopes=None, **kwargs):
2329+
def initiate_device_flow(self, scopes=None, *, claims_challenge=None, **kwargs):
23302330
"""Initiate a Device Flow instance,
23312331
which will be used in :func:`~acquire_token_by_device_flow`.
23322332
@@ -2341,6 +2341,8 @@ def initiate_device_flow(self, scopes=None, **kwargs):
23412341
flow = self.client.initiate_device_flow(
23422342
scope=self._decorate_scope(scopes or []),
23432343
headers={msal.telemetry.CLIENT_REQUEST_ID: correlation_id},
2344+
data={"claims": _merge_claims_challenge_and_capabilities(
2345+
self._client_capabilities, claims_challenge)},
23442346
**kwargs)
23452347
flow[self.DEVICE_FLOW_CORRELATION_ID] = correlation_id
23462348
return flow

msal/oauth2cli/oauth2.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class Client(BaseClient): # We choose to implement all 4 grants in 1 class
305305
grant_assertion_encoders = {GRANT_TYPE_SAML2: BaseClient.encode_saml_assertion}
306306

307307

308-
def initiate_device_flow(self, scope=None, **kwargs):
308+
def initiate_device_flow(self, scope=None, *, data=None, **kwargs):
309309
# type: (list, **dict) -> dict
310310
# The naming of this method is following the wording of this specs
311311
# https://tools.ietf.org/html/draft-ietf-oauth-device-flow-12#section-3.1
@@ -323,8 +323,11 @@ def initiate_device_flow(self, scope=None, **kwargs):
323323
DAE = "device_authorization_endpoint"
324324
if not self.configuration.get(DAE):
325325
raise ValueError("You need to provide device authorization endpoint")
326+
_data = {"client_id": self.client_id, "scope": self._stringify(scope or [])}
327+
if isinstance(data, dict):
328+
_data.update(data)
326329
resp = self._http_client.post(self.configuration[DAE],
327-
data={"client_id": self.client_id, "scope": self._stringify(scope or [])},
330+
data=_data,
328331
headers=dict(self.default_headers, **kwargs.pop("headers", {})),
329332
**kwargs)
330333
flow = json.loads(resp.text)

0 commit comments

Comments
 (0)