Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: incorporate custom headers into default header setup #533

Merged
merged 3 commits into from
Apr 7, 2024

Conversation

mattcollie
Copy link
Contributor

Hi this is my first contribution to this project, and I hope I'm doing this right. If there's anything I've missed or any additional information you need, please let me know.

Overview

Refactor of KeycloakOpenIDConnection, setting headers and custom_headers before any web request requiring any custom headers. This allows custom headers like Cloudflare access tokens to be included in the initial get_token() request.

Changes

This pull request refactors how default headers are set up. I've made modifications to ensure that custom headers, when provided, are incorporated correctly before any web requests.

The key changes include:

  • The custom headers are merged before the self.get_token() method is called.
  • Ensuring that custom headers such as Cloudflare access tokens are included in all requests.
  • Maintaining the default headers like 'Authorization' and 'Content-Type', ensuring they are not overwritten.

Reason

The motivation behind these changes is to ensure custom headers are available before any web requests requiring headers are made. This was a particular error when using KeycloakOpenIDConnection for KeycloakAdmin.

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'.
Fixing linting issue by adding trailing comma to key in dict
Adding `custom_headers` to KeycloakOpenID instantiation.
Copy link
Collaborator

@ryshoooo ryshoooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @mattcollie

The change makes sense and overall it looks good to me :)

@ryshoooo ryshoooo merged commit 1dd6c81 into marcospereirampj:master Apr 7, 2024
19 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants