Skip to content

Generate the UI's API token with generate_api_jwt so it works with the Authorization header - #77182

Open
dabla wants to merge 1 commit into
apache:mainfrom
dabla:fix/ui-generated-token-uses-api-jwt
Open

dabla wants to merge 1 commit into
apache:mainfrom
dabla:fix/ui-generated-token-uses-api-jwt

Conversation

@dabla

@dabla dabla commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

POST /ui/auth/token, the route behind "Generate token" in the UI, signs the token with generate_jwt, the method for the browser session cookie. An auth manager that keeps part of its state in cookies leaves that state out of this token. The Keycloak auth manager does so since Airflow 3.3: the Keycloak tokens travel in their own cookies, so the generated token carries none. Sent with the Authorization header it resolves to no user, and every request answers 500 in the authorization checks ('NoneType' object has no attribute 'access_token').

The route now calls generate_api_jwt, which exists for exactly this client: one that authenticates with the header and sends no cookies. Auth managers whose tokens are self-contained do not override it, so nothing changes for them.

This is another path to the 500 described in #76352. #76353 fixes the browser session whose Keycloak tokens are gone; this one was found in its review (#76353 (comment)) and is separate because it is a core change, while #76353 only touches the Keycloak provider.

Test: the route returns what generate_api_jwt returns, for both token types and with their expiration times. It fails on main, where generate_jwt is called.

related: #76352, #76353, #72381


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Fable 5.2)

Generated-by: Claude Code (Fable 5.2) following the guidelines

🤖 Generated with Claude Code

…e Authorization header

POST /ui/auth/token signed the token with generate_jwt, the method for the
browser session cookie. An auth manager that keeps part of its state in
cookies leaves that state out of such a token: with the Keycloak auth
manager on Airflow 3.3+ the generated token carries no Keycloak tokens,
resolves to no user when sent with the Authorization header, and every
request answers 500 in the authorization checks.

The route now calls generate_api_jwt, which exists for a client that
authenticates with the header and sends no cookies. Auth managers whose
tokens are self-contained do not override it and are unaffected.

The new test asserts the route returns the auth manager's API token for
both token types, with their expiration times.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant