baptistegh opened a new pull request, #77444: URL: https://github.com/apache/airflow/pull/77444
`airflowctl auth login --sso` (#75938) needs a browser on the same machine, because the identity provider redirects back to `127.0.0.1`. Over SSH or in a container there is none. This adds `airflowctl auth login --device-code` (and `auth token --device-code`): airflowctl prints a URL and a code, and the user approves the login on any device. airflowctl follows the device code contract documented in core (#75672), so it works with any auth manager that advertises it. The Keycloak auth manager is the first, in #77443. The two PRs are independent and can be merged in either order. related: #75560 ### Changes - `--device-code` reads `GET /api/v2/auth/cli/metadata`. It needs the `urn:ietf:params:oauth:grant-type:device_code` grant and both endpoints on the API server, otherwise it fails at once with "does not offer device code login". - It calls `device_authorization_endpoint`, prints the URL and the code on stderr, and polls `token_endpoint`, following `interval`, adding 5 seconds on `slow_down`, and stopping on `access_denied` or `expired_token`. `TOKEN=$(airflowctl auth token --device-code)` still captures only the token. - `--timeout` (default 300 seconds) also bounds the wait, and so does the lifetime of the code (`expires_in`). - It is an explicit flag, not a fallback of `--sso`, so users only see a code when they asked for one. `--device-code` implies `--sso`; `--sso --device-code` also works. `--no-browser` is rejected with it. - When a server offers only device code login, `--sso` says "Use --device-code to log in with a code instead". - A code or URL with control characters is refused, so the server cannot rewrite what the terminal shows. - Docs: `start.rst` describes the new login, and the `auth login` help image is regenerated. ### Trying it With #77443 and `[keycloak_auth_manager] cli_device_code_enabled = True`: ```bash airflowctl auth login --device-code --api-url http://localhost:8080 --env device airflowctl dags list --env device ``` Tested end to end in Breeze with Keycloak and #77443: approved, refused and timed-out logins, the stored token, and a Keycloak outage while polling. --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes (please specify the tool below) Generated-by: Claude Code (Opus 5.5) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
