Conversation
…i_complete Co-authored-by: i8ramin <49030+i8ramin@users.noreply.github.com>
Review from @chocothebot 🐢Copilot's approach is solid — pushed one improvement on top: ✅ What Copilot got right
🐛 Bug I fixed (commit
|
🚀 Preview Deployed — PR #35Branch: Quick smoke testsBASE="https://botcha-pr-35.carrot-cart.workers.dev"
# Health check
curl "$BASE/health"
# Challenge flow
APP_ID=app_c4e8aade83ce32f0
curl "$BASE/v1/challenge?app_id=$APP_ID"
# New endpoints on this PR (check EPIC.md for specifics)
curl "$BASE/v1/" | jq .
Auto-deployed by preview.yml · View logs |
|
🧹 Preview worker |
There was a problem hiding this comment.
Pull request overview
Improves the OAuth device authorization flow UX by switching agents to share the one-click verification_uri_complete link and enhancing the /device page to auto-submit approvals when opened with a ?code= param.
Changes:
- Update OAuth device response copy to direct users to the one-click
verification_uri_completelink. - Add client-side countdown + cancel UX to auto-approve on
/devicewhen?code=is present. - Update onboarding instruction copy to reference
verification_uri_completeinstead of manual code entry.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/cloudflare-workers/src/oauth-agent.ts | Device flow guidance + response message updated to use the one-click URL. |
| packages/cloudflare-workers/src/index.tsx | Onboarding step copy updated; /device page adds countdown auto-submit behavior for ?code= links. |
| package-lock.json | Version/lockfile updates aligned with the workspace version bump. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tick(); | ||
| } | ||
| // Wait for lookup to complete (lookup has 400ms debounce + fetch), then start countdown | ||
| setTimeout(startCountdown, 1200); |
There was a problem hiding this comment.
The auto-approval countdown relies on a fixed 1200ms delay, then immediately fails if resolvedCode !== urlCode. On slower networks (or if the 400ms debounce + fetch takes longer), this can incorrectly show “Code not found or expired” and never auto-approve. Consider starting the countdown when the lookup actually succeeds (e.g., trigger from lookupCode when d.success and val === urlCode), or poll/wait up to a timeout instead of using a single fixed delay.
| setTimeout(startCountdown, 1200); | |
| (function waitForLookupAndStart() { | |
| var maxWaitMs = 10000; // maximum time to wait for code lookup | |
| var pollIntervalMs = 200; | |
| var waitedMs = 0; | |
| function poll() { | |
| if (autoCancelled) return; | |
| if (resolvedCode === urlCode) { | |
| startCountdown(); | |
| return; | |
| } | |
| waitedMs += pollIntervalMs; | |
| if (waitedMs >= maxWaitMs) { | |
| autoStatus.textContent = 'Code not found or expired. Please check with your agent.'; | |
| return; | |
| } | |
| setTimeout(poll, pollIntervalMs); | |
| } | |
| poll(); | |
| })(); |
| // Auto-submit if code came from URL params (verification_uri_complete) | ||
| var urlCode = new URLSearchParams(window.location.search).get('code'); | ||
| if (urlCode && urlCode.length === 13) { | ||
| var autoTimer = null; | ||
| var autoCancelled = false; | ||
| var autoStatus = document.getElementById('status'); | ||
| function startCountdown() { | ||
| if (autoCancelled) return; | ||
| // Only proceed if the lookup confirmed the code is valid | ||
| if (resolvedCode !== urlCode) { | ||
| autoStatus.textContent = 'Code not found or expired. Please check with your agent.'; | ||
| return; | ||
| } |
There was a problem hiding this comment.
urlCode is read directly from the query string and compared to resolvedCode, but it’s never normalized (uppercased) and the countdown doesn’t verify the current input value still matches urlCode. Normalizing urlCode (and/or explicitly setting the input value from it) would make the auto-approval path more robust and avoid false mismatches or approving if the user edits the field before the countdown completes.
| @@ -10,7 +10,7 @@ | |||
| * 1. Agent: POST /v1/oauth/device { agent_id, app_id } | |||
| * ← { device_code, user_code: "BOTCHA-XXXX", verification_url, expires_in: 600, interval: 5 } | |||
There was a problem hiding this comment.
The flow doc comment references sending <verification_uri_complete>, but the step-1 response example above doesn’t list verification_uri_complete (or message). Updating the example response fields would keep the comment accurate for readers.
| * ← { device_code, user_code: "BOTCHA-XXXX", verification_url, expires_in: 600, interval: 5 } | |
| * ← { device_code, user_code: "BOTCHA-XXXX", verification_url, verification_uri_complete, expires_in: 600, interval: 5, message } |
| return c.json({ | ||
| device_code, | ||
| user_code, | ||
| verification_url: `${base_url}/device`, | ||
| verification_uri: `${base_url}/device`, // RFC 8628 canonical name | ||
| verification_uri_complete: `${base_url}/device?code=${user_code}`, | ||
| expires_in: DEVICE_TTL_SEC, | ||
| interval: 5, | ||
| message: `Tell your human: visit ${base_url}/device and enter ${user_code}`, | ||
| message: `Approve me: ${base_url}/device?code=${user_code}`, | ||
| }); |
There was a problem hiding this comment.
There are unit tests covering other Cloudflare Worker modules under tests/unit, but this change alters the OAuth device response contract (message now contains the one-click URL). Adding a small unit test for handleOAuthDevice to assert verification_uri_complete is returned and message uses the same URL would help prevent regressions.
The device flow was instructing agents to tell humans to visit the bare
/deviceURL and manually type the code — despiteverification_uri_complete(with the code embedded) already being returned in the response.Changes
oauth-agent.ts:messagenow usesverification_uri_completedirectly:/devicepage JS: When?code=is present in the URL, triggers a 3-second countdown auto-submit with a visible Cancel button — human taps link, agent info loads, approval fires without any typing.Onboarding instructions (step 11): Updated to instruct agents to share
verification_uri_completeas the one-click link rather than bare URL + code separately.The
/devicepage already handled server-side pre-fill and auto-lookup from?code=; the only missing pieces were the countdown auto-submit and fixing themessagecopy agents were presenting to humans.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.