Fix logout route in Keycloak provider so a KeycloakostError doesn't lead to Internal Server Error in API server#59382
Merged
potiuk merged 20 commits intoapache:mainfrom Dec 16, 2025
Conversation
…ostError doesn't propagate to API server also which leads to Internal Server Error
Contributor
|
CI is unhappy :( |
Contributor
Author
|
I've put this PR in draft because I still need to add a test for the logout route |
Contributor
Author
Yes it's still WIP but I wanted to already start the PR so we know it's being handled ;-) |
…en refresh_token is being invoked in logout route
Contributor
Author
|
Test added |
…akAuthManagerUser
vincbeck
reviewed
Dec 15, 2025
Contributor
vincbeck
left a comment
There was a problem hiding this comment.
One nit, overall, looks good
…/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
vincbeck
approved these changes
Dec 15, 2025
FoxHelms
pushed a commit
to FoxHelms/airflow
that referenced
this pull request
Dec 17, 2025
…ead to Internal Server Error in API server (apache#59382) * refactor: Fix logout route in Keycloak provider also so the KeycloakPostError doesn't propagate to API server also which leads to Internal Server Error * refactor: Fixed static checks * refactor: Fixed refresh_token invocations * refactor: Must call refresh_user in refresh route * refactor: refresh_token must always return a dict * refactor: Added test when keycloak client raises KeycloakPostError when refresh_token is being invoked in logout route * refactor: Fixed some additional static checks * refactor: Refactored refresh_user * refactor: Reformatted imports * refactor: Fixed mocking in refresh test * refactor: Removed unused mocking of keycloak client in test_refresh_token * refactor: Fixed mock get_auth_manager and added missing import KeycloakAuthManagerUser * refactor: Refresh token route calls refresh_user instead of refresh_token * refactor: Changed assert on refresh user * Update providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * refactor: Fixed calls to refresh_tokens instead of refresh_token --------- Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
TempestShaw
pushed a commit
to TempestShaw/airflow
that referenced
this pull request
Dec 24, 2025
…ead to Internal Server Error in API server (apache#59382) * refactor: Fix logout route in Keycloak provider also so the KeycloakPostError doesn't propagate to API server also which leads to Internal Server Error * refactor: Fixed static checks * refactor: Fixed refresh_token invocations * refactor: Must call refresh_user in refresh route * refactor: refresh_token must always return a dict * refactor: Added test when keycloak client raises KeycloakPostError when refresh_token is being invoked in logout route * refactor: Fixed some additional static checks * refactor: Refactored refresh_user * refactor: Reformatted imports * refactor: Fixed mocking in refresh test * refactor: Removed unused mocking of keycloak client in test_refresh_token * refactor: Fixed mock get_auth_manager and added missing import KeycloakAuthManagerUser * refactor: Refresh token route calls refresh_user instead of refresh_token * refactor: Changed assert on refresh user * Update providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * refactor: Fixed calls to refresh_tokens instead of refresh_token --------- Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
54 tasks
jhgoebbert
pushed a commit
to jhgoebbert/airflow_Owen-CH-Leung
that referenced
this pull request
Feb 8, 2026
…ead to Internal Server Error in API server (apache#59382) * refactor: Fix logout route in Keycloak provider also so the KeycloakPostError doesn't propagate to API server also which leads to Internal Server Error * refactor: Fixed static checks * refactor: Fixed refresh_token invocations * refactor: Must call refresh_user in refresh route * refactor: refresh_token must always return a dict * refactor: Added test when keycloak client raises KeycloakPostError when refresh_token is being invoked in logout route * refactor: Fixed some additional static checks * refactor: Refactored refresh_user * refactor: Reformatted imports * refactor: Fixed mocking in refresh test * refactor: Removed unused mocking of keycloak client in test_refresh_token * refactor: Fixed mock get_auth_manager and added missing import KeycloakAuthManagerUser * refactor: Refresh token route calls refresh_user instead of refresh_token * refactor: Changed assert on refresh user * Update providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * refactor: Fixed calls to refresh_tokens instead of refresh_token --------- Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
Subham-KRLX
pushed a commit
to Subham-KRLX/airflow
that referenced
this pull request
Mar 4, 2026
…ead to Internal Server Error in API server (apache#59382) * refactor: Fix logout route in Keycloak provider also so the KeycloakPostError doesn't propagate to API server also which leads to Internal Server Error * refactor: Fixed static checks * refactor: Fixed refresh_token invocations * refactor: Must call refresh_user in refresh route * refactor: refresh_token must always return a dict * refactor: Added test when keycloak client raises KeycloakPostError when refresh_token is being invoked in logout route * refactor: Fixed some additional static checks * refactor: Refactored refresh_user * refactor: Reformatted imports * refactor: Fixed mocking in refresh test * refactor: Removed unused mocking of keycloak client in test_refresh_token * refactor: Fixed mock get_auth_manager and added missing import KeycloakAuthManagerUser * refactor: Refresh token route calls refresh_user instead of refresh_token * refactor: Changed assert on refresh user * Update providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * refactor: Fixed calls to refresh_tokens instead of refresh_token --------- Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is also related to issue #59359.
Problem is during the logout route defined in the Keycloak provider is that there the refresh_token is also called directly on the Keycloak client. When a KeycloakPostError is raised when the refresh token fails, the error will also be raised and this will lead to an HTTP 500 Internal Server Error in the API server.
So I extracted a refresh_token method from the refresh_user method in the KeycloakAuthManager so the refresh_token method is guarded and thus catches the KeycloakPostError, that way I can also re-use that method in the logout route so that when an exception occurs the API server doesn't return an HTTP 500 Internal Server Error.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.