[wrangler] Add experimental OAuth 2.0 Device Authorization Grant support#14064
Draft
petebacondarwin wants to merge 1 commit into
Draft
[wrangler] Add experimental OAuth 2.0 Device Authorization Grant support#14064petebacondarwin wants to merge 1 commit into
petebacondarwin wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 9c81731 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
✅ All changesets look good |
This comment was marked as outdated.
This comment was marked as outdated.
4 tasks
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
fa7f05c to
d604f3f
Compare
5 tasks
d604f3f to
ea3cd3d
Compare
ea3cd3d to
b6ac62c
Compare
b6ac62c to
6318f88
Compare
6318f88 to
24ccd5f
Compare
Adds a new `--experimental-device` flag to `wrangler login` that uses the OAuth 2.0 Device Authorization Grant (RFC 8628) instead of the existing localhost callback flow. The new flow: - prints the verification URL and user code to the terminal, - attempts to open the verification URL in the default browser, - prints a QR code of the verification URL, - polls the token endpoint with grant_type=device_code until the user approves the request, denies it, or the device code expires, - caps polling at 5 minutes to limit any leaked-user-code abuse window. Useful in containers, remote SSH sessions, and Codespaces where the OAuth provider cannot reach a callback server on localhost:8976. `--callback-host` and `--callback-port` are rejected when `--experimental-device` is set, since the device flow has no local callback server. The device-flow primitives live in `@cloudflare/workers-auth` (exposed via the existing `createOAuthFlow(...)` API as a `device` login option), so other Cloudflare CLIs that consume the package get the flow for free. The QR renderer is injected through the OAuth flow context, mirroring the existing `generateAuthUrl` / `generateRandomState` test-injection seam. The flag is gated as experimental and is inert until the supporting server-side work ships (AUTHN-216 / AUTHN-217 / AUTHN-218).
24ccd5f to
9c81731
Compare
2 tasks
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.
Adds an experimental
--experimental-deviceflag towrangler loginthat uses the OAuth 2.0 Device Authorization Grant (RFC 8628) instead of the existing localhost callback flow.Replaces #13130 with an industry standard approach.
Fixes #13117
Fixes #10935
Note
Ready for code review, not yet ready to merge. The flag is gated behind
--experimental-deviceand is inert in production until the supporting server-side work ships (see Dependencies below). Kept as a Draft until then.What this changes
wrangler login --experimental-deviceruns a new flow that:grant_type=urn:ietf:params:oauth:grant-type:device_codeuntil the user approves the request, denies it, or the device code expires.This is useful in containers, remote SSH sessions, Codespaces, and any other environment where
localhost:8976is unreachable from the user's browser.Where the code lives
Since this PR was first opened, wrangler's OAuth machinery was extracted into the
@cloudflare/workers-authpackage (#14185). This PR is rebased onto that structure:@cloudflare/workers-auth, exposed through the existingcreateOAuthFlow(...)API as a newdevicelogin option. Other Cloudflare CLIs that consume the package get the flow for free.--experimental-deviceflag and injects its QR renderer + client config into the flow context.renderDeviceQrCode), mirroring the existinggenerateAuthUrl/generateRandomStatetest-injection seam, so the device-flow snapshot tests stay deterministic.Behaviour details
intervalfield (RFC 8628 §3.5), with a minimum floor of 1s. If the server sendsslow_down, we add +5s as required by the RFC.expires_in, to limit the abuse window if a user code is ever leaked (RFC 8628 §5.4).--callback-hostand--callback-portare rejected (hard error) when--experimental-deviceis set — this flow has no local callback server.offline_accessscope is appended unconditionally, same as the auth-code flow, so refresh tokens still work end-to-end.authorization_pending/slow_downis the expected RFC 8628 §3.5 control mechanism, so the poll path logs non-2xx responses atdebuglevel only — a normal pending login produces no error output.Why "experimental"
This is gated behind
--experimental-deviceso we can iterate on UX (polling cadence, timeout messaging, QR rendering, etc.) before committing to the surface. There is no auto-detection or fallback from the existing flow — users have to opt in explicitly.Dependencies
This is the client-side (Wrangler) portion. It is safe to land independently because the flag is experimental and opt-in, but the end-to-end flow only works in production once the supporting server-side work ships:
packages/wrangler/src/__tests__/user.test.ts; flow primitives in@cloudflare/workers-auth)wrangler login --experimental-devicecloudflare-docs#31091