Skip to content

Commit 032418d

Browse files
marlenekohMarlene
and
Marlene
authored
fix: add scopes to device auth (#599)
* feat: add scopes to device authorization * fix: add types --------- Co-authored-by: Marlene <marlene.koh@xtraman.org>
1 parent d44ae42 commit 032418d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/keycloak/keycloak_openid.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def register_client(self, token: str, payload: dict):
822822
)
823823
return raise_error_from_response(data_raw, KeycloakPostError)
824824

825-
def device(self):
825+
def device(self, scope: str = ""):
826826
"""Get device authorization grant.
827827
828828
The device endpoint is used to obtain a user code verification and user authentication.
@@ -837,11 +837,13 @@ def device(self):
837837
https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow
838838
https://github.com/keycloak/keycloak-community/blob/main/design/oauth2-device-authorization-grant.md#how-to-try-it
839839
840+
:param scope: Scope of authorization request, split with the blank space
841+
:type scope: str
840842
:returns: Device Authorization Response
841843
:rtype: dict
842844
"""
843845
params_path = {"realm-name": self.realm_name}
844-
payload = {"client_id": self.client_id}
846+
payload = {"client_id": self.client_id, "scope": scope}
845847

846848
payload = self._add_secret_key(payload)
847849
data_raw = self.connection.raw_post(URL_DEVICE.format(**params_path), data=payload)
@@ -1464,7 +1466,7 @@ async def a_register_client(self, token: str, payload: dict):
14641466
)
14651467
return raise_error_from_response(data_raw, KeycloakPostError)
14661468

1467-
async def a_device(self):
1469+
async def a_device(self, scope: str = ""):
14681470
"""Get device authorization grant asynchronously.
14691471
14701472
The device endpoint is used to obtain a user code verification and user authentication.
@@ -1479,11 +1481,13 @@ async def a_device(self):
14791481
https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow
14801482
https://github.com/keycloak/keycloak-community/blob/main/design/oauth2-device-authorization-grant.md#how-to-try-it
14811483
1484+
:param scope: Scope of authorization request, split with the blank space
1485+
:type scope: str
14821486
:returns: Device Authorization Response
14831487
:rtype: dict
14841488
"""
14851489
params_path = {"realm-name": self.realm_name}
1486-
payload = {"client_id": self.client_id}
1490+
payload = {"client_id": self.client_id, "scope": scope}
14871491

14881492
payload = self._add_secret_key(payload)
14891493
data_raw = await self.connection.a_raw_post(URL_DEVICE.format(**params_path), data=payload)

0 commit comments

Comments
 (0)