|
29 | 29 | import copy |
30 | 30 | import json |
31 | 31 | from builtins import isinstance |
32 | | -from typing import Optional |
| 32 | +from typing import Any, Dict, Optional |
33 | 33 |
|
34 | 34 | import deprecation |
35 | 35 | from requests_toolbelt import MultipartEncoder |
@@ -739,6 +739,27 @@ def update_mapper_in_idp(self, idp_alias, mapper_id, payload): |
739 | 739 |
|
740 | 740 | return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204]) |
741 | 741 |
|
| 742 | + def delete_mapper_to_idp(self, idp_alias: str, mapper_id: str) -> Dict[str, Any]: |
| 743 | + """Delete an IDP mapper. |
| 744 | +
|
| 745 | + IdentityProviderRepresentation |
| 746 | + https://www.keycloak.org/docs-api/22.0.5/rest-api/index.html#_identityprovidermapperrepresentation |
| 747 | +
|
| 748 | + :param: idp_alias: alias for Idp to add mapper in |
| 749 | + :type idp_alias: str |
| 750 | + :param: mapper_id: ID of mapper |
| 751 | + :type mapper_id: str |
| 752 | + :returns: Keycloak server response |
| 753 | + :rtype: dict |
| 754 | + """ |
| 755 | + params_path = { |
| 756 | + "realm-name": self.connection.realm_name, # type:ignore |
| 757 | + "idp-alias": idp_alias, |
| 758 | + "mapper-id": mapper_id, |
| 759 | + } |
| 760 | + data_raw = self.raw_delete(urls_patterns.URL_ADMIN_IDP_MAPPER_UPDATE.format(**params_path)) |
| 761 | + return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) |
| 762 | + |
742 | 763 | def get_idp_mappers(self, idp_alias): |
743 | 764 | """Get IDP mappers. |
744 | 765 |
|
@@ -785,6 +806,57 @@ def delete_idp(self, idp_alias): |
785 | 806 | data_raw = self.connection.raw_delete(urls_patterns.URL_ADMIN_IDP.format(**params_path)) |
786 | 807 | return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) |
787 | 808 |
|
| 809 | + def get_idp_management_permissions(self, idp_alias: str) -> Dict[str, Any]: |
| 810 | + """Get management permissions for a client. |
| 811 | +
|
| 812 | + ManagementPermissionReference |
| 813 | + https://www.keycloak.org/docs-api/22.0.5/rest-api/index.html#_managementpermissionreference |
| 814 | +
|
| 815 | + :param: idp_alias: idp alias name |
| 816 | + :type idp_alias: str |
| 817 | + :returns: Keycloak server response |
| 818 | + :rtype: dict |
| 819 | + """ |
| 820 | + params_path = { |
| 821 | + "realm-name": self.connection.realm_name, # type:ignore |
| 822 | + "alias": idp_alias, |
| 823 | + } |
| 824 | + data_raw = self.raw_get( |
| 825 | + urls_patterns.URL_ADMIN_IDP_MANAGEMENT_PERMISSIONS.format(**params_path) |
| 826 | + ) |
| 827 | + return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[200]) |
| 828 | + |
| 829 | + def update_idp_management_permissions( |
| 830 | + self, idp_alias: str, payload: Dict[str, Any] |
| 831 | + ) -> Dict[str, Any]: |
| 832 | + """Update management permissions for a client. |
| 833 | +
|
| 834 | + ManagementPermissionReference |
| 835 | + https://www.keycloak.org/docs-api/22.0.5/rest-api/index.html#_managementpermissionreference |
| 836 | +
|
| 837 | + :param: idp_alias: idp alias name |
| 838 | + :type idp_alias: str |
| 839 | + :param payload: ManagementPermissionReference |
| 840 | + :type payload: dict |
| 841 | + :returns: Keycloak server response |
| 842 | + :rtype: dict |
| 843 | +
|
| 844 | + Payload example:: |
| 845 | +
|
| 846 | + payload={ |
| 847 | + "enabled": true |
| 848 | + } |
| 849 | + """ |
| 850 | + params_path = { |
| 851 | + "realm-name": self.connection.realm_name, # type:ignore |
| 852 | + "alias": idp_alias, |
| 853 | + } |
| 854 | + data_raw = self.raw_put( |
| 855 | + urls_patterns.URL_ADMIN_IDP_MANAGEMENT_PERMISSIONS.format(**params_path), |
| 856 | + data=json.dumps(payload), |
| 857 | + ) |
| 858 | + return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[200]) |
| 859 | + |
788 | 860 | def create_user(self, payload, exist_ok=False): |
789 | 861 | """Create a new user. |
790 | 862 |
|
|
0 commit comments