Browse Source

fix: content type for async initial access token

pull/566/head
Richard Nemeth 11 months ago
parent
commit
647396d689
No known key found for this signature in database GPG Key ID: 21C39470DF3DEC39
  1. 14
      src/keycloak/keycloak_openid.py
  2. 2
      tests/test_keycloak_admin.py

14
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)

2
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",

Loading…
Cancel
Save