Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scopes to device auth #599

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/keycloak/keycloak_openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def register_client(self, token: str, payload: dict):
)
return raise_error_from_response(data_raw, KeycloakPostError)

def device(self):
def device(self, scope: str = ""):
"""Get device authorization grant.

The device endpoint is used to obtain a user code verification and user authentication.
Expand All @@ -837,11 +837,13 @@ def device(self):
https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow
https://github.com/keycloak/keycloak-community/blob/main/design/oauth2-device-authorization-grant.md#how-to-try-it

:param scope: Scope of authorization request, split with the blank space
:type scope: str
:returns: Device Authorization Response
:rtype: dict
"""
params_path = {"realm-name": self.realm_name}
payload = {"client_id": self.client_id}
payload = {"client_id": self.client_id, "scope": scope}

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

async def a_device(self):
async def a_device(self, scope: str = ""):
"""Get device authorization grant asynchronously.

The device endpoint is used to obtain a user code verification and user authentication.
Expand All @@ -1479,11 +1481,13 @@ async def a_device(self):
https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow
https://github.com/keycloak/keycloak-community/blob/main/design/oauth2-device-authorization-grant.md#how-to-try-it

:param scope: Scope of authorization request, split with the blank space
:type scope: str
:returns: Device Authorization Response
:rtype: dict
"""
params_path = {"realm-name": self.realm_name}
payload = {"client_id": self.client_id}
payload = {"client_id": self.client_id, "scope": scope}

payload = self._add_secret_key(payload)
data_raw = await self.connection.a_raw_post(URL_DEVICE.format(**params_path), data=payload)
Expand Down
Loading