Skip to content

MCP OAuth: offer the RFC 8628 device authorization grant to MCP clients, so a client running on a remote or headless machine can be authorized from a phone without a localhost redirect #35801

Description

@objectstack-fleet

repo:cloud#5 · hotlong · session_01Q4EjjPP1zuWBNq3nBXVei9

Filing gate: ③ a task on the maintainer's word, verbatim 「立卡」, given in the repo:cloud#5 seat session (2026-11-20). He had just shown a remote MCP client failing to complete OAuth against a hosted environment. Reader: the domain:server lane (plugin-auth OAuth / MCP authorization). Dedupe: device authorization MCP oauth (is:issue) returned 5 unrelated QA-run and invitation cards; no open card covers this.

维护者速读

  • 问题:MCP 客户端跑在云端电脑或服务器上(例如 WorkBuddy 的 Cloud Computer)时,用手机走 OAuth 授权,授权完会跳到 http://localhost:<port>/callback。这个地址指向手机自己,打不开,用户只能手动复制地址栏网址发回给客户端。
  • 要做:MCP 的授权入口同时提供「设备码授权」(RFC 8628)。客户端显示一个短码,用户在手机上打开授权页、输入短码确认即可,不需要跳回 localhost。
  • 平台已有这套机制:objectstack login 已经在用 /api/v1/auth/device/code。要补的是对 MCP 客户端开放,并在授权服务器元数据里声明它。
  • 需要你做的:无。

What was seen

A remote MCP client registered by DCR with a loopback redirect, http://localhost:8765/callback. That is allowed for native clients (RFC 8252; packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts around lines 668–689). The user authorized from a phone. The redirect went to the phone's own localhost and failed. The flow only completed because the user copied the URL by hand back to the client.

Measured (objectstack main)

  • The device flow exists for the CLI: packages/cli/src/commands/login.ts calls POST /api/v1/auth/device/code and polls with grant_type=urn:ietf:params:oauth:grant-type:device_code.
  • The authorization-server metadata (/.well-known/oauth-authorization-server, packages/plugins/plugin-auth/src/auth-plugin.ts around lines 6286–6292) is what MCP clients discover. Not yet read: whether it advertises device_authorization_endpoint and the device grant in grant_types_supported, and whether DCR accepts that grant for a public MCP client. The dev measures these first.

Done when

  • The MCP-facing authorization-server metadata advertises device_authorization_endpoint, and lists urn:ietf:params:oauth:grant-type:device_code in grant_types_supported.
  • A DCR-registered public MCP client can complete the device flow and receive a token with the same scopes and consent screen as the authorization-code flow.
  • The consent page names the client and the requested scopes before approval. The user code is short-lived and single-use.
  • A test pins both the metadata and an end-to-end device-flow token for an MCP client.

The security reading is owed in the PR: user-code entropy and expiry, polling rate limits, and the consent page as the only approval point. Device-flow phishing (a code relayed to a victim) is mitigated by naming the client on consent.

Activity

  1. added
    enhancement
    on Nov 20, 2026
  2. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Triage: lands in domain:server (plugin-auth OAuth, MCP authorization) · pm:queue; rationale: area:ai · Feature (offer the RFC 8628 device authorization grant to MCP clients and declare it in the authorization-server metadata, so a client on a remote or headless machine completes OAuth without a localhost redirect; objectstack login already uses /api/v1/auth/device/code) · filed on the maintainer's word 「立卡」 after a remote MCP client failed OAuth on a hosted environment → p2 (a maintainer-sourced Feature; he may raise it) · size M.

  3. added
    area:ai
    domain:server
    pm:queue
    priority:p2
    on Nov 20, 2026
  4. objectstack-fleet commented on Nov 21, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#6 · sunhaolin · session_017xRBcSPM86QhYAcidhG5Bu

    维护者速读

    • 问题:AI 客户端跑在云端电脑上、用户在手机上点同意时,授权结果被送去手机自己的本机地址,页面打不开,只能把地址栏的网址手抄回客户端。只见过你演示的那一次;这类客户端每次连接都会遇到。
    • 选项:A 增加“设备码授权”,客户端显示短码、用户在任意屏幕输入并同意,约 3 个 PR,只对会用设备码的客户端生效;B 现在不做,卡挂起,等有客户端确实会用设备码再做,用户照旧手抄;C 同意页在手机上不再跳去打不开的地址,改成“复制链接”一步,1 个小 PR。
    • 推荐 B:实测通用的 AI 客户端开发包里没有设备码授权,也没有证据说明出问题的那个客户端会用它,现在做等于给每个环境多开一扇没人走的门。
    • 不定会怎样:现状不变,远程客户端的用户授权后看到浏览器报错页,手抄网址才能连上。

    Decision analysis: a second way to approve an AI app that runs on another machine

    Question. A person approves an AI app from a phone while the app runs on a cloud computer, lands on a page that cannot open, and copies the address back by hand: should the platform add an approval that needs no redirect?

    Background. The card's premise (the platform already has this; open it to MCP clients) does not hold as measured: the existing short-code sign-in mints a full sign-in session, not the scoped agent grant.

    Governing text: packages/spec/src/system/auth-config.zod.ts:63-79 (the switch is "CLI / TV-style login"; /device/token is "poll for the issued session token"); ruling 6232069920 A at packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts:707-745 (a consent binds the approving session's organization, never a guessed one); objectstack-ai/cloud#3606 ruling A at mcp-token-revocation.ts:251-259, same directory (the consent is the revocable record the MCP door reads); docs/NORTH-STAR.md:11 (road step "connect an agent"). No option conflicts with these; A must satisfy both rulings.

    Protocol. A adds public surface: a token-endpoint grant, a discovery key, a registrable grant, two columns on sys_device_code, a new meaning for the spec switch. B and C add none.

    Premises (origin/main 30b0987, committed 2026-11-21T15:25Z; "run" = executed on better-auth and @better-auth/oauth-provider 1.7.12, tarballs matching the lockfile; A=packages/plugins/plugin-auth, P=ui/apps/console/src/pages/auth):

    1. Discovery today lists three grants and no device endpoint, and self-registration silently drops a requested device grant (run). The document is the vendor's ($A/src/auth-plugin.ts:6251-6255). Re-check: git grep -l "oauthDeviceAuthorization\|device_authorization_endpoint" origin/main | wc -l → 0 (control: git grep -c deviceAuthorization origin/main -- $A/src/auth-manager-plugin-list.ts → 5).
    2. The existing flow is the vendor's plain plugin, off by default, no environment switch (auth-manager-plugin-list.ts:237, :996-1002). Not gated to the CLI: an unregistered client name gets a code, and approval yields a full session, not a scoped grant (run). Vendor defaults: 8-character code (40 bits), 30 min expiry, 5 s polling interval, single use (run). Re-check: git grep -n validateClient origin/main -- $A/src | wc -l → 0.
    3. The pinned vendor ships its own OAuth device grant. Switched on with nothing else (run): discovery advertises it; an anonymous client registers for it with no redirect address; the first-party name objectstack-cli (packages/cli/src/commands/login.ts:422, packages/cloud-connection/src/cloud-connection-plugin.ts:751) is refused; the token carries no organization and leaves no consent record, though the approving session had one. The MCP door refuses a token with no consent (mcp-token-revocation.ts:277; read, not run). Re-check: grep -n "function oauthDeviceAuthorization" $A/node_modules/@better-auth/oauth-provider/dist/index.mjs.
    4. The consent page names the app, marks it unverified, names where the grant goes and lists permissions ($P/OAuthConsentPage.tsx:190, :392, :438). The device page shows none of these (DeviceAuthPage.tsx:56, :299-309), and a device request has no destination to show. Re-check: git grep -n "client_id\|scope" origin/main -- $P/DeviceAuthPage.tsx | wc -l → 0.
    5. No reader is measured: the pinned MCP client kit (@modelcontextprotocol/sdk 1.32.1) contains no device grant. Re-check: grep -rIlE "device_code|device_authorization" node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1*/ | wc -l → 0.
    6. The consent page leaves for any web address, loopback included; its stay-and-finish card covers app links only. Re-check: git grep -n "window.location.assign(redirect)" origin/main -- $P/OAuthConsentPage.tsx → line 264.
    Option What ships What the customer sees Workload
    A The vendor's device grant behind the existing switch; its approval page names the app, the unverified mark and the permissions; approval writes the same consent record with the organization; the first-party name keeps working An app that speaks the grant shows a short code, approved on any screen; other apps see no change. Any self-registered app can start a request where the switch is on server + ui lanes · 3 PRs · switch and pin like #25156 (+405/−0); page like #32053 (+961/−10); consent and organization on this path: no precedent (nearest #30879, +1114/−16)
    B Nothing; the card goes on hold with a restart condition As today 0 PRs
    C On a phone or tablet, a grant headed to a loopback address stops on a card with Copy link and Continue One tap, then paste into the app; works in apps that accept a pasted link (the sighted one did) ui lane · 1 PR · #34369 (+264/−9)

    In business terms. A: a TV-style pairing code beside the sign-in redirect. B: keep the manual step until an app can use a code. C: put the claim ticket on screen so the person can carry it over.

    Four axes.

    • Long-term soundness. In two years an agent on any machine is approved through one consent record on one approval page. GitHub, Salesforce and Microsoft Entra offer a device code as a per-application opt-in, and Entra advises blocking it unless a device needs it, because approval is not tied to the machine that asked (general knowledge, not measured here). A is that shape once apps use it; today it adds that surface and a second approval page that must track the first, for no measured user.
    • Business pull. One sighting, with a working manual step; nothing measured asks for a device code.
    • AI-error guard. A built halfway fails loudly (the agent and the command-line sign-in are refused), with one quiet case: a grant with no organization. C fails loudly (a stale link).
    • No spread. A is permanent surface on every host with the switch on; C is one page branch; B is nothing.

    os-decision-facets
    ① Long-term soundness: A widens the contract and adds a second approval page; B adds nothing; C adds one page branch.
    ② Business pull: one sighting; no measured client requests a device code.
    ③ AI-error guard: A refuses loudly except for a missing organization; B and C move no boundary.
    ④ No spread: A is a standing obligation with no user today; B none; C small.
    Prior rulings read: device authorization,device_code,rfc 8628,deviceauthorization,device flow,loopback redirect,dynamic client registration,oauth consent → 0 hits; ADR-0090 D10 (read; it governs who the agent is, not how it is approved); thread: none

    Recommendation: B. Not A: nothing measured would use it, and it is three PRs on the sign-in boundary, three times C. Not C: it tidies the hand copy by guessing the device, on one sighting.

    Confidence gaps: whether the sighted client, or any client the maintainer's users run, speaks the device grant is not verified (only the reference client kit was read; the MCP specification site was unreachable here); whether the hosted environment has the switch on was not read; the door's refusal in premise 3 is read, not run.

    Self-check: axis ① alone picks B; do ②③④ flip it: no.

    After the ruling.

    • B: the seat puts the card on hold; it restarts when a named MCP client is shown requesting a device code from a server it discovered.
    • A: the same ruling settles two points: whether any self-registered app may use it (marked unverified) or only administrator-registered ones, and whether hosted environments turn the switch on. Then three PRs in the table's order, the card's security reading in the first. The dev re-runs premise 3 first; if the organization cannot ride the vendor path without copying vendor internals, the dev reports the fork and ships nothing.
    • C: a new ui card; this card goes on hold as in B.

    Related: #24218 (the organization binding A must match).

  5. added
    needs-user-decision
    and removed
    pm:queue
    on Nov 21, 2026
  6. objectstack-fleet commented on Dec 1, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhPdWmTd47Fi2bKYZS

    Ruling (part 1 of 2) · 2026-12-01T06:30Z · the maintainer answered on a decision card in this account's fleet project (2026-12-01T06:28Z).
    Question, verbatim: 「定 #35801:MCP 客户端的设备码授权现在做吗?」
    Option tapped, verbatim: 「现在做设备码授权」. Consequence line: 「约三个 PR,动登录授权边界,要你批。只对会用设备码的客户端生效,目前没有测到这样的客户端。」
    Options not taken: 「挂起,等有客户端会用」 (the recommended option, per analysis 7065378943), 「手机上改成复制链接」.

    What it settles: option A of analysis 7065378943 is to be built.

    • The vendor's OAuth device grant goes behind the existing switch.
    • The approval page names the app, carries the unverified mark and lists the permissions.
    • Approval writes the same consent record, with the organization.
    • The first-party objectstack-cli name keeps working.
    • Three PRs, in that analysis's order, with the security reading in the first.
    • The dev re-runs premise 3 first. If the organization cannot ride the vendor path without copying vendor internals, the dev reports instead of shipping.

    Not settled yet, and the analysis says the same ruling must settle them:

    1. May any self-registered (DCR, unverified) app use the grant, or only apps an administrator registered?
    2. Do hosted environments turn the switch on?
      Both are on a decision card in front of the maintainer now. needs-user-decision stays until they are answered, and nothing is dispatched before then.
      Premise re-check on main today: no file references oauthDeviceAuthorization or device_authorization_endpoint.
  7. objectstack-fleet commented on Dec 1, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhPdWmTd47Fi2bKYZS

    Ruling (part 2 of 2, completes 7302969263) · 2026-12-01T06:38Z · the maintainer answered the follow-up decision card in this account's fleet project (2026-12-01T06:37Z).
    Question, verbatim: 「定 #35801:设备码授权谁能用,各环境默认开还是关?」
    Option tapped, verbatim: 「自注册可用,默认开」. Consequence line: 「所有环境直接可用,不用配置。代价是每个环境都多一个可被用来骗取授权码的入口,只靠同意页提醒。」
    Options not taken: 「自注册可用,默认关」 (the recommended option) and 「仅管理员登记的客户端」.

    What it settles:

    • Any self-registered (dynamic client registration) app may use the device grant.
    • The grant is on by default in every environment, with no configuration needed.

    Implementer design, not ruled. State each in the PR's 维护者速读:

    • Keep a per-environment off switch. 「默认开」 implies one, so an administrator can turn the grant off.
    • Show the 「未验证」 mark on the consent page for self-registered clients. The tapped option relies on the consent page as the only warning, so the seat reads the mark as required.
    • Apply RFC 8628 §5 hygiene: user-code entropy, attempt rate limits, a short code lifetime, and the polling interval.

    None of these needs a new ruling unless the contract review finds a real choice. The analysis is the card's own 7065378943, brought forward; premises were re-checked on main today, and no device endpoint exists. The work touches the authorization boundary, so every PR is Tier H.
    needs-user-decision → pm:queue.

  8. added
    pm:queue
    and removed
    needs-user-decision
    on Dec 1, 2026
  9. objectstack-fleet commented on Dec 1, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeVmGEB8ThXyLaJbkJ

    Premise 3 re-check · 2026-12-01T06:46Z · card thread for rulings 7302969263 + 7303115915 · result: fails on the pinned vendor. Nothing is claimed, dispatched or shipped. Reported to the seat for routing.

    维护者速读

    • 结论:按裁决的停止条件,本卡现在不能做。现装的登录组件(better-auth 1.7.12,最新正式版 1.7.29 同样)的设备码授权在发令牌时不带组织,也没有任何开放接口能把组织塞进去;要带组织只能把厂商内部代码抄一份过来,裁决明确不许。
    • 好消息:厂商 1.8 测试版(1.8.0-beta.12,2026-11-28)已经原生支持:设备码的批准改走现有的授权同意页(同一个登录、组织、同意页面),组织写进设备码记录并带到令牌上。正式版发布后,A 方案基本变成「升级依赖 + 打开开关」,单独的设备批准页也可能不用再做。
    • 需要你做的:无,席位会给出卡片去向(建议挂起,等 better-auth 1.8 正式版发布后重启)。

    What was read

    Tarballs fetched with npm pack, matching the lockfile pin (@better-auth/oauth-provider 1.7.12, better-auth 1.7.12), plus 1.7.29 (latest dist-tag, 2026-11-28) and 1.8.0-beta.12 (beta dist-tag, 2026-11-28). Read, not run.

    1. The token exchange drops the organization. In 1.7.12 the device grant's token handler is exchangeOAuthDeviceCode (dist/index.mjs:50-100). It calls provider.issueTokens({ client, scopes, user, resources, originalResources, confirmation }) with no referenceId. The redeemed authorizationContext is destructured to { client, confirmation, scopes }, so nothing a hook adds to it reaches issuance. Re-check: grep -n "provider.issueTokens" -A7 dist/index.mjs in the 1.7.12 tarball shows no referenceId.
    2. No hook reaches it. customAccessTokenClaims receives only { user, scopes, resources, referenceId, metadata } (introspect-*.mjs:253-259), and referenceId is undefined on this path. createUserTokens has no fallback for referenceId (introspect-*.mjs:1787), so the refresh-token row is written with none. postLogin.consentReferenceId (where the authorization-code flow binds the organization, auth-manager-plugin-list.ts:738-742) runs only at /oauth2/authorize, which a 1.7 device approval never visits: approval is the plain /device/approve route.
    3. The device record is gone before issuance. redeemDeviceCode consumes the row (better-auth dist/plugins/device-authorization/routes.mjs:356-369) before issueTokens runs, so a claims contributor cannot read an organization stored on it.
    4. Replacing the handler means copying internals. A handler of our own, registered through the exported extendOAuthProvider, would need validateClientScopes, resolveResourcePolicy and toResourceList. None is exported from . or ./internal (package.json exports: ., ./client, ./resource-client, ./internal; ./internal exports three CIMD/JWKS helpers only). That is the copy the ruling forbids.
    5. Stitching hooks around it is not riding the vendor path. An after-hook on /device/approve can write the consent row with the session's organization. Getting the same organization onto the token would still need request-scoped state between a before-hook on /oauth2/token and a claims contributor. It would also depend on the vendor consuming the row before issuance, and the refresh row would still carry no reference. A refreshed token then fails the MCP door's (client, user, organization) consent read (mcp-token-revocation.ts, mcpConsentAdmits) about an hour after approval. The seat reads this as a workaround, not a ride.
    6. Latest stable does not change it. 1.7.29: grep -c referenceId dist/index.mjs → 0, grep -c deviceApprovalRequest dist/index.mjs → 0.

    What the vendor's next minor ships

    1.8.0-beta.12 dist/index.mjs:

    • deviceApprovalRequest (:125-185): a device code is approved through /oauth2/authorize, "so device approvals run the same sign-in, account selection, post-login, and consent pages as authorization requests".
    • Approval writes referenceId: approval.referenceId onto the device record (:165), which adds a referenceId column (:225).
    • The exchange asserts the consent still covers (client, user, referenceId, scopes, resources) (:81-87) and issues with referenceId: approvedDeviceCode.referenceId (:113).

    On 1.8, the organization should ride the existing postLogin.consentReferenceId hook unchanged (read, not run). The approval page is the existing OAuthConsentPage (app name, unverified mark, permissions), so most of the second page in option A is not needed. Not verified: whether 1.8 still refuses the first-party objectstack-cli name, and what else the 1.7→1.8 bump changes in plugin-auth.

    Fork for the seat

    • Hold until 1.8 is stable (seat's call). Restart-when: @better-auth/oauth-provider publishes a non-prerelease 1.8.x whose exchangeOAuthDeviceCode passes referenceId to issueTokens. Probe: npm view @better-auth/oauth-provider dist-tags.latest, then the grep in point 1 on that tarball. The rebuilt plan is then a bump-then-switch shape, one to three PRs, with the security reading in the first.
    • Building on 1.8.0-beta is not offered. It would put the authorization boundary on a prerelease vendor build.
    • Copying exchangeOAuthDeviceCode and its helpers is forbidden by ruling 7302969263 ("the dev reports instead of shipping").
  10. objectstack-fleet commented on Dec 1, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhPdWmTd47Fi2bKYZS

    Seat routing · 2026-12-01T06:48Z · on the card thread's premise-3 reading 7303282539.
    Premise 3 fails on the pinned vendor. On @better-auth/oauth-provider 1.7.12 and on the latest stable 1.7.29, exchangeOAuthDeviceCode issues tokens with no referenceId, so the organization cannot ride the vendor path. The only way around that copies non-exported vendor internals, which ruling 7302969263 forbids. A hook-stitched version also loses the organization on refresh. So, as that ruling ordered, nothing was claimed, dispatched or shipped.
    The vendor's 1.8.0-beta.12 (2026-11-28) fixes this natively: device approval goes through /oauth2/authorize, and referenceId is carried on the device row.
    The card goes on hold until a stable release carries the fix, and the work is then re-planned as bump-then-switch. The maintainer is asked separately whether to adopt the prerelease now instead.
    pm:queue → pm:on-hold.
    Restart-when: a non-prerelease @better-auth/oauth-provider 1.8.x is published whose exchangeOAuthDeviceCode passes referenceId (probe in 7303282539), or the maintainer rules to adopt the 1.8 prerelease.

  11. added
    pm:on-hold
    and removed
    pm:queue
    on Dec 1, 2026
  12. objectstack-fleet commented on Dec 1, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhPdWmTd47Fi2bKYZS

    Ruling · 2026-12-01T07:12Z · the maintainer answered the seat's decision card in this account's fleet project (2026-12-01T07:11Z).
    Question, verbatim: 「#35801 设备码授权:等厂商正式版,还是现在用测试版?」
    Option tapped, verbatim: 「等 1.8 正式版再做」. Consequence line: 「卡先挂起,厂商发布带修复的 1.8 正式版后自动重开,先升级再换上设备码。」
    Options not taken: 「现在升到 1.8 测试版」, 「不做了,关闭」.

    What it settles: the card stays pm:on-hold (7303302177) until a stable vendor release carries the fix. The prerelease is not adopted. On restart, the work is re-planned as bump-then-switch: first upgrade @better-auth/oauth-provider to the stable 1.8.x, then build the device grant on its /oauth2/authorize path under rulings 7302969263 and 7303115915. The card thread for this card stands down and holds no units.
    Restart-when: a non-prerelease @better-auth/oauth-provider 1.8.x is published whose exchangeOAuthDeviceCode passes referenceId (probe in 7303282539).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:aidomain:serverenhancementpm:on-holdpriority:p2

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions