diff --git a/src/keycloak/keycloak_openid.py b/src/keycloak/keycloak_openid.py index 94144de..5e556e9 100644 --- a/src/keycloak/keycloak_openid.py +++ b/src/keycloak/keycloak_openid.py @@ -1424,6 +1424,8 @@ class KeycloakOpenID: params_path = {"realm-name": self.realm_name} orig_bearer = self.connection.headers.get("Authorization") self.connection.add_param_headers("Authorization", "Bearer " + token) + orig_content_type = self.connection.headers.get("Content-Type") + self.connection.add_param_headers("Content-Type", "application/json") data_raw = await self.connection.a_raw_post( URL_CLIENT_REGISTRATION.format(**params_path), data=json.dumps(payload) ) @@ -1432,6 +1434,11 @@ class KeycloakOpenID: if orig_bearer is not None else self.connection.del_param_headers("Authorization") ) + ( + self.connection.add_param_headers("Content-Type", orig_content_type) + if orig_content_type is not None + else self.connection.del_param_headers("Content-Type") + ) return raise_error_from_response(data_raw, KeycloakPostError) async def a_device(self): @@ -1477,6 +1484,8 @@ class KeycloakOpenID: params_path = {"realm-name": self.realm_name, "client-id": client_id} orig_bearer = self.connection.headers.get("Authorization") self.connection.add_param_headers("Authorization", "Bearer " + token) + orig_content_type = self.connection.headers.get("Content-Type") + self.connection.add_param_headers("Content-Type", "application/json") # Keycloak complains if the clientId is not set in the payload if "clientId" not in payload: @@ -1490,4 +1499,9 @@ class KeycloakOpenID: if orig_bearer is not None else self.connection.del_param_headers("Authorization") ) + ( + self.connection.add_param_headers("Content-Type", orig_content_type) + if orig_content_type is not None + else self.connection.del_param_headers("Content-Type") + ) return raise_error_from_response(data_raw, KeycloakPutError) diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index d57654f..8a61faa 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -6114,7 +6114,7 @@ async def test_a_initial_access_token( client = str(uuid.uuid4()) secret = str(uuid.uuid4()) - res = oid.register_client( + res = await oid.a_register_client( token=res["token"], payload={ "name": "DynamicRegisteredClient",