Skip to content

feat(mosaic,nextjs): add OAuthDeviceVerification - #11135

Draft
austincalvelage wants to merge 5 commits into
mainfrom
austin/mosaic-oauth-device-verification
Draft

austincalvelage wants to merge 5 commits into
mainfrom
austin/mosaic-oauth-device-verification

Conversation

@austincalvelage

Copy link
Copy Markdown
Member

Description

Adds OAuthDeviceVerification to Mosaic and exports it from @clerk/nextjs/preview. A signed-in user enters the code a device shows, or arrives with it in user_code, reviews the request, picks an organization, and approves or denies. It lands on the same views as @clerk/ui's <OAuthDeviceVerification />, using the existing useOAuthDeviceVerification data layer and Mosaic's model, controller and view split.

Shared changes (for Mosaic reviewers)

  • oauth-consent.view.tsx exports ConsentLogos and a new OrganizationSelect, which consent's own single-org branch now uses. PRIVATE_METADATA_SCOPE moves into oauth-consent.utils.ts beside the other scope constants.
  • The fake FAPI answers the device lookup and decision endpoints, with error codes taken from FAPI's oauth2_idp service.

1. Every FAPI answer leads where ui's switch sends it. The flow is one state machine in the controller, and three tables decide each transition, mirroring ui's showLookupResult, showLookupError and decision handler.

const LOOKUP_STATUS_STEPS = {
  pending: 'confirmation',
  approved: 'alreadyApproved',
  denied: 'alreadyDenied',
  consumed: 'consumed',
} as const satisfies Record<OAuthDeviceVerificationStatus, LookupStep>;

const LOOKUP_ERROR_STEPS = {
  resource_not_found: 'entry',
  oauth_device_code_expired: 'expired',
  too_many_requests: 'rateLimited',
} as const satisfies Record<string, 'entry' | OAuthDeviceVerificationOutcome>;

const DECISION_ERROR_STEPS = {
  oauth_device_code_expired: 'expired',
  too_many_requests: 'rateLimited',
  bad_request: 'alreadyDecided',
} as const satisfies Record<string, OAuthDeviceVerificationOutcome>;

Anything else goes to the error view, the only one that offers "Enter another code", as in ui.

2. Code entry matches ui's rules. Eight slots in two groups of four. The code is normalized and validated with ui's pattern, so an invalid code shows "Enter a valid 8-character code." and sends nothing, and an unknown code returns to entry with the field still editable. A valid user_code in the URL is looked up once.

3. The confirmation screen reuses consent's pieces. The two logos, the scope list styles and the organization select come from oauth-consent. offline_access is hidden from the list and turns on the offline notice. The organization select shows only with user:org:read and organizations enabled, and defaults to the last active organization. Approve and deny each send one decision, and only the chosen button shows pending.

JSDoc for review.

Lets the signed-in user approve or deny a device, such as a TV or a CLI, that asked to sign in to their account with the OAuth device authorization flow. The user enters the code the device shows, or arrives with it in the user_code URL parameter, then reviews the application and the scopes it asked for, picks an organization when the application reads organizations, and approves or denies. It renders fallback until Clerk loads, and nothing at all when nobody is signed in.

OAuthDeviceVerificationProps: Everything <OAuthDeviceVerification /> takes.

fallback: The element to render while Clerk loads.

Known gaps

  • ui shows a separate loading view during lookup. Mosaic keeps entry on screen with Continue pending and the field disabled.
  • The code slots drop characters other than letters and digits as the user types. ui accepts any text and rejects it on submit. Digits and vowels still get in and are rejected on submit with ui's message.
  • The organization select has a visible "Grant access for:" label, from consent's select.
  • utils.ts is copied from ui, not shared. Moving it to @clerk/shared would give both one validation rule.
  • Not run in a real app against FAPI, not checked visually, and no Swingset story yet.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

🤖 Generated with Claude Code

Serve POST /v1/me/oauth/device/lookup and POST /v1/me/oauth/device the way
FAPI does: an unknown code or one decided by another user answers 404
resource_not_found, an expired pending code 400 oauth_device_code_expired,
a decision on a code that is no longer pending 400 bad_request, and a
rate-limited instance 429 too_many_requests. Record every lookup and
decision body so feature tests can assert what reached FAPI.
Export ConsentLogos, typed to the logo fields it reads, and pull the
single-organization select out of OrganizationField as OrganizationSelect,
which takes its label as a string. The device verification confirmation
shows the same logos and organization select with its own copy.
Port the legacy OAuthDeviceVerification component tests and user code
tests: code entry and normalization, URL prefill, each view a lookup or a
decision can end on, approve and deny, the organization select, and the
signed-out guard. They fail until the component exists.
Port the legacy OAuthDeviceVerification component to Mosaic and export it
from @clerk/nextjs/preview. A state machine owns the flow from code entry
through lookup, confirmation, and the decision, and tables map each FAPI
status and error code to the view the user lands on.
@vercel

vercel Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Dec 5, 2026 10:07pm UTC
mosaic-docs Ready Ready Preview Dec 5, 2026 10:07pm UTC
swingset Ready Ready Preview Dec 5, 2026 10:07pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 20a2fa7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@clerk/mosaic Minor
@clerk/nextjs Minor
@clerk/mosaic-docs Patch
@clerk/swingset Patch

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

@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pkg-pr-new

pkg-pr-new Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@11135

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@11135

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@11135

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@11135

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@11135

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@11135

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@11135

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@11135

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@11135

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@11135

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@11135

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@11135

@clerk/express

npm i https://pkg.pr.new/@clerk/express@11135

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@11135

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@11135

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@11135

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@11135

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@11135

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@11135

@clerk/react

npm i https://pkg.pr.new/@clerk/react@11135

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@11135

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@11135

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@11135

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@11135

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@11135

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@11135

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@11135

commit: 20a2fa7

Cover what the legacy component does that no Mosaic test pinned: an
unexpected lookup failure offers another code, an unknown code stays in
the field, an expired or rate-limited code at lookup offers no action,
and a user without an email address is named by phone number.

This branch was successfully deployed

2 active deployments
Preview – swingset — 20a2fa7c Deployed Dec 5, 2026 by vercel[bot]
Preview – clerk-js-sandbox — 20a2fa7c Deployed Dec 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant