diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 24f3f47..cdbd9ea 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -1755,10 +1755,50 @@ class KeycloakAdmin: params_path = {"realm-name": self.realm_name, "id": client_id} data_raw = self.raw_post( - URL_ADMIN_CLIENT_PROTOCOL_MAPPER.format(**params_path), data=json.dumps(payload)) + URL_ADMIN_CLIENT_PROTOCOL_MAPPERS.format(**params_path), data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201]) + + def update_client_mapper(self, client_id, mapper_id, payload): + """ + Update client mapper + :param client_id: The id of the client + :param client_mapper_id: The id of the mapper to be deleted + :param payload: ProtocolMapperRepresentation + :return: Keycloak server response + """ + + params_path = { + "realm-name": self.realm_name, + "id": self.client_id, + "protocol-mapper-id": mapper_id, + } + data_raw = self.raw_put( + URL_ADMIN_CLIENT_PROTOCOL_MAPPER.format(**params_path), data=json.dumps(payload)) + + return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) + + def remove_client_mapper(self, client_id, client_mapper_id): + """ + Removes a mapper from the client + https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_protocol_mappers_resource + :param client_id: The id of the client + :param client_mapper_id: The id of the mapper to be deleted + :return: Keycloak server response + """ + + params_path = { + "realm-name": self.realm_name, + "id": client_id, + "protocol-mapper-id": mapper_id + } + + data_raw = self.raw_delete( + URL_ADMIN_CLIENT_PROTOCOL_MAPPER.format(**params_path)) + + return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) + def generate_client_secrets(self, client_id): """ diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index ac0b16c..bfaadc1 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -76,7 +76,8 @@ URL_ADMIN_CLIENT_AUTHZ_RESOURCES = URL_ADMIN_CLIENT + "/authz/resource-server/re URL_ADMIN_CLIENT_SERVICE_ACCOUNT_USER = URL_ADMIN_CLIENT + "/service-account-user" URL_ADMIN_CLIENT_CERTS = URL_ADMIN_CLIENT + "/certificates/{attr}" URL_ADMIN_CLIENT_INSTALLATION_PROVIDER = URL_ADMIN_CLIENT + "/installation/providers/{provider-id}" -URL_ADMIN_CLIENT_PROTOCOL_MAPPER = URL_ADMIN_CLIENT + "/protocol-mappers/models" +URL_ADMIN_CLIENT_PROTOCOL_MAPPERS = URL_ADMIN_CLIENT + "/protocol-mappers/models" +URL_ADMIN_CLIENT_PROTOCOL_MAPPER = URL_ADMIN_CLIENT_PROTOCOL_MAPPERS + "/{protocol-mapper-id}" URL_ADMIN_CLIENT_SCOPES = "admin/realms/{realm-name}/client-scopes" URL_ADMIN_CLIENT_SCOPE = URL_ADMIN_CLIENT_SCOPES + "/{scope-id}"