Repository navigation
feat(cli): add lightning login --device for machines without a browser - #218
Conversation
`lightning login --device` signs in with the OAuth 2.0 device authorization grant (RFC 8628): it prints a code to enter in a browser on any other device, polls until the sign-in is approved, and saves the session the same way `lightning login` does. When `lightning login` can't open a browser, its error now points at `--device`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ethanwharris
left a comment
There was a problem hiding this comment.
Nice! My only question is whether --device is the right flag, is that standard? Or are other things doing like --no-browser or something?
This still requires to input the code on a browser so I think that would be a misnomer here. Cloudflare: |
dhedey
left a comment
There was a problem hiding this comment.
Shouldn't it be https://platform.lightning.ai/device ?
There was a problem hiding this comment.
For the fallback I'd suggest going with paste-back (auth code + PKCE, like gcloud auth login --no-launch-browser or claude code's no browser path) over the device flow.
Most companies are slowly looking to drop device flow because it's a little too easy to convince someone to enter a code at a URL:
- gcloud dropped device code a few years ago
- AWS swapped their default to Auth code + PKCE since CLI 2.22.0
Claude pipes in with:
The Device Code RFC is from 2019, but the newer guidance is blunter - RFC 10027 (BCP 247, 2026) says to use it only if nothing else is viable, and to "avoid using if the protected resources are sensitive, high value, or business critical."
Paste-back is a little better - it's the same auth code + PKCE flow we already use, with a page that shows the code in place of the localhost redirect. To phish it, someone has to be talked into sending the code to the attacker, and a code leaked any other way is useless without the PKCE verifier.
The page should also make very clear what access pasting back provides -- i.e. "This gives access to your account. Only paste it back into a CLI or SDK that you trust. Do not give it to anyone else" style of message.
Alternatively, if we want to keep device code, we could reduce the risk of phishing a little by making very clear in the UI before entering the code that by entering a code, you are authorizing the thing that gave you the code full access to your account, before showing them the box to enter the code.
Happy with either, I just want to make sure we're responsible with how we do things :)
Interesting, yeah paste-back seems to be better. Let me make a plan for these changes, but in the meantime we can add the device flow since this is ready. We already have the UI in place to have an explicit approve and deny https://github.com/gridai/grid/pull/49150 |
lightning login --devicesigns in on a machine without a browser, such as a remote server or a container, using the OAuth 2.0 device authorization grant (RFC 8628). It prints a short code and an address; the user enters the code in a browser on any other device and approves, and the CLI saves the session the same waylightning logindoes.What
lightning login --devicecallsPOST /oidc/device_authorizationas clientlightning-cli, shows the code, and pollsPOST /oidc/tokenwith the device-code grant at the interval the server gives, adding 5 seconds onslow_down. It stops onaccess_denied,expired_token, or whenexpires_inruns out, and saves the session to the usual 0600 credentials file.lightning logincan't open a browser, the error now points atlightning login --deviceinstead ofLIGHTNING_API_KEY.--device.Notes
--devicereports that the server doesn't support it.Tests
pytest tests/cli/utils/test_auth.py tests/cli/test_entrypoint.py: 39 passed. New tests cover polling throughauthorization_pendingandslow_down, denial, expiry reported by the server and byexpires_in, a server without device login, andlogin --devicereplacing a saved session.ruff check/ruff format --checkclean; mypy not run locally.