Skip to content

Fix Airflow JWT getting cleared in KeycloakAuthManager /login_callback route - #71077

Merged
vincbeck merged 1 commit into
apache:mainfrom
stephen-bracken:fix-keycloak-login
Aug 10, 2026
Merged

Fix Airflow JWT getting cleared in KeycloakAuthManager /login_callback route#71077
vincbeck merged 1 commit into
apache:mainfrom
stephen-bracken:fix-keycloak-login

Conversation

@stephen-bracken

Copy link
Copy Markdown
Contributor

Fix Airflow JWT getting cleared in KeycloakAuthManager /login_callback route

related: #70800

In the /login_callback route the request has no _token property because the /login_callback route is going to set _token in the response. The KeycloakJWTMiddleware was incorrectly raising a 401 status and clearing the _token cookie, preventing logins. Gracefully handle this scenario by returning None, None for the user.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
  • No

@vincbeck
vincbeck merged commit 2ece6fd into apache:main Aug 10, 2026
152 checks passed
stegololz added a commit to stegololz/airflow that referenced this pull request Aug 12, 2026
KeycloakJWTMiddleware clears the JWT cookie when token validation fails.
When the failing token arrives on the login callback request itself (a
re-login after the previous JWT expired, with the stale cookie still in
the browser jar), the clearing Set-Cookie is appended after the fresh
token the callback just set. The browser applies the deletion last, the
new session dies in the response that created it, and the user is sent
back to login indefinitely.

apache#71077 fixed the same clobber for requests carrying no token at all;
this covers the remaining path where an expired token is present.

The login callback now signals via request.state.jwt_token_issued that
the response carries a freshly issued JWT, and the middleware skips the
cookie clear in that case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
stegololz added a commit to stegololz/airflow that referenced this pull request Aug 12, 2026
KeycloakJWTMiddleware clears the JWT cookie when token validation fails.
When the failing token arrives on the login callback request itself (a
re-login after the previous JWT expired, with the stale cookie still in
the browser jar), the clearing Set-Cookie is appended after the fresh
token the callback just set. The browser applies the deletion last, the
new session dies in the response that created it, and the user is sent
back to login indefinitely.

apache#71077 fixed the same clobber for requests carrying no token at all;
this covers the remaining path where an expired token is present.

The login callback now signals via request.state.jwt_token_issued that
the response carries a freshly issued JWT, and the middleware skips the
cookie clear in that case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
stegololz added a commit to stegololz/airflow that referenced this pull request Aug 12, 2026
KeycloakJWTMiddleware clears the JWT cookie when token validation fails.
When the failing token arrives on the login callback request itself (a
re-login after the previous JWT expired, with the stale cookie still in
the browser jar), the clearing Set-Cookie is appended after the fresh
token the callback just set. The browser applies the deletion last, the
new session dies in the response that created it, and the user is sent
back to login indefinitely.

apache#71077 fixed the same clobber for requests carrying no token at all;
this covers the remaining path where an expired token is present.

The login callback now signals via request.state.jwt_token_issued that
the response carries a freshly issued JWT, and the middleware skips the
cookie clear in that case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
stegololz added a commit to stegololz/airflow that referenced this pull request Aug 13, 2026
KeycloakJWTMiddleware clears the JWT cookie when token validation fails.
When the failing token arrives on the login callback request itself (a
re-login after the previous JWT expired, with the stale cookie still in
the browser jar), the clearing Set-Cookie is appended after the fresh
token the callback just set. The browser applies the deletion last, the
new session dies in the response that created it, and the user is sent
back to login indefinitely.

apache#71077 fixed the same clobber for requests carrying no token at all;
this covers the remaining path where an expired token is present.

The login callback now signals via request.state.jwt_token_issued that
the response carries a freshly issued JWT, and the middleware skips the
cookie clear in that case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
vincbeck pushed a commit that referenced this pull request Aug 13, 2026
…#71506)

KeycloakJWTMiddleware clears the JWT cookie when token validation fails.
When the failing token arrives on the login callback request itself (a
re-login after the previous JWT expired, with the stale cookie still in
the browser jar), the clearing Set-Cookie is appended after the fresh
token the callback just set. The browser applies the deletion last, the
new session dies in the response that created it, and the user is sent
back to login indefinitely.

#71077 fixed the same clobber for requests carrying no token at all;
this covers the remaining path where an expired token is present.

The login callback now signals via request.state.jwt_token_issued that
the response carries a freshly issued JWT, and the middleware skips the
cookie clear in that case.
dabla pushed a commit to dabla/airflow that referenced this pull request Aug 14, 2026
dabla pushed a commit to dabla/airflow that referenced this pull request Aug 14, 2026
…apache#71506)

KeycloakJWTMiddleware clears the JWT cookie when token validation fails.
When the failing token arrives on the login callback request itself (a
re-login after the previous JWT expired, with the stale cookie still in
the browser jar), the clearing Set-Cookie is appended after the fresh
token the callback just set. The browser applies the deletion last, the
new session dies in the response that created it, and the user is sent
back to login indefinitely.

apache#71077 fixed the same clobber for requests carrying no token at all;
this covers the remaining path where an expired token is present.

The login callback now signals via request.state.jwt_token_issued that
the response carries a freshly issued JWT, and the middleware skips the
cookie clear in that case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants