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

added functionality for scope base permission and group based policies #430

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e013b18
added create_client_authz_group_based_policy, create_client_authz_sco…
Apr 12, 2023
6ef75fe
added update_client_authz_role_based_policy, update_client_authz_grou…
Apr 13, 2023
2eae560
forgot to push urls
Apr 13, 2023
cde8b14
added update_resource_server
Apr 24, 2023
ffe3204
test: fixed tests for new keycloak (#438)
ryshoooo Apr 28, 2023
e0c2725
fix(pyproject.toml): loose requests pgk and remove urllib3 as depende…
karimelhajoui63 Apr 28, 2023
85855e6
docs: changelog update
ryshoooo Apr 28, 2023
a7407cd
feat: Add get and delete methods for client authz resources (#435)
sras1599 Apr 28, 2023
7711fe4
docs: changelog update
ryshoooo Apr 28, 2023
d0f1080
fix: Initializing KeycloakAdmin without server_url (#439)
arminshoughi May 1, 2023
8814991
docs: changelog update
ryshoooo May 1, 2023
c289ed6
docs: Fixed a typo (#441)
michitaro May 8, 2023
d80b855
fix: issue with app engine reported in #440 (#442)
isccarrasco May 9, 2023
50ad533
docs: changelog update
ryshoooo May 9, 2023
b5e1904
fix: Fixes `Authorization.load_config` breaking if a scope based perm…
sras1599 May 15, 2023
fcf521f
docs: changelog update
ryshoooo May 15, 2023
89a6082
perf: improve performance of get_user_id (#449)
mjeanroy May 28, 2023
a0ed022
docs: changelog update
ryshoooo May 28, 2023
fe31e7d
fix: do not swap realm for user_realm when logging in with a client s…
gboor May 28, 2023
ad3f898
docs: changelog update
ryshoooo May 28, 2023
b9bacdb
fix: relax the version constraints
ryshoooo-adamatics May 28, 2023
06d320a
chore: bump the deprecation to v4
ryshoooo-adamatics May 28, 2023
803aa3d
ci: include the package
ryshoooo-adamatics May 28, 2023
a179569
docs: changelog update
ryshoooo May 28, 2023
d247539
refactor: Exchange token method
AndreasBBS May 28, 2023
9cf0577
docs: changelog update
ryshoooo May 28, 2023
00521ea
feat: Add query to get users group method and permit pagination (#444)
anapaulamendes Jun 23, 2023
223eeaa
docs: changelog update
ryshoooo Jun 23, 2023
683d021
test: fix the user group pagination test
ryshoooo Jun 23, 2023
4add676
test: fix the token test
ryshoooo Jun 23, 2023
7a87fac
chore: deps update
ryshoooo Jun 23, 2023
b7ec87e
fix: remove duplicate slash in URL_ADMIN_IDP (#459)
jasminapegan Jun 23, 2023
6146010
docs: changelog update
ryshoooo Jun 23, 2023
e802222
feat: Implement missing admin method create_client_authz_scope_based_…
cainotis Jun 23, 2023
a9b364e
docs: changelog update
ryshoooo Jun 23, 2023
2e2735a
feat: added KeycloakAdmin.update_client_authz_resource() (#462)
cainotis Jun 27, 2023
66eae8e
docs: changelog update
ryshoooo Jun 27, 2023
c087ebf
feat: add an optional search criteria to the get_realm_roles function…
SalemWafi Nov 13, 2023
8bd71e0
docs: changelog update
ryshoooo Nov 13, 2023
ca8cfb3
chore: Add direct "setuptools" dependency (#505)
pehala Nov 13, 2023
e579296
chore: make audience in token exchange optional (#499)
pitwegner Nov 13, 2023
17ad531
chore: Add typing to Keycloak admin connection (#496)
jackylamhk Nov 13, 2023
67d888c
chore: add typing for KeycloakAdmin connection attribute (#492)
Kevin-Bannier Nov 13, 2023
a082cc9
feat: Update dynamic client using registration access token (#491)
mklassen Nov 13, 2023
b158c6a
docs: Allow the verify attribute to be bool or string #479 (#480)
waza-ari Nov 13, 2023
37fc295
docs: changelog update
ryshoooo Nov 13, 2023
e272547
feat: add KeycloakAdmin.get_idp() (#478)
derlin Nov 13, 2023
cb6f8d2
docs: changelog update
ryshoooo Nov 13, 2023
a724051
chore: Feat/create permission for scopes (#400)
Hadeer-Elsaeed Nov 13, 2023
6885ada
chore: implement get_realm_role_groups method (#464)
enzossatolo Nov 13, 2023
8d5942b
chore: implement partialImport request (#456)
Ujifman Nov 13, 2023
0f43cee
chore: add missing get_realm_role_by_id to KeycloakAdmin (#468)
cainotis Nov 13, 2023
a9180de
chore: loosen requests-toolbelt dependency (#473)
mnaser Nov 13, 2023
71442ab
docs: Remove removed function attribute from README.md (#469)
vitorespindola Nov 13, 2023
3bcc0a1
chore: Feat/support admin events (#474)
zimaldone Nov 13, 2023
73af7b9
chore: Add device authorization grant (#454)
manonmichel Nov 13, 2023
dee59c6
fix: Ci/fix tests (#506)
ryshoooo Nov 13, 2023
734ecf5
docs: changelog update
ryshoooo Nov 13, 2023
78b3e9e
fix: no prints
ryshoooo Nov 13, 2023
8ad784c
feat: realm changing helpers
ryshoooo Nov 13, 2023
1e74b43
docs: changelog update
ryshoooo Nov 13, 2023
026e3c0
added create_client_authz_group_based_policy, create_client_authz_sco…
Apr 12, 2023
563e7e6
added get_child_groups
Jan 8, 2024
6a8831b
added pagination to get_child_groups
Jan 9, 2024
80a6c94
fixed wrong url in get_child_groups
Jan 9, 2024
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
175 changes: 175 additions & 0 deletions src/keycloak/keycloak_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,163 @@ def create_client_authz_role_based_policy(self, client_id, payload, skip_exists=
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)

def create_client_authz_group_based_policy(self, client_id, payload, skip_exists=False):
"""Create group-based policy of client.

Payload example::

payload={
"type": "group",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"name": "Policy-1",
"groups": [
{
"id": id
}
]
}

:param client_id: id in ClientRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_clientrepresentation
:type client_id: str
:param payload: No Document
:type payload: dict
:param skip_exists: Skip creation in case the object exists
:type skip_exists: bool
:return: Keycloak server response
:rtype: bytes

"""
params_path = {"realm-name": self.realm_name, "id": client_id}

data_raw = self.connection.raw_post(
urls_patterns.URL_ADMIN_CLIENT_AUTHZ_GROUP_BASED_POLICY.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)

def update_client_authz_role_based_policy(self, client_id, policy_id, payload):
"""Update role-based policy of client.

Payload example::

payload={
"id": "policy_id"
"type": "role",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"name": "Policy-1",
"roles": [
{
"id": id
}
]
}

:param client_id: id in ClientRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_clientrepresentation
:type client_id: str
:param payload: No Document
:type payload: dict
:param skip_exists: Skip creation in case the object exists
:type skip_exists: bool
:return: Keycloak server response
:rtype: bytes

"""
params_path = {"realm-name": self.connection.realm_name, "id": client_id,"policy_id": policy_id}

data_raw = self.connection.raw_put(
urls_patterns.URL_ADMIN_CLIENT_AUTHZ_ROLE_BASED_POLICY_UPDATE.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakPostError, expected_codes=[201],
)

def update_client_authz_group_based_policy(self, client_id,policy_id, payload):
"""Update group-based policy of client.

Payload example::

payload={
"id": "policy_id"
"type": "group",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"name": "Policy-1",
"groups": [
{
"id": id
}
]
}

:param client_id: id in ClientRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_clientrepresentation
:type client_id: str
:param payload: No Document
:type payload: dict
:param skip_exists: Skip creation in case the object exists
:type skip_exists: bool
:return: Keycloak server response
:rtype: bytes

"""
params_path = {"realm-name": self.realm_name, "id": client_id, "policy_id": policy_id}

data_raw = self.connection.raw_put(
urls_patterns.URL_ADMIN_CLIENT_AUTHZ_GROUP_BASED_POLICY_UPDATE.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakPostError, expected_codes=[201]
)

def create_client_authz_scope_based_permission(self, client_id, payload, skip_exists=False):
"""Create scope-based permission of client.

Payload example::

payload={
"type": "resource",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"name": "Permission-Name",
"scopes": [
scope_id
],
"policies": [
policy_id
]

:param client_id: id in ClientRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_clientrepresentation
:type client_id: str
:param payload: PolicyRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_policyrepresentation
:type payload: dict
:param skip_exists: Skip creation in case the object already exists
:type skip_exists: bool
:return: Keycloak server response
:rtype: bytes

"""
params_path = {"realm-name": self.realm_name, "id": client_id}

data_raw = self.connection.raw_post(
urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SCOPE_BASED_PERMISSION.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)



def create_client_authz_resource_based_permission(self, client_id, payload, skip_exists=False):
"""Create resource-based permission of client.

Expand Down Expand Up @@ -1938,6 +2095,24 @@ def update_client(self, client_id, payload):
)
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])

def update_resource_server(self, client_id, payload):
"""Update a client.

:param client_id: Client id
:type client_id: str
:param payload: payload
:type payload: dict

:return: Http response
:rtype: bytes
"""
params_path = {"realm-name": self.connection.realm_name, "id": client_id}
data_raw = self.connection.raw_put(
urls_patterns.URL_ADMIN_CLIENT_AUTHZ.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])


def delete_client(self, client_id):
"""Get representation of the client.

Expand Down
4 changes: 4 additions & 0 deletions src/keycloak/urls_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
URL_ADMIN_CLIENT_AUTHZ_PERMISSIONS = URL_ADMIN_CLIENT_AUTHZ + "/permission?max=-1"
URL_ADMIN_CLIENT_AUTHZ_POLICIES = URL_ADMIN_CLIENT_AUTHZ + "/policy?max=-1&permission=false"
URL_ADMIN_CLIENT_AUTHZ_ROLE_BASED_POLICY = URL_ADMIN_CLIENT_AUTHZ + "/policy/role?max=-1"
URL_ADMIN_CLIENT_AUTHZ_ROLE_BASED_POLICY_UPDATE = URL_ADMIN_CLIENT_AUTHZ + "/policy/role/{policy_id}"
URL_ADMIN_CLIENT_AUTHZ_GROUP_BASED_POLICY = URL_ADMIN_CLIENT_AUTHZ + "/policy/group?max=-1"
URL_ADMIN_CLIENT_AUTHZ_GROUP_BASED_POLICY_UPDATE = URL_ADMIN_CLIENT_AUTHZ + "/policy/group/{policy_id}"
URL_ADMIN_CLIENT_AUTHZ_SCOPE_BASED_PERMISSION = URL_ADMIN_CLIENT_AUTHZ + "/permission/scope?max=-1"
URL_ADMIN_CLIENT_AUTHZ_RESOURCE_BASED_PERMISSION = (
URL_ADMIN_CLIENT_AUTHZ + "/permission/resource?max=-1"
)
Expand Down