Browse Source

refactor: incorporate custom headers into default header setup

Modify the default headers construction to merge in custom headers if provided. This change ensures that custom headers, such as Cloudflare access tokens, are included in the request before self.get_token() is called and without overwriting the default headers like 'Authorization' and 'Content-Type'.
pull/533/head
Matt Collecutt 2 months ago
parent
commit
0b8d45e148
  1. 13
      src/keycloak/openid_connection.py

13
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

Loading…
Cancel
Save