Browse Source

fix: incorporate custom headers into default header setup (#533)

* 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'.

* refactor: Fixing linting issue

Fixing linting issue by adding trailing comma to key in dict

* refactor: adding custom headers to KeycloakOpenID

Adding `custom_headers` to KeycloakOpenID instantiation.
pull/534/head v3.9.3
Matt Collecutt 4 weeks ago
committed by GitHub
parent
commit
1dd6c81f52
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      src/keycloak/openid_connection.py

12
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",
}
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
@ -301,6 +300,7 @@ class KeycloakOpenIDConnection(ConnectionManager):
verify=self.verify,
client_secret_key=self.client_secret_key,
timeout=self.timeout,
custom_headers=self.custom_headers,
)
return self._keycloak_openid

Loading…
Cancel
Save