diff --git a/src/keycloak/openid_connection.py b/src/keycloak/openid_connection.py index 081cbaf..96ea296 100644 --- a/src/keycloak/openid_connection.py +++ b/src/keycloak/openid_connection.py @@ -114,19 +114,18 @@ class KeycloakOpenIDConnection(ConnectionManager): self.client_secret_key = client_secret_key self.user_realm_name = user_realm_name self.timeout = timeout + self.headers = {} + self.custom_headers = custom_headers if self.token is None: self.get_token() - self.headers = ( - { + if self.token is not None: + self.headers = { + **self.headers, "Authorization": "Bearer " + self.token.get("access_token"), - "Content-Type": "application/json", + "Content-Type": "application/json" } - if self.token is not None - else {} - ) - self.custom_headers = custom_headers super().__init__( base_url=self.server_url, headers=self.headers, timeout=60, verify=self.verify